Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix duplicate inforSchema information of rename tables (#47087) #47142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1352,9 +1352,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