Skip to content

Commit 9bc709a

Browse files
authored
ddl: fix duplicate inforSchema information of rename tables (#47087) (#47142)
close #47064
1 parent 2a3255d commit 9bc709a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

ddl/db_rename_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,15 @@ func TestRenameMultiTables(t *testing.T) {
293293
tk.MustExec("drop database test1")
294294
tk.MustExec("drop database test")
295295
}
296+
297+
func TestRenameMultiTablesIssue47064(t *testing.T) {
298+
store := testkit.CreateMockStore(t, mockstore.WithDDLChecker())
299+
300+
tk := testkit.NewTestKit(t, store)
301+
tk.MustExec("use test")
302+
tk.MustExec("create table t1(a int)")
303+
tk.MustExec("create table t2(a int)")
304+
tk.MustExec("create database test1")
305+
tk.MustExec("rename table test.t1 to test1.t1, test.t2 to test1.t2")
306+
tk.MustQuery("select column_name from information_schema.columns where table_name = 't1'").Check(testkit.Rows("a"))
307+
}

ddl/ddl_worker.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,13 @@ func updateSchemaVersion(d *ddlCtx, t *meta.Meta, job *model.Job, multiInfos ...
13551355
if err != nil {
13561356
return 0, errors.Trace(err)
13571357
}
1358-
affects := make([]*model.AffectedOption, len(newSchemaIDs))
1358+
affects := make([]*model.AffectedOption, len(newSchemaIDs)-1)
13591359
for i, newSchemaID := range newSchemaIDs {
1360-
affects[i] = &model.AffectedOption{
1360+
// Do not add the first table to AffectedOpts. Related issue tidb#47064.
1361+
if i == 0 {
1362+
continue
1363+
}
1364+
affects[i-1] = &model.AffectedOption{
13611365
SchemaID: newSchemaID,
13621366
TableID: tableIDs[i],
13631367
OldTableID: tableIDs[i],

ddl/fktest/foreign_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ func TestRenameTablesWithForeignKey(t *testing.T) {
15661566
// check the schema diff
15671567
diff := getLatestSchemaDiff(t, tk)
15681568
require.Equal(t, model.ActionRenameTables, diff.Type)
1569-
require.Equal(t, 3, len(diff.AffectedOpts))
1569+
require.Equal(t, 2, len(diff.AffectedOpts))
15701570

15711571
// check referred foreign key information.
15721572
t1ReferredFKs := getTableInfoReferredForeignKeys(t, dom, "test", "t1")

0 commit comments

Comments
 (0)