DD partitions data into table shards by day of month. Each table shard holds data for one specific day, and the shard name directly reflects the day number it contains.
How it works
DD extracts the day-of-month value from the partitioning key and uses it as the table shard subscript. For example, a row with create_time = '2024-03-15 10:00:00' maps to the shard for day 15. The resulting physical table is named after that day number, so the shard name directly identifies which day's data it holds.
Use cases
DD works well for workloads where data is queried or purged by day. Because each shard maps to a single day, you can remove an entire day's data by dropping one table shard.
Example
The following Data Definition Language (DDL) statement partitions data into database shards by user ID (id) and creates one table shard per day based on create_time. With tbpartitions 31, up to 31 table shards are created — one per possible day in a month.
CREATE TABLE test_dd_tb (
id INT,
name VARCHAR(30) DEFAULT NULL,
create_time DATETIME DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8
dbpartition BY HASH(id)
tbpartition BY DD(create_time) tbpartitions 31;Limitations
| Constraint | Detail |
|---|---|
| Partitioning key types | DATE, DATETIME, or TIMESTAMP only |
| Partitioning scope | Table shards (tbpartition) only; cannot be used for database shards (dbpartition) |
| Maximum table shards per database shard | 31 — a month has at most 31 days |
| Minimum PolarDB-X 1.0 version | 5.1.28-1320920 |