Issues Related to TiDB shard_row_id_bits

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb shard_row_id_bits 相关问题

| username: Raymond

I watched the TiDB course, and the instructor mentioned that if shard_row_id_bits is set to 4, then a 64-bit value is assigned to row_id, where the first 4 bits are random and the remaining 60 bits are sequentially assigned IDs, which will be inserted into different regions. However, based on my own experiments, I found that the generated row_id is not 64 bits but only 20 bits. What is going on here? Could the experts please advise?

| username: xfworld | Original post link

There is a bit of a misunderstanding. tidb_rowid is a hidden column, and it actually only exists for non-clustered index primary keys, which will have this 64-bit value.

Reference the description in the documentation:

Additionally, for this kind of primary key definition, it is best to use BIGINT:

CREATE TABLE t (a BIGINT PRIMARY KEY /*T![clustered_index] CLUSTERED */, b VARCHAR(255));
CREATE TABLE t (a BIGINT PRIMARY KEY /*T![clustered_index] NONCLUSTERED */, b VARCHAR(255));
| username: ddhe9527 | Original post link

64-bit, not a 64-digit decimal value. ROWID is of type int64.

| username: system | Original post link

This topic will be automatically closed 60 days after the last reply. No new replies are allowed.