-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ddl: Support multiple table rename #19962
Conversation
ddl/ddl_api.go
Outdated
SchemaName: newSchema.Name.L, | ||
Type: model.ActionRenameTable, | ||
BinlogInfo: &model.HistoryInfo{}, | ||
Args: []interface{}{oldSchemaIDs, tableNames, tableIDs}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args: []interface{}{oldSchemaIDs, tableNames, tableIDs}, | |
Args: []interface{}{oldSchemaIDs, newSchemaIDs, tableNames, tableIDs}, |
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)) |
There was a problem hiding this comment.
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) | ||
} |
There was a problem hiding this comment.
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
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") |
There was a problem hiding this comment.
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
There was a problem hiding this 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
Do you mean we should add |
There is no reward for this challenge pull request, so you can request a reward from @zimulala. |
yes, just like |
There is no reward for this challenge pull request, so you can request a reward from @zimulala. |
…zKitLo40/tidb into support-multiple-table-rename
I have added it. |
There is no reward for this challenge pull request, so you can request a reward from @zimulala. |
good, you can |
/merge |
/run-all-tests |
@djshow832 Please don't merge PR when the CI still pending. cc: @TszKitLo40 @zimulala |
@zimulala is on leave and can't give the reward. @hi-rustin |
/reward 1500 |
This PR already closed! |
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
Release note