How to choose the number of shards
When you create a PolarDB-X 1.0 database with Horizontal Partitioning, PolarDB-X 1.0 distributes data across physical database shards — 8 per ApsaraDB RDS for MySQL instance by default. On top of each physical database shard, you can create one or more physical table shards. The number of table shards is often referred to as the number of shards. This page explains how to calculate the right number of physical table shards based on your projected data volume.
Capacity guidelines
Size each physical table shard to stay within these row limits:
| Row size | Recommended row limit per shard |
|---|---|
| Standard (4 KB or less per row) | 5 million – 50 million rows |
| Large (more than 4 KB per row) | Up to 5 million rows |
We also recommend that you set the depth of a B+ tree to three to four layers.
Base your estimates on projected data volume 1 to 2 years out, not your current data size.
Calculate the shard count
Use this formula to determine how many physical table shards to create in each physical database shard:
Physical table shards per physical database shard =
CEILING(Estimated total rows / (Number of ApsaraDB RDS for MySQL instances × 8) / 5,000,000)
| Result | Action |
|---|---|
| 1 | Use one physical table shard per physical database shard |
| Greater than 1 | Create that many physical table shards per physical database shard |
Examples
Example 1: 4 RDS instances, 100 million rows projected
CEILING(100,000,000 / (4 × 8) / 5,000,000) = CEILING(0.625) = 1
Result: 1 physical table shard per physical database shard.
Example 2: 1 RDS instance, 100 million rows projected
CEILING(100,000,000 / (1 × 8) / 5,000,000) = CEILING(2.5) = 3
Result: 3 physical table shards per physical database shard.