Skip to content

Commit 6badab9

Browse files
authored
ddl: fix duplicate inforSchema information of rename tables (#47087) (#47141)
close #47064
1 parent b0d4953 commit 6badab9

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
@@ -1542,9 +1542,13 @@ func updateSchemaVersion(d *ddlCtx, t *meta.Meta, job *model.Job, multiInfos ...
15421542
if err != nil {
15431543
return 0, errors.Trace(err)
15441544
}
1545-
affects := make([]*model.AffectedOption, len(newSchemaIDs))
1545+
affects := make([]*model.AffectedOption, len(newSchemaIDs)-1)
15461546
for i, newSchemaID := range newSchemaIDs {
1547-
affects[i] = &model.AffectedOption{
1547+
// Do not add the first table to AffectedOpts. Related issue tidb#47064.
1548+
if i == 0 {
1549+
continue
1550+
}
1551+
affects[i-1] = &model.AffectedOption{
15481552
SchemaID: newSchemaID,
15491553
TableID: tableIDs[i],
15501554
OldTableID: tableIDs[i],

ddl/foreign_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ func TestRenameTablesWithForeignKey(t *testing.T) {
18491849
// check the schema diff
18501850
diff := getLatestSchemaDiff(t, tk)
18511851
require.Equal(t, model.ActionRenameTables, diff.Type)
1852-
require.Equal(t, 3, len(diff.AffectedOpts))
1852+
require.Equal(t, 2, len(diff.AffectedOpts))
18531853

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

0 commit comments

Comments
 (0)