Skip to content
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

sql: update the step of the "Auto Increment ID" #842

Merged
merged 2 commits into from
Aug 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sql/mysql-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ TiDB 的自增 ID (Auto Increment ID) 只保证自增且唯一,并不保证连
>
> TiDB 实现自增 ID 的原理是每个 tidb-server 实例缓存一段 ID 值用于分配,用完这段值再去取下一段。

> 假设集群中有两个 tidb-server 实例 A 和 B(A 缓存 [1,5000] 的自增 ID,B 缓存 [5001,10000] 的自增 ID),
> 假设集群中有两个 tidb-server 实例 A 和 B(A 缓存 [1,30000] 的自增 ID,B 缓存 [30001,60000] 的自增 ID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在上面一行中增加 batch size的描述吧:“每个 tidb-server 实例对每一个表缓存一段 ID 值用于分配(目前一段是 30000 个 ID)”

>
> 依次执行操作:
>
> 1. 客户端向 B 插入一条将 `id` 设置为 1 的语句 `insert into t values (1, 1)`,并执行成功。
> 2. 客户端向 A 发送 Insert 语句 `insert into t (c) (1)`,这条语句中没有指定 `id` 的值,所以会由 A 分配,当前 A 缓存了 [1, 5000] 这段 ID,所以会分配 1 为自增 ID 的值,并把本地计数器加 1。而此时数据库中已经存在 `id` 为 1 的数据,最终返回 `Duplicated Error` 错误。
> 2. 客户端向 A 发送 Insert 语句 `insert into t (c) (1)`,这条语句中没有指定 `id` 的值,所以会由 A 分配,当前 A 缓存了 [1, 30000] 这段 ID,所以会分配 1 为自增 ID 的值,并把本地计数器加 1。而此时数据库中已经存在 `id` 为 1 的数据,最终返回 `Duplicated Error` 错误。


### 内建函数
Expand Down