Skip to content

insert get duplicate key on auto_increment column after rename table #55846

@joechenrh

Description

@joechenrh

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

This error is found by #52688. There are two ways to reproduce this error.

  1. Apply the following change on master and run TestRenameTable
diff --git a/pkg/executor/test/ddl/main_test.go b/pkg/executor/test/ddl/main_test.go
index f5f05d63d2..7159aefdb9 100644
--- a/pkg/executor/test/ddl/main_test.go
+++ b/pkg/executor/test/ddl/main_test.go
@@ -24,7 +24,7 @@ import (
 )
 
 func TestMain(m *testing.M) {
-	autoid.SetStep(5000)
+	autoid.SetStep(1)
 	config.UpdateGlobal(func(conf *config.Config) {
 		conf.Log.SlowThreshold = 30000 // 30s
 		conf.TiKVClient.AsyncCommit.SafeWindow = 0
-- 
2.39.3 (Apple Git-146)

Start tidb server and run following SQLs:

create database test1;
create database test2;
create table test1.t (a int primary key auto_increment);
insert into test1.t values();
rename table test1.t to test2.t;
drop database test1;

Restart server and run

insert into test2.t values();

2. What did you expect to see? (Required)

  1. Test passed.
  2. Insert succeed.

3. What did you see instead (Required)

  1. Test failed.
  2. ERROR 1062 (23000): Duplicate entry '1' for key 't.PRIMARY'

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.severity/majortype/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