Skip to content

AutoID service client still used the old database id after rename for incremental diff load. #64561

@YangKeao

Description

@YangKeao

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Start a TiDB cluster:
tiup playground nightly
  1. 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)
  1. 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)
  1. 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)

  1. Insert successfully.
  2. The rebase should use new dbID.

3. What did you see instead (Required)

  1. Dup key error.
  2. 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)

Metadata

Metadata

Assignees

Labels

affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.report/customerCustomers have encountered this bug.severity/majorsig/sql-infraSIG: SQL Infratype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions