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: Support multiple table rename #19962

Merged
merged 38 commits into from
Oct 28, 2020

Conversation

TszKitLo40
Copy link
Contributor

@TszKitLo40 TszKitLo40 commented Sep 12, 2020

What problem does this PR solve?

Issue Number: close #9384
Related to PR: pingcap/parser#1021

Problem Summary:

What is changed and how it works?

What's Changed:
Support multiple table rename
RENAME TABLE tbl_name TO new_tbl_name [, tbl_name2 TO new_tbl_name2] ...

Check List

Tests

  • Unit test

Release note

  • Support multiple table rename

@TszKitLo40 TszKitLo40 requested a review from a team as a code owner September 12, 2020 03:42
@TszKitLo40 TszKitLo40 requested review from fzhedu and removed request for a team September 12, 2020 03:42
@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Sep 12, 2020
@github-actions github-actions bot added sig/sql-infra SIG: SQL Infra sig/execution SIG execution labels Sep 12, 2020
ddl/db_test.go Show resolved Hide resolved
ddl/ddl_api.go Outdated
SchemaName: newSchema.Name.L,
Type: model.ActionRenameTable,
BinlogInfo: &model.HistoryInfo{},
Args: []interface{}{oldSchemaIDs, tableNames, tableIDs},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Args: []interface{}{oldSchemaIDs, tableNames, tableIDs},
Args: []interface{}{oldSchemaIDs, newSchemaIDs, tableNames, tableIDs},

ddl/ddl_worker.go Show resolved Hide resolved
ddl/ddl_api.go Outdated
fmt.Sprintf("%s.%s", oldIdents[i].Schema, oldIdents[i].Name),
fmt.Sprintf("%s.%s", newIdents[i].Schema, newIdents[i].Name),
168,
fmt.Sprintf("Database `%s` doesn't exist", newIdents[i].Schema))
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 extract line4359-line4386 into a function? Then, both RenameTable and RenameTables can use this function.

ver, err := updateSchemaVersion(t, job)
if err != nil {
return ver, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto. Could we extract a function to reduce duplicate code?

ddl/db_test.go Outdated
Comment on lines 3258 to 3273
tk.MustExec("create database rename1")
tk.MustExec("create database rename2")
tk.MustExec("create database rename3")
tk.MustExec("create database rename4")
tk.MustExec("create table rename1.t1 (a int primary key auto_increment)")
tk.MustExec("create table rename3.t3 (a int primary key auto_increment)")
tk.MustExec("rename table rename1.t1 to rename2.t2, rename3.t3 to rename4.t4")
// Make sure the drop old database doesn't affect the rename2.t2, rename4.t4's operations.
tk.MustExec("drop database rename1")
tk.MustExec("drop database rename3")
tk.MustExec("insert rename2.t2 values ()")
tk.MustExec("insert rename4.t4 values ()")
tk.MustQuery("select * from rename2.t2").Check(testkit.Rows("1"))
tk.MustQuery("select * from rename4.t4").Check(testkit.Rows("1"))
tk.MustExec("drop database rename2")
tk.MustExec("drop database rename4")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this part is duplicate with the following part. It can be removed.
However, more cases are needed.
E.g.

create table rename1.t1 (a int primary key auto_increment);
create table rename3.t3 (a int primary key auto_increment);
rename table rename1.t1 to rename2.t2, rename3.t3 to rename2.t2;    # fail
rename table rename1.t1 to rename2.t2, rename2.t2 to rename1.t1;    # succeed

ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 27, 2020
ti-srebot
ti-srebot previously approved these changes Oct 27, 2020
@bb7133 bb7133 added the require-LGT3 Indicates that the PR requires three LGTM. label Oct 27, 2020
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM
ps: remember to add ActionRenameTables to cancel logic in rollingback.go

@ti-srebot ti-srebot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Oct 27, 2020
@TszKitLo40
Copy link
Contributor Author

TszKitLo40 commented Oct 27, 2020

LGTM
ps: remember to add ActionRenameTables to cancel logic in rollingback.go

Do you mean we should add ActionRenameTables in the L444 in rollingback.go?

@ti-challenge-bot
Copy link

There is no reward for this challenge pull request, so you can request a reward from @zimulala.

Details

Tip : About reward you can refs to reward-command.

Warning: None

@AilinKid
Copy link
Contributor

LGTM
ps: remember to add ActionRenameTables to cancel logic in rollingback.go

Do you mean we should add ActionRenameTables in the L444 in rollingback.go?

yes, just like model.ActionRenameTable

@ti-challenge-bot
Copy link

There is no reward for this challenge pull request, so you can request a reward from @zimulala.

Details

Tip : About reward you can refs to reward-command.

Warning: None

@TszKitLo40
Copy link
Contributor Author

LGTM
ps: remember to add ActionRenameTables to cancel logic in rollingback.go

Do you mean we should add ActionRenameTables in the L444 in rollingback.go?

yes, just like model.ActionRenameTable

I have added it.

@ti-challenge-bot
Copy link

There is no reward for this challenge pull request, so you can request a reward from @zimulala.

Details

Tip : About reward you can refs to reward-command.

Warning: None

@AilinKid
Copy link
Contributor

good, you can make tidy to resolve the go.sum's conflicts

@djshow832
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 28, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@djshow832 djshow832 merged commit 91db54e into pingcap:master Oct 28, 2020
@Rustin170506
Copy link
Member

@djshow832 Please don't merge PR when the CI still pending.
image

cc: @TszKitLo40 @zimulala

@djshow832
Copy link
Contributor

@zimulala is on leave and can't give the reward. @hi-rustin

@djshow832
Copy link
Contributor

/reward 1500

@ti-challenge-bot
Copy link

This PR already closed!

@XuHuaiyu XuHuaiyu removed the sig/execution SIG execution label Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge-program contribution This PR is from a community contributor. require-LGT3 Indicates that the PR requires three LGTM. sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple table rename (swap table use case)
8 participants