-
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
Unexpected side-effects of setting auto_increment #34142
Comments
Some additional information: a warning would be given in TiDB but not in MySQL after
|
Thanks for your help. How can I get this warning BTW? I just did this successfully in TiDB without warning:
|
/assign |
alter table test1 auto_increment=9223372036854775807;
alter table test1 auto_increment=9223372036854775803; -- This takes no effect! In the current implementation, TiDB does not allow to 'ATLER' the ID to a smaller value to avoid possible duplicate IDs in a distributed environment. No error is reported as this is compatible with MySQL: mysql> create table t (a int auto_increment primary key);
Query OK, 0 rows affected (0.06 sec)
mysql> alter table t auto_increment = 100;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into t values ();
Query OK, 1 row affected (0.02 sec)
mysql> alter table t auto_increment = 1;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into t values ();
Query OK, 1 row affected (0.02 sec)
mysql> select * from t;
+-----+
| a |
+-----+
| 100 |
| 101 |
+-----+
2 rows in set (0.01 sec) TiDB has no idea if the 'ALTER' ID is larger than the maximum ID in the table. Therefore, this must be achieved by the keyword 'FORCE': alter table test1 auto_increment=9223372036854775807; -- Oops, it is too large
alter table test1 FORCE auto_increment=9223372036854775803; -- This takes effect! |
One more question: create table test(
a bigint auto_increment,
b int,
primary key(a)
); I tried inserting values: mysql> insert into test values(1,2),
-> (9223372036854775806,3);
mysql> insert into test(b) values(100);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
mysql> select * from test;
+---------------------+------+
| a | b |
+---------------------+------+
| 1 | 2 |
| 9223372036854775806 | 3 |
+---------------------+------+
2 rows in set (0.00 sec)
mysql> insert into test values(9223372036854775807, 100);
Query OK, 1 row affected (0.01 sec)
mysql> select * from test;
+---------------------+------+
| a | b |
+---------------------+------+
| 1 | 2 |
| 9223372036854775806 | 3 |
| 9223372036854775807 | 100 |
+---------------------+------+
3 rows in set (0.00 sec) It's obvious that |
@CbcWestwolf Could you fix this issue in your PR? |
@tangenta I'll have a try to fix it. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
Successfully inserting
(9223372036854775803, 4)
Same sql done in MySQL:
3. What did you see instead (Required)
tidb reports error:
Additionally,
9223372036854775807
is within the range of BIGINT and thus, TiDB has no reason to report an error.4. What is your TiDB version? (Required)
ebdc784
The text was updated successfully, but these errors were encountered: