-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ddl: allow altering the auto_increment id 'back' to a small value #25400
Comments
I prefer to add a new syntax. Since this operation is unlikely to be done in business application code, I don't think a new session variable is needed: ALTER TABLE `t` FORCE AUTO_INCREMENT = 3;
ALTER TABLE `t` /*T![force_auto_inc] FORCE */ AUTO_INCREMENT = 3; There is another question: if the table contains an auto_id value that larger than the target value, how should TiDB handle it? MyISAM and InnoDB handle it differently:
|
Sounds reasonable!
I do not think we need to worry about it since it is a 'force rebase'. If there's a conflict because of the larger values, so be it. |
Does this option exist for sequences too? |
@kennytm Nope. I think we can drop and recreate the sequence to achieve the same purpose at a low cost.
@bb7133 In the previous implementation, TiDB does not handle the duplicated drop table if exists t;
create table t (a int);
insert into t values (1), (2), (3);
select a, _tidb_rowid from t;
alter table t force auto_increment = 1;
insert into t values (10000);
select a, _tidb_rowid from t;
Is it appropriate to simply return the "duplicate entry" error?
|
After investigation, I found that detecting Since |
Maybe |
@kennytm Personally, I prefer to skip
|
except for partitioned table the (I'm ignoring the cost of walking one step in the LSM tree here, which at worst is logarithmic.) |
Feature Request
Is your feature request related to a problem? Please describe:
For now, the auto ID in TiDB grows only and can never bet set 'back':
Although the
ALTER TABLE
statement returns success, the auto ID is not rebased back to3
, see #5472 (comment).If the auto ID is rebased to a very large value because of either mistake or bug, it is almost impossible to set it back, this can be a headache for the users.
Describe the feature you'd like:
We can provide a system variable named like 'tidb_enable_unsafe_auto_id_rebase' to allow 'forcing' the auto ID to a smaller value.
Describe alternatives you've considered:
For now, we do not have the alternative, the only way is recreating the table and importing the data.
Teachability, Documentation, Adoption, Migration Strategy:
See #25355 for the hacking PR.
The text was updated successfully, but these errors were encountered: