From 9980920d9eec9396b3efa1587a97d8e8d7644419 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 28 Jul 2025 09:35:17 +0800 Subject: [PATCH 1/4] Add temp.md --- temp.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 temp.md diff --git a/temp.md b/temp.md new file mode 100644 index 0000000000000..af27ff4986a7b --- /dev/null +++ b/temp.md @@ -0,0 +1 @@ +This is a test file. \ No newline at end of file From 6bf77bcb50086c296fb85e84add5316b8396f635 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 28 Jul 2025 09:35:22 +0800 Subject: [PATCH 2/4] Delete temp.md --- temp.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 temp.md diff --git a/temp.md b/temp.md deleted file mode 100644 index af27ff4986a7b..0000000000000 --- a/temp.md +++ /dev/null @@ -1 +0,0 @@ -This is a test file. \ No newline at end of file From 8d36b0bef0a55472cedad9adc7be375964106945 Mon Sep 17 00:00:00 2001 From: Test User Date: Mon, 28 Jul 2025 10:06:11 +0800 Subject: [PATCH 3/4] Update shard-row-id-bits.md --- shard-row-id-bits.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shard-row-id-bits.md b/shard-row-id-bits.md index 3109bcc48e466..02a266671dbcb 100644 --- a/shard-row-id-bits.md +++ b/shard-row-id-bits.md @@ -17,6 +17,22 @@ To mitigate the hot spot issue, you can configure `SHARD_ROW_ID_BITS`. The row I - `SHARD_ROW_ID_BITS = 6` indicates 64 shards - `SHARD_ROW_ID_BITS = 0` indicates the default 1 shard +When you set `SHARD_ROW_ID_BITS = S`, the structure of `_tidb_rowid` is as follows: + +| Signed bit | Shard bits | Auto-increment bits | +|--------|--------|--------------| +| 1 bit | `S` bits | `63-S` bits | + +- The values of the auto-increment bits are stored in TiKV and allocated sequentially. Each time a value is allocated, the next value is incremented by 1. The auto-increment bits ensure that the column values of `_tidb_rowid` are unique globally. When the value of the auto-increment bits is exhausted (that is, when the maximum value is reached), subsequent automatic allocations fail with the error `Failed to read auto-increment value from storage engine`. +- The value range of `_tidb_rowid`: the maximum number of bits for the final generated value = shard bits + auto-increment bits, so the maximum value is `(2^63)-1`. + +> **Note:** +> +> Selection of shard bits (`S`): +> +> - Because the total bits of `_tidb_rowid` is 64, the number of shard bits affects the number of auto-increment bits: when the number of shard bits increases, the number of auto-increment bits decreases, and vice versa. Therefore, you need to balance the randomness of the auto-increment values and the available auto-increment space. +> - The best practice is to set the shard bits to `log(2, x)`, where `x` is the number of TiKV nodes in the cluster. For example, if there are 16 TiKV nodes in a TiDB cluster, it is recommended to set the shard bits to `log(2, 16)`, which equals `4`. After all Regions are evenly scheduled to each TiKV node, the load of bulk writes can be evenly distributed to different TiKV nodes to maximize resource utilization. + For details on the usage, see [the Troubleshoot Hotspot Issues guide](/troubleshoot-hot-spot-issues.md#use-shard_row_id_bits-to-process-hotspots). From 63d3b8602bf8a6078b7fdf1eecd8766a43a2e510 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 14 Aug 2025 08:15:29 +0800 Subject: [PATCH 4/4] Update shard-row-id-bits.md Co-authored-by: Aolin --- shard-row-id-bits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard-row-id-bits.md b/shard-row-id-bits.md index 02a266671dbcb..38073c00b5da2 100644 --- a/shard-row-id-bits.md +++ b/shard-row-id-bits.md @@ -19,7 +19,7 @@ To mitigate the hot spot issue, you can configure `SHARD_ROW_ID_BITS`. The row I When you set `SHARD_ROW_ID_BITS = S`, the structure of `_tidb_rowid` is as follows: -| Signed bit | Shard bits | Auto-increment bits | +| Sign bit | Shard bits | Auto-increment bits | |--------|--------|--------------| | 1 bit | `S` bits | `63-S` bits |