- What's New
- Service Overview
- Getting Started
-
User Guide
- Function Overview
- Permissions Management
-
Instance Management
- Buying a DDM Instance
- Splitting Read-only and Read-Write Services
- Changing Class of a DDM Node
- Scaling Out a DDM Instance
- Scaling In a DDM Instance
- Changing Billing Mode of a DDM Instance
- Renewing a DDM Instance
- Restarting a DDM Instance
- Unsubscribing from a DDM Instance
- Deleting a DDM Instance
- Modifying Parameters of a DDM Instance
- Splitting Read and Write Requests
- Configuring a Parameter Template
- Connection 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
- Shard Configuration
- Data Node Management
- Account Management
- Backups and Restorations
-
Data Migration
- Overview
- Migration Evaluation
- Scenario 1: Migrating Data from Huawei Cloud RDS to DDM
- Scenario 2: Migrating Data from an On-Premises RDS Instance for MySQL to DDM
- Scenario 3: Migrating Data from a Third-Party RDS for MySQL Instance to DDM
- Scenario 4: Migrating Data from a Self-Built MySQL Instance to DDM
- Scenario 5: Migrating Data from Heterogeneous Databases to DDM
- Scenario 6: Exporting Data from a DDM Instance
- Slow Queries
- Monitoring Management
- Auditing
-
SQL Syntax
- Introduction
- DDL
- DML
- Functions
- Use Constraints
- Supported SQL Statements
- Global Sequence
- Database Management Syntax
- Advanced SQL Functions
- Quotas
- Change History
-
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
- 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 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
- Schemas
- DDM Accounts
- Monitoring
-
DDM Instances
- APIs (Unavailable Soon)
- Appendix
- Change History
- 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
- 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?
- What Version and Parameters Should I Select?
- 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
- Connection Management
- Resource Freezing, Release, Deletion, and Unsubscription
- Change History
- Videos
YYYYMM
Application Scenarios
This algorithm applies when data is routed to shards by year and month. Recommend you to use this algorithm together with tbpartition YYYYMM(ShardKey).
Instructions
The sharding key must be DATE, DATETIME, or TIMESTAMP.
Data Routing
The data route depends on the remainder of the sharding key hash value divided by database shards. Enter the year and month into the hash function to obtain the hash value.
For example, YYYYMM ('2012-12-31 12:12:12') is equivalent to (2012 x 12 + 12) % D. D is the number of database or table shards.
Calculation Method
Condition |
Calculation Method |
Example |
---|---|---|
Database sharding key ≠ Table sharding key |
Sharding key: yyyy-MM-dd Database routing result = (yyyy x 12 + MM) % Database shards Table routing result = (yyyy x 12 + MM) % Table shards |
Sharding key: 2012-11-20 Database shard: (2012 x 12 + 11) % 8 = 3 Table shard: (2012 x 12 + 11) % 3 = 2 |
Database sharding key = Table sharding key |
Sharding key: yyyy-MM-dd Table routing result = (yyyy x 12 + MM) % (Database shards x Table shards) Database routing result = Table routing result / Table shards |
Sharding key: 2012-11-20 Table shard: (2012 x 12 + 11) % (8 x 3) = 11 Database shard: 11 % 3 = 3 |
Syntax for Creating Tables
Assume that there are already 8 physical databases in your database instance. Now you want to shard data by year and month and require that data of the same month be stored in one table and each month within two years should correspond to an independent table, so that you can query data from a physical table in a physical database by the sharding key.
In this scenario, you can select the YYYYMM algorithm. Then create 24 physical tables for 24 months of the two years, each month corresponding to one table. Since you already have 8 physical databases, three physical tables should be created in each of them. The following is an example SQL statement for creating a table:
create table test_yyyymm_tb( id int, name varchar(30) DEFAULT NULL, create_time datetime DEFAULT NULL, primary key(id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 dbpartition by YYYYMM(create_time) tbpartition by YYYYMM(create_time) tbpartitions 3;
Syntax for creating tables when only database sharding is required:
create table YYYYMM( id int, name varchar(30) DEFAULT NULL, create_time datetime DEFAULT NULL, primary key(id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 dbpartition by YYYYMM(create_time);
Precautions
- This YYYYMM algorithm does not apply if each month of a year corresponds to one database shard. The number of tables must be fixed if database and table sharding is both required.
- Data of the same month in different years may be routed to the same database or table. The result depends on the number of tables.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.