-
Notifications
You must be signed in to change notification settings - Fork 680
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 description of auto id conflicts #488
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,22 @@ The auto-increment ID feature in TiDB is only guaranteed to be automatically inc | |
|
||
> **Warning**: | ||
> | ||
> If you use the auto-increment ID in a cluster with multiple TiDB servers, do not mix the default value and the custom value, because it reports an error in the following situation: | ||
> If you use the auto-increment ID in a cluster with multiple tidb-server instances, do not mix the default value and the custom value, otherwise an error occurs in the following situation: | ||
> | ||
> In a cluster of two TiDB servers, namely TiDB A and TiDB B, TiDB A caches [1,5000] auto-increment ID, while TiDB B caches [5001,10000] auto-increment ID. Use the following statement to create a table with auto-increment ID: | ||
> Assume that you have a table with the auto-increment ID: | ||
> | ||
> ``` | ||
> create table t(id int unique key auto_increment, c int); | ||
> ``` | ||
> | ||
> The principle of the auto-increment ID in TiDB is that each tidb-server instance caches a section of ID values for allocation and fetches the next section after this section is used up. | ||
> | ||
> The statement is executed as follows: | ||
> Assume that the cluster contains two tidb-server instances, namely Instance A and Instance B. Instance A caches the auto-increment ID of [1,5000], while Instance B caches the auto-increment ID of [5001,10000]. | ||
> | ||
> The operations are executed as follows: | ||
> | ||
> 1. The client inserts a statement to TiDB B which sets the `id` to be 1 and the statement is executed successfully. | ||
> 2. The client inserts a record to TiDB A which sets the `id` set to the default value 1. In this case, it returns `Duplicated Error`. | ||
> 1. The client inserts the `insert into t values (1, 1)` statement to Instance B which sets the `id` to 1 and the statement is executed successfully. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The client inserts -> The client issues |
||
> 2. The client inserts the `insert into t (c) (1)` statement to Instance A. This statement does not specify the value of `id`, therefore Instance A allocates the value. Currently, Instances A caches the auto-increment ID of [1,5000], so it allocates the `id` value to 1 and adds 1 to the local counter. However, at this time the data with the `id` of 1 already exists in the cluster, therefore it reports `Duplicated Error`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
||
### Built-in functions | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[1,5000] -> [1, 5000]
[5001,10000] -> [5001, 10000]