Skip to content

Commit

Permalink
ddl: fix duplicate inforSchema information of rename tables (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 22, 2023
1 parent b0d4953 commit 6badab9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions ddl/db_rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,15 @@ func TestRenameMultiTables(t *testing.T) {
tk.MustExec("drop database test1")
tk.MustExec("drop database test")
}

func TestRenameMultiTablesIssue47064(t *testing.T) {
store := testkit.CreateMockStore(t, mockstore.WithDDLChecker())

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t1(a int)")
tk.MustExec("create table t2(a int)")
tk.MustExec("create database test1")
tk.MustExec("rename table test.t1 to test1.t1, test.t2 to test1.t2")
tk.MustQuery("select column_name from information_schema.columns where table_name = 't1'").Check(testkit.Rows("a"))
}
8 changes: 6 additions & 2 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,13 @@ func updateSchemaVersion(d *ddlCtx, t *meta.Meta, job *model.Job, multiInfos ...
if err != nil {
return 0, errors.Trace(err)
}
affects := make([]*model.AffectedOption, len(newSchemaIDs))
affects := make([]*model.AffectedOption, len(newSchemaIDs)-1)
for i, newSchemaID := range newSchemaIDs {
affects[i] = &model.AffectedOption{
// Do not add the first table to AffectedOpts. Related issue tidb#47064.
if i == 0 {
continue
}
affects[i-1] = &model.AffectedOption{
SchemaID: newSchemaID,
TableID: tableIDs[i],
OldTableID: tableIDs[i],
Expand Down
2 changes: 1 addition & 1 deletion ddl/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ func TestRenameTablesWithForeignKey(t *testing.T) {
// check the schema diff
diff := getLatestSchemaDiff(t, tk)
require.Equal(t, model.ActionRenameTables, diff.Type)
require.Equal(t, 3, len(diff.AffectedOpts))
require.Equal(t, 2, len(diff.AffectedOpts))

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

0 comments on commit 6badab9

Please sign in to comment.