Are IDs generated by RANDOM sequentially increasing?

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

Original topic: RANDOM 生成的ID是否是有序递增的?

| username: TiDBer_E3pRgGAy

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version] 6.5.5
[Reproduction Path] Whether the ID generated by setting RANDOM on the primary key in a single table is sequentially incremented

| username: 芮芮是产品 | Original post link

It is auto-increment, not sequentially increasing.

| username: h5n1 | Original post link

Yes, when inserting multiple rows at once

| username: 像风一样的男子 | Original post link

The specific structure of the AUTO_RANDOM column value is as follows:

Total Bits Sign Bit Reserved Bits Shard Bits Incremental Bits
64 bits 0/1 bit (64-R) bits S bits (R-1-S) bits
  • The length of the sign bit is determined by whether the column has the UNSIGNED attribute: if it exists, it is 0; otherwise, it is 1.
  • The length of the reserved bits is 64-R, and the content of the reserved bits is always 0.
  • The content of the shard bits is obtained by calculating the hash value of the start time of the current transaction. To use a different number of shard bits (e.g., 10), you can specify AUTO_RANDOM(10) when creating the table.
  • The value of the incremental bits is stored in the storage engine and allocated sequentially, incrementing by 1 each time a value is allocated. The incremental bits ensure the global uniqueness of the AUTO_RANDOM column value.
| username: Fly-bird | Original post link

Random auto-increment

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.