Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
- Start a TiDB cluster:
- Create a database and a table with
AUTO_ID_CACHE=1. Insert some rows into it, rename it to a new database.
mysql> use test;
Database changed
mysql> create table t(id int primary key auto_increment) AUTO_ID_CACHE=1;
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t values ();
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values ();
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values ();
Query OK, 1 row affected (0.00 sec)
mysql> create database test2;
Query OK, 0 rows affected (0.02 sec)
mysql> alter table t rename test2.t;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into test2.t values ();
Query OK, 1 row affected (0.00 sec)
- Insert into
test2.t with explicit id:
mysql> insert into test2.t values (100);
Query OK, 1 row affected (0.00 sec)
Read the tidb log, you'll find that it still used the old database id:
[2025/11/19 16:19:55.895 +08:00] [INFO] [autoid.go:194] ["alloc4Signed from"] [category="autoid service"] [dbID=112] [tblID=117] ["from base"=0] ["from end"=0] ["to base"=0] ["to end"=4000]
dbID=112 is test, but not test2. test2 is 119.
Now, the content of test2.t is:
mysql> select * from test2.t;
+-----+
| id |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 100 |
+-----+
5 rows in set (0.00 sec)
- Start a new TiDB and attach to this cluster, insert into
t on this new TiDB:
mysql> insert into test2.t values ();
ERROR 1062 (23000): Duplicate entry '1' for key 't.PRIMARY'
2. What did you expect to see? (Required)
- Insert successfully.
- The
rebase should use new dbID.
3. What did you see instead (Required)
- Dup key error.
- The
rebase still used old dbID.
I think it's related to the diff load schema. The allocator is not renewed after loading the diff when the db changed.
4. What is your TiDB version? (Required)
mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-309-g6499b2f
Edition: Community
Git Commit Hash: 6499b2ff017629efa9ec1f23e8260c53681e2314
Git Branch: HEAD
UTC Build Time: 2025-08-13 02:44:13
GoVersion: go1.23.12
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Kernel Type: Classic |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
AUTO_ID_CACHE=1. Insert some rows into it, rename it to a new database.test2.twith explicit id:Read the tidb log, you'll find that it still used the old database id:
dbID=112istest, but nottest2.test2is119.Now, the content of
test2.tis:ton this new TiDB:2. What did you expect to see? (Required)
rebaseshould use newdbID.3. What did you see instead (Required)
rebasestill used olddbID.I think it's related to the diff load schema. The allocator is not renewed after loading the diff when the db changed.
4. What is your TiDB version? (Required)