-
Notifications
You must be signed in to change notification settings - Fork 693
docs: clarify AUTO_RANDOM_BASE usage and explicit insert behavior #20734
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Conversation
Warning You have reached your daily quota limit. As a reminder, free tier users are limited to 5 requests per day. Please wait up to 24 hours and I will start processing your requests again! |
cf4c762
to
2a8de50
Compare
2a8de50
to
be6b29d
Compare
To confirm the behavior described in the documentation updates, I ran the following tests on a local TiDB instance: 1. Create Table: CREATE TABLE t (a BIGINT PRIMARY KEY AUTO_RANDOM, b VARCHAR(255));
2. Attempt ALTER TABLE t AUTO_RANDOM_BASE=0;
SHOW WARNINGS;
(Confirms the command completes with a warning but doesn't reset to 0.) 3. Attempt ALTER TABLE t FORCE AUTO_RANDOM_BASE=0;
(Confirms forcing the base to 0 results in an error.) 4. Attempt ALTER TABLE t FORCE AUTO_RANDOM_BASE = 1000;
(Confirms forcing the base to a non-zero value succeeds.) 5. Insert data after forcing base to 1000: INSERT INTO t (b) VALUES ('test1'), ('test2');
SELECT * FROM t WHERE b LIKE 'test%';
(Confirms the auto-increment part starts from the forced base value.) These results align with the behavior described in the updated documentation. |
auto-random.md
Outdated
|
||
> **Note:** | ||
> | ||
> * If you try to alter `AUTO_RANDOM_BASE` without the `FORCE` keyword, the value will not change. The command completes, but the base value stays unchanged. A subsequent `SHOW WARNINGS` reveals the specific warning `Can't reset AUTO_INCREMENT to 0 without FORCE option, using 1 instead`. |
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.
If you try to alter
AUTO_RANDOM_BASE
without theFORCE
keyword,
the value WILL not change even if the warning is reported. We should suggest ignoring the warning instead of using FORCE
(see my comment above)
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.
@tangenta I appreciate this critical correction. I've updated the documentation to clearly state that when using AUTO_RANDOM_BASE=0
without the FORCE
keyword, "the value will change and you can safely ignore this warning." This is an important distinction that users need to know.
The warning message itself (Can't reset AUTO_INCREMENT to 0 without FORCE option, using XXX instead
) is a bit misleading since it mentions AUTO_INCREMENT
instead of AUTO_RANDOM
and suggests the change isn't happening when it actually is. Would updating this warning message be something to consider for a future release?
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.
Suggestion just in case you are considering updating the warning message: "AUTO_RANDOM_BASE has been updated to XXX. You specified '0' which triggered automatic rebasing to prevent ID collisions."
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.
Mention conflicts happen in deployments with multiple TiDB nodes.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Adjustments based on the review by @tangenta
fixing link that had an extra slash "/"
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
|
||
You can run the `ALTER TABLE` statement to set `AUTO_RANDOM_BASE=0` to clear the auto-increment ID cache on all TiDB nodes in the cluster. For example: | ||
The collision happens as follows: each `AUTO_RANDOM` ID contains an auto-incrementing part alongside random bits. TiDB uses an internal counter for this auto-incrementing part. If you explicitly insert an ID where the auto-incrementing part matches the counter's next value, a duplicate key error might occur when TiDB later attempts to generate the same ID automatically. For more details, see [AUTO_INCREMENT Uniqueness](/auto-increment.md#uniqueness). |
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.
The collision happens as follows: each `AUTO_RANDOM` ID contains an auto-incrementing part alongside random bits. TiDB uses an internal counter for this auto-incrementing part. If you explicitly insert an ID where the auto-incrementing part matches the counter's next value, a duplicate key error might occur when TiDB later attempts to generate the same ID automatically. For more details, see [AUTO_INCREMENT Uniqueness](/auto-increment.md#uniqueness). | |
The collision happens as follows: each `AUTO_RANDOM` ID consists of random bits and an auto-incrementing part. TiDB uses an internal counter for this auto-incrementing part. If you explicitly insert an ID where the auto-incrementing part matches the counter's next value, a duplicate key error might occur when TiDB later attempts to generate the same ID automatically. For more details, see [AUTO_INCREMENT Uniqueness](/auto-increment.md#uniqueness). |
``` | ||
Query OK, 0 rows affected, 1 warning (0.52 sec) | ||
``` | ||
This statement automatically determines an appropriate base value. Although it produces a warning message similar to `Can't reset AUTO_INCREMENT to 0 without FORCE option, using XXX instead`, the value **will** change and you can safely ignore this warning. |
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.
This statement automatically determines an appropriate base value. Although it produces a warning message similar to `Can't reset AUTO_INCREMENT to 0 without FORCE option, using XXX instead`, the value **will** change and you can safely ignore this warning. | |
This statement automatically determines an appropriate base value. Although it produces a warning message similar to `Can't reset AUTO_INCREMENT to 0 without FORCE option, using XXX instead`, the base value **will** change and you can safely ignore this warning. |
+---------+------+-------------------------------------------------------------------------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
This approach is less convenient because it requires you to determine an appropriate value yourself. |
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.
This approach is less convenient because it requires you to determine an appropriate value yourself. | |
This approach is less convenient because it requires you to determine an appropriate base value yourself. |
|
||
> **Note:** | ||
> | ||
> You must use a non-zero positive integer value when using `FORCE`. |
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.
> You must use a non-zero positive integer value when using `FORCE`. | |
> When using `FORCE`, you must specify a non-zero positive integer. |
First-time contributors' checklist
What is changed, added or deleted? (Required)
Close issue: #20732
This PR updates the "Clear the auto-increment ID cache" section in
auto-random.md
to address confusion reported in the issue above. Specifically, the changes:ALTER TABLE ... AUTO_RANDOM_BASE
without theFORCE
keyword does not actually change the value, despite the warning message.FORCE
keyword is mandatory to modifyAUTO_RANDOM_BASE
.AUTO_RANDOM_BASE
to0
, even withFORCE
, will result in an error.FORCE
.AUTO_RANDOM
IDs, potentially leading to duplicate key errors.Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions.
What is the related PR or file link(s)?
auto-random.md
Do your changes match any of the following descriptions?