- 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
Range
Application Scenarios
This algorithm applies to routing data in different ranges to different shards. Less-than signs (<), greater-than signs (>), and BETWEEN ... AND ... are frequently used in SQL queries.
Instructions
The sharding key can only be an integer, a date, or used in combination with a date function. If a date function is used, the sharding key must be DATE, DATETIME, or TIMESTAMP.
Data Routing
Data is routed to different shards by the sharding key value based on algorithm metadata rules.
Metadata needs to be set when a table is created. For example, if there are eight shards in one schema, the metadata range can be 1-2=0, 3-4=1, 5-6=2, 7-8=3, 9-10=4, 11-12=5, 13-14=6, and default=7. Data is routed to shards by the sharding key value based on the range.
Calculation Method
Method 1: Use an Integer as the Sharding Key
Condition |
Calculation Method |
Example |
---|---|---|
Integer sharding keys |
Database routing result: Data is routed to different shards based on the sharding key and the preset metadata range. |
Data is routed to shard1 if the sharding key value is 3 and the preset metadata range is 3–4. |
Method 2: Use a Date as the Sharding Key
Date Function |
Calculation Method |
Example |
---|---|---|
year() |
year(yyyy-MM-dd)=yyyy |
year('2019-10-11')=2019 |
month() |
month(yyyy-MM-dd)=MM |
month('2019-10-11')=10 |
weekofyear() |
weekofyear(yyyy-MM-dd)=Week number of the current year |
weekofyear ('2019-10-11')=41 |
day() |
day(yyyy-MM-dd)=Day number of the current month |
day ('2019-10-11')=11 |
Condition |
Calculation Method |
Example |
---|---|---|
Date sharding key |
Database routing: Data is routed to different database shards based on the date function (database sharding key value) and the preset metadata range. |
Data is routed to shard 4 based on the metadata range 9–10 when the sharding key value is 10: month(2019-10-11)=10 belongs to 9–10=4. |
Syntax for Creating Tables
create table range_tb( id int, name varchar(30) DEFAULT NULL, create_time datetime DEFAULT NULL, primary key(id) ) dbpartition by range(id) { 1-2=0, 3-4=1, 5-6=2, 7-8=3, 9-10=4, 11-12=5, 13-14=6, default=7 };
Precautions
None
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.