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

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -1377,9 +1377,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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not change these codes and remove line1393-1295 to fix it?

Copy link
Contributor Author

@jiyfhust jiyfhust Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afaid it can't work if we just remove line 1393-1395, because the infoschema builder will applyTableUpdate on a not normal "SchemaDiff". It will give applyTableUpdate a risk, is it?

Copy link
Contributor

@zimulala zimulala Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be fixed, but it does have potential risks. We may need to remove "applyTableUpdate" like "applyCreateTables" for safety.

Or we can do this according to your PR first, and then do unification.

Copy link
Contributor Author

@jiyfhust jiyfhust Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do unification later and i'm pleased to do that. We can choose the second method first, because it is a simple and reliable way to fix the problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We can fix the bug first.
Thank you very much for the follow-up help to unify this logic.

continue
}
affects[i-1] = &model.AffectedOption{
SchemaID: newSchemaID,
TableID: tableIDs[i],
OldTableID: tableIDs[i],
Expand Down