Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: tidb 表中 auto_random 的字段的分片位有什么用?
[TiDB Usage Environment] Production Environment
[TiDB Version] 6.5.0
[Resource Configuration] 5 TiKV Nodes
[Attachment: Screenshot/Log/Monitoring]
What is the purpose of the shard bits in the auto_random field in a TiDB table?
I don’t quite understand its specific function. Can someone explain it?
Can it scatter the ID generation when data is inserted after the table is created? Does it ensure that data is evenly distributed across TiKV nodes? If so, why is this possible? Is it because the ID generation algorithm is influenced by it? Seeking help.
If you use AUTO_INCREMENT
for auto-increment, the write hotspot may only be on one region. By using the sharding bits of the auto_random field, the write hotspot will be shared by multiple regions.
For more details, see here:
SHARD_ROW_ID_BITS | PingCAP Documentation Center
If I have 5 TiKV nodes here, should I set the shard bits to 2 or 3? If it’s 2, will one node have no load? What will happen if it’s 3?
Setting 2 or 3 is fine for 5 TiKV nodes.
There is a different perspective: although random uniqueness can solve the hotspot issue, the separation of regions is based on range. Does it improve overall performance? Is the impact of later merging significant? Will the generated random values be very large in a short period of time? For example, values with large spans like 1, 10000, 100000, 999999.
Performance has improved, reducing hotspots. You only need to scatter data if you are sure there will be a large amount of data written, so merging is generally not necessary.
There are two places in this document that feel a bit ambiguous. Can you explain them, please?
There shouldn’t be any ambiguity, right? The first sentence means that if there are no multiple replicas, each region can only be stored on one node. The second sentence means that in reality, there are multiple replicas, so besides the leader of each region being stored on one node, the other followers are stored on other nodes.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.