MMDD partitions a large table into table shards by calendar day in PolarDB-X 1.0. Each table shard name subscript maps to a specific day, identified by a two-digit month and a two-digit day (MMDD format).
How it works
MMDD derives the table shard subscript from the month and day portion of the partitioning key value. A row with a create_time of 2024-03-15 maps to table shard 0315, placing it in the shard that represents March 15.
Because MMDD routes by day of year, each database shard holds at most 366 table shards — one per possible calendar day.
Limitations
| Constraint | Detail |
|---|---|
| Supported data types | DATE, DATETIME, or TIMESTAMP |
| Sharding scope | Table shards only — cannot be used for database sharding |
| Maximum table shards per database shard | 366 (one per calendar day; a year has at most 366 days) |
| Minimum version | PolarDB-X 1.0 instance version 5.1.28-1320920 or later |
Use cases
Use MMDD when you need to partition a large table by day of year and query patterns align with specific calendar days. The table shard subscript directly represents a calendar day, making day-based range queries efficient.
MMDD is not suitable for:
Database sharding —
MMDDonly works for table shards.Even data distribution regardless of date — if your data volume varies significantly by day (for example, heavy traffic on weekdays and low traffic on weekends),
MMDDwill produce unevenly sized shards. Use a hash-based function for uniform distribution.
Create a table with MMDD sharding
The following Data Definition Language (DDL) example partitions data into database shards by user name (hash) and into table shards by calendar day using MMDD on the create_time column.
CREATE TABLE test_mmdd_tb (
id INT,
name VARCHAR(30) DEFAULT NULL,
create_time DATETIME DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8
dbpartition BY HASH(name)
tbpartition BY MMDD(create_time) tbpartitions 366;
-- 366 tbpartitions: one per possible calendar day (a year has at most 366 days)Key parameters:
| Parameter | Value | Description |
|---|---|---|
dbpartition by | HASH(name) | Distributes rows across database shards by hashing the name column |
tbpartition by | MMDD(create_time) | Routes each row to a table shard based on the month and day of create_time |
tbpartitions | 366 | Number of table shards per database shard — set to 366 to cover every calendar day of the year |