Skip to content

Commit

Permalink
ddl: fix duplicate inforSchema information of rename tables (#47087) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed Oct 13, 2023
1 parent 2a3255d commit 9bc709a
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 @@ -1355,9 +1355,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/fktest/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,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 9bc709a

Please sign in to comment.