-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reference/sql: add some details to the document of auto_random #2478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
@bb7133 PTAL
+ 如果该 `INSERT` 语句没有指定整型主键列(`a` 列)的值,TiDB 会为该列自动分配值。该值不保证自增,不保证连续,只保证唯一,避免了连续的行 ID 带来的热点问题。 | ||
+ 如果该 `INSERT` 语句显式指定了整型主键列的值,和 `AUTO_INCREMENT` 属性类似,TiDB 会保存该值。 | ||
+ 如果该 `INSERT` 语句没有指定整型主键列(`a` 列)的值,或者指定为 `NULL`,TiDB 会为该列自动分配值。该值不保证自增,不保证连续,只保证唯一,避免了连续的行 ID 带来的热点问题。 | ||
+ 如果该 `INSERT` 语句显式指定了整型主键列的值,和 `AUTO_INCREMENT` 属性类似,TiDB 会保存该值。注意,如果系统变量 `@@sql_mode` 中没有设置 `NO_AUTO_VALUE_ON_ZERO`, 即使显式指定为 0,TiDB 也会为该列自动分配值。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ 如果该 `INSERT` 语句显式指定了整型主键列的值,和 `AUTO_INCREMENT` 属性类似,TiDB 会保存该值。注意,如果系统变量 `@@sql_mode` 中没有设置 `NO_AUTO_VALUE_ON_ZERO`, 即使显式指定为 0,TiDB 也会为该列自动分配值。 | |
+ 如果该 `INSERT` 语句显式指定了整型主键列的值,和 `AUTO_INCREMENT` 属性类似,TiDB 会保存该值。注意,如果未在系统变量 `@@sql_mode` 中设置 `NO_AUTO_VALUE_ON_ZERO`, 即使显式指定整型主键列的值为 `0`,TiDB 也会为该列自动分配值。 |
|
||
自动分配值的计算方式如下: | ||
|
||
该行值在二进制形式下的最高五位(称为 shard bits)由当前事务的开始时间决定,剩下的位数按照自增顺序分配数值。 | ||
该行值在二进制形式下,除去最高位(无论是 unsigned 还是 signed)的次高 5 位(称为 shard bits)由当前事务的开始时间决定,剩下的位数按照自增的顺序分配。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该行值在二进制形式下,除去最高位(无论是 unsigned 还是 signed)的次高 5 位(称为 shard bits)由当前事务的开始时间决定,剩下的位数按照自增的顺序分配。 | |
该行值在二进制形式下,除去最高位(无论是 unsigned 还是 signed)的次高五位(称为 shard bits)由当前事务的开始时间决定,剩下的位数按照自增的顺序分配。 |
|
||
另外,含有 `AUTO_RANDOM` 属性的表在系统表 `information_schema.tables` 中 `TIDB_ROW_ID_SHARDING_INFO` 一列的值为 `PK_AUTO_RANDOM_BITS=x`,其中 `x` 为 shard bits 的数量。 | ||
|
||
要获取上一次 TiDB 隐式分配的 id,可以使用 `select last_insert_id()` 查看,例如: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要获取上一次 TiDB 隐式分配的 id,可以使用 `select last_insert_id()` 查看,例如: | |
要获取上一次 TiDB 隐式分配的 ID,可以使用 `select last_insert_id()` 查看,例如: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Your auto merge job has been accepted, waiting for 2512, 2513, 2514 |
/run-all-tests |
cherry pick to release-3.1 in PR #2516 |
What is changed, added or deleted? (Required)
Add some details to the document of auto_random.
Which TiDB version(s) do your changes apply to? (Required)
If you select two or more versions from above, to trigger the bot to cherry-pick this PR to your desired release version branch(es), you must add corresponding labels such as needs-cherry-pick-3.1, needs-cherry-pick-3.0, and needs-cherry-pick-2.1.
What is the related PR or file link(s)?
pingcap/tidb#15145: fix last_insert_id in auto_random mode
pingcap/tidb#15262: show max allocate times when an auto_random table is created