- What's New
- Product Bulletin
- Service Overview
- Billing
- Getting Started
-
User Guide
- Function Overview
- Kernel Version Notes
- Permissions Management
-
Instance Management
- Instance Statuses
- Buying a DDM instance
- Splitting Read-only and Read-Write Services
- Changing Node Class
- Scaling Out a DDM Instance
- Scaling In a DDM Instance
- Restarting a DDM Instance or an Instance Node
- Deleting Pay-per-Use Instances
- Reloading Table Data
- Changing a Parameter Template
- Modifying Parameters of a DDM Instance
- Rolling Back the Version of a DDM Instance
- Upgrading the Version of a DDM Instance
- Upgrading the DDM Engine and OS
- Connection Management
- Schema Management
- Shard Configuration
- Data Nodes
-
Parameter Template Management
- Instance Parameters
- Creating a Parameter Template
- Modifying a Custom Parameter Template
- Comparing Two Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying the Description of a Parameter Template
- Deleting a Parameter Template
- Account Management
- Backups and Restorations
-
Data Migration
- Overview
- Migration Evaluation
- Scenario 1: Migrating Data from an On-Premises MySQL Instance to DDM
- Scenario 2: Migrating Data from a Third-Party Cloud MySQL Instance to DDM
- Scenario 3: Migrating Data from an ECS-hosted MySQL Instance on Huawei Cloud to DDM
- Scenario 4: Exporting Data from a DDM Instance
- Scenario 5: Migrating Data from Heterogeneous Databases to DDM
- Scenario 6: Migrating Data from Huawei Cloud RDS for MySQL to DDM
- Session Management
- Slow Queries
- Monitoring and Alarm Reporting
- Task Center
- Tags
- Auditing
-
SQL Syntax
- Introduction
- DDL
- DML
- Online DDL
- Functions
- Unsupported Objects and Use Constraints
- Supported SQL Statements
- Global Sequence
- Database Management Syntax
- Advanced SQL Functions
- Quotas
-
API Reference
- Before You Start
- API Overview
- Calling APIs
-
APIs (Recommended)
-
DDM Instances
- Buying a DDM instance
- Querying DDM Instances
- Querying Details of a DDM Instance
- Modifying the Name of a DDM Instance
- Changing the Security Group of a DDM Instance
- Deleting a DDM Instance
- Restarting a DDM Instance
- Reloading Table Data
- Scaling Out a DDM Instance
- Scaling in a DDM instance
- Modifying the Read Policy of the Associated DB Instance
- Synchronizing Data Node Information
- Querying Nodes of a DDM Instance
- Querying Details of a DDM Instance Node
- Querying Parameters of a Specified DDM Instance
- Modifying Parameters of a DDM Instance
- Querying DDM Engine Information
- Querying DDM Node Classes Available in an AZ
- Changing the Node Class of a DDM Instance
- Obtaining the Instance Group Information
- Creating an Instance Group
- Schemas
- Accounts
- Monitoring
- Session Management
- Application Examples
-
DDM Instances
- Permissions Policies and Supported Actions
- Appendix
- SDK Reference
-
Best Practices
- Overview
- Formulating Sharding Rules
- Determining the Number of Shards in a Schema
- Using Broadcast and Unsharded Tables
- Transaction Models
- SQL Standards
- Migrating an Entire RDS Database to DDM
- Migrating an Entire MyCat Database to DDM
- Accessing DDM Using a JDBC Connection Pool
- Logging In to a DDM Instance Using Navicat
- Migrating Data from RDS for MySQL to DDM Using DRS
- Sharding Database and Table Data of an RDS for MySQL Instance
- Performance White Paper
-
FAQs
- General Questions
-
DDM Usage
- How Does DDM Perform Sharding?
- What Do I Do If I Fail to Connect to a DDM Instance Using the JDBC Driver?
- Why It Takes So Long Time to Export Data from MySQL Using mysqldump?
- What Do I Do If a Duplicate Primary Key Error Occurs When Data Is Imported into DDM?
- What Should I Do If an Error Message Is Returned When I Specify an Auto-Increment Primary Key During Migration?
- What Do I Do If an Error Is Reported When Parameter Configuration Does Not Time Out?
- Which Should I Delete First, a Schema or its Associated RDS Instances?
- Can I Manually Delete Databases and Accounts Remained in Data Nodes After a Schema Is Deleted?
- SQL Syntax
-
RDS-related Questions
- Is the Name of a Database Table Case-Sensitive?
- What Risky Operations on RDS for MySQL Will Affect DDM?
- How Do I Handle Data with Duplicate Primary Keys in a Table?
- How Can I Query RDS for MySQL Information by Running Command show full innodb status?
- What Should I Pay Attention to When Selecting RDS for MySQL Instance Specifications?
- Connection Management
- Resource Freezing, Release, Deletion, and Unsubscription
- Videos
-
More Documents
-
User Guide (ME-Abu Dhabi Region)
- Service Overview
- Getting Started
- Function Overview
- Instance Management
-
Parameter Template Management
- Creating a Parameter Template
- Editing a Parameter Template
- Comparing Two Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying the Description of a Parameter Template
- Deleting a Parameter Template
- Task Center
- Schema Management
- Account Management
- Backup Management
- Monitoring Management
- Auditing
-
SQL Syntax
- Introduction
- DDL
- DML
- Functions
- Unsupported Items
- Supported SQL Statements
- Global Sequence
- Database Management Syntax
- Advanced SQL Functions
-
FAQs
- General Questions
-
DDM Usage
- How Can I Rectify a Fault in Accessing DDM by Using the JDBC Driver?
- What Version and Parameters Should I Select?
- Why It Takes So Long Time to Export Data from MySQL Using mysqldump?
- How Should I Handle the Duplicate Primary Key Error Occurring After Data Is Imported into DDM?
- What Should I Do If an Error Message Is Returned After I Specify an Auto-Increment Primary Key?
- How Do I Handle the Error Reported When Parameter Configuration Does Not Time Out?
- Which Should I Delete First, Schema or Associated RDS DB Instances?
- Should I Manually Delete Databases and Accounts Remained in the Associated RDS DB Instances After a Schema Is Deleted?
- SQL Syntax
- RDS-related Questions
- Connection Management
-
User Guide (Kuala Lumpur Region)
- Service Overview
- Getting Started
- Function Overview
- Instance Management
-
Parameter Template Management
- Creating a Parameter Template
- Editing a Parameter Template
- Comparing Two Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying the Description of a Parameter Template
- Deleting a Parameter Template
- Task Center
- Schema Management
- Account Management
- Backup Management
- Monitoring Management
- Auditing
-
SQL Syntax
- Introduction
- DDL
- DML
- Functions
- Unsupported Items
- Supported SQL Statements
- Global Sequence
- Database Management Syntax
- Advanced SQL Functions
-
FAQs
- General Questions
-
DDM Usage
- How Can I Rectify a Fault in Accessing DDM by Using the JDBC Driver?
- What Version and Parameters Should I Select?
- Why It Takes So Long Time to Export Data from MySQL Using mysqldump?
- How Should I Handle the Duplicate Primary Key Error Occurring After Data Is Imported into DDM?
- What Should I Do If an Error Message Is Returned After I Specify an Auto-Increment Primary Key?
- How Do I Handle the Error Reported When Parameter Configuration Does Not Time Out?
- Which Should I Delete First, Schema or Associated RDS DB Instances?
- Should I Manually Delete Databases and Accounts Remained in the Associated RDS DB Instances After a Schema Is Deleted?
- SQL Syntax
- RDS-related Questions
- Connection Management
-
API Reference (Kuala Lumpur Region)
- Before You Start
- API Overview
- Calling APIs
-
DDM Instance Management
- Querying DDM Engine
- Querying the Quota of Classes Available in Each AZ
- Creating a DDM Instance
- Querying DDM Instances
- Viewing Details of a DDM Instance
- Modifying the Name of a DDM Instance
- Modifying the Security Group of a DDM Instance
- Deleting a DDM Instance
- Restarting a DDM Instance
- Reloading Table Data
- Scaling Out a DDM instance
- Scaling In a DDM instance
- Modifying the Read Policy of the Associated DB Instance
- Synchronizing DB Instance Data
- Querying Nodes of a DDM Instance
- Querying Details of a DDM Instance Node
- Querying Parameters of a Specified DDM Instance
- Modifying Parameters of a DDM Instance
- Schema Management
- Account Management
- Monitoring Management
- Permissions Policies and Supported Actions
- Appendix
- Change History
-
User Guide (ME-Abu Dhabi Region)
- General Reference
Copied.
Formulating Sharding Rules
If a relationship exists between entities on different tables, formulate the same sharding rule for these tables, and select the associated table fields as the sharding keys respectively so that associated data in different tables is stored in the same shard to avoid cross-shard JOIN operations. For example, use the customer ID as the sharding key when creating sharded tables for storing customer information, orders, or order details.
Sharding Algorithm |
Hash |
Range |
||
---|---|---|---|---|
Sharding Key |
Table field |
Table field+date function |
Table field |
Table field+date function |
Description |
Data is evenly distributed to shards by table field. |
Data is evenly distributed to shards by table field and date function. The table field must be date, datetime, or timestamp. |
Data is distributed to a specific shard based on the rules defined in algorithm metadata. |
Data is distributed to shards by table field and date function based on the rules defined in algorithm metadata. The table field must be date, datetime, or timestamp. |
Application Scenarios |
Scenarios requiring even data distribution, for example, banking applications where logical entities are customers. In this case, use the table field corresponding to customers (for example, customer account numbers) as the sharding key. |
Scenarios requiring data to be split by time (year, month, day, week, or their combinations), for example, gaming applications. For these applications, use the table field (for instance, player registration time) corresponding to players as the sharding key. Sharding by day, month, or year helps you easily collect and query operation statistics of players for a specified day or month, and helps game vendors conduct big data analysis. |
Scenarios with a large number of range operations, for instance, e-commerce applications. If a service scenario is focused on promotional activities and logical entities are activity dates, use the table field corresponding to activity dates (for example, activity name and date range) as the sharding key. This helps you collect statistics about the sales volume for a specified cycle. |
Scenarios involving many different types of complicated information. For example, for log analysis, you can select the time field as the sharding key and then shard data using the date function. To make it easier to clear and dump logs, select the range algorithm and convert the time field value into "year" using the date function so that logs are stored in shards by year. For details, see examples in the following passages. |
Selecting a Sharding Algorithm
A sharding algorithm partitions data from logical tables to multiple shards. DDM supports hash and range algorithms.
- Hash
Hash evenly distributes data across shards.
Select this algorithm if operators = and IN need to be frequently used in SQL queries.
- Range
Range stores records in tables based on the range specified in algorithm metadata.
Select this algorithm if operators greater (>), less (<), and BETWEEN ... AND ... need to be frequently used in SQL queries.
CAUTION:
If the sharding algorithm is a range algorithm and a DATE function and the sharding key field indicates the creation time, hotspot issues may occur when data is imported to the database. As a result, the advantages of multiple MySQL databases cannot be fully utilized.
Select an appropriate algorithm based on your service requirements to improve efficiency.
Selecting a Sharding Key
A sharding key is a table field used to generate a route during horizontal partitioning of logical tables. After specifying a table field, you can select a date function or manually enter date function (field name). The table field must be date, datetime, or timestamp. Select a date function if data needs to be redistributed by year, month, day, week, or some combinations thereof.
DDM calculates routes based on the sharding key and sharding algorithm, horizontally partitions data in sharded tables, and then redistributes it to shards.
Note that when you select a sharding key and a sharding algorithm:
- Ensure that data is evenly distributed to each shard as much as possible.
- Select the most frequently used field or the most important query condition as the sharding key.
- Prioritize the primary key as the sharding key to keep query the fastest.
Service Scenarios with a Clear Entity
A sharded table generally contains tens of millions of data records. It is extremely important to select an appropriate sharding key and a sharding algorithm. If a logical entity is identified and most database operations are performed on data of that entity, select the table field corresponding to the entity as a sharding key for horizontal partitioning.
Logical entities depend on actual applications. The following scenarios each include a clear logical entity.
- For customer-related applications of banks, the service logical entities are customers. In this case, use the table field corresponding to customers (for example, customer numbers) as the sharding key. Service scenarios of some systems are based on bank cards or accounts. In such cases, select the bank card or account as the sharding key.
- For e-commerce applications, if service scenarios are based on products, the service logical entity is products. In this case, use the table field corresponding to products (for example, product code) as the sharding key.
- Game applications mainly focus on player data, and the service logical entity is players. In this case, use the table field corresponding to players (for example, player ID) as the sharding key.
The following is an example SQL statement for creating tables for bank services:
CREATE TABLE PERSONALACCOUNT( ACCOUNT VARCHAR(20) NOT NULL PRIMARY KEY, NAME VARCHAR(60) NOT NULL, TYPE VARCHAR(10) NOT NULL, AVAILABLEBALANCE DECIMAL(18, 2) NOT NULL, STATUS CHAR(1) NOT NULL, CARDNO VARCHAR(24) NOT NULL, CUSTOMID VARCHAR(15) NOT NULL ) ENGINE = INNODB DEFAULT CHARSET = UTF8 dbpartition by hash(ACCOUNT);
Service Scenarios Without a Clear Entity
If you cannot identify a suitable entity for your service scenario, select the table field that can provide even data distribution as the sharding key.
For example, the log system may contain a wide range of data records. In this case, you can select the time field as the sharding key.
When the time field is selected as the sharding key, you can specify a date function to partition data.
To make it easier to clear and dump logs, select the range algorithm and convert the time field value into "month" using the date function so that logs are stored in shards by month.
Example SQL statement for creating a table:
CREATE TABLE LOG( LOGTIME DATETIME NOT NULL, LOGSOURCESYSTEM VARCHAR(100), LOGDETAIL VARCHAR(10000) ) dbpartition by range(month(LOGTIME)) { 1 - 2 = 0, 3 - 4 = 1, 5 - 6 = 2, 7 - 8 = 3, 9 - 10 = 4, 11 - 12 = 5, default = 0 };
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot