Repository navigation
mysql: rewrite multi-table rename into one statement #6848
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
Merged
+528
−14
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
31be808
mysql: rewrite multi-table rename into one statement
harry-hao ce20889
fixup! mysql: rewrite multi-table rename into one statement
harry-hao ad9fcae
mysql: rename atomic rename query builder
lidezhu c9e2bbd
Merge remote-tracking branch 'upstream/master' into codex/fix/pr-6848…
lidezhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -972,3 +972,42 @@ func IsSplitable(tableInfo *common.TableInfo) bool { | |
|
|
||
| return common.IsSplitable(tableInfo.HasClusteredPrimaryKey(), tableInfo.GetIndices()) | ||
| } | ||
|
|
||
| // FixRenameTablesQuery takes a multi-statement rename query, and converts it into | ||
| // a single statement, for atomicity. | ||
| // | ||
| // A DDLEvent may have a blank query in two cases: (1) every renaming table is | ||
| // discarded by the table filter, or (2) every rename SQL is ignored by the | ||
| // event filter. The first case never reaches here because schema storage | ||
| // suppresses the event. The second case still reaches here, executing it will | ||
| // cause ER_EMPTY_QUERY(1065), so we return skip=true tells the caller to skip it. | ||
| func FixRenameTablesQuery(d *DDLEvent) (string, bool, error) { | ||
| if timodel.ActionType(d.Type) != timodel.ActionRenameTables { | ||
| return d.Query, false, nil | ||
| } | ||
|
|
||
| if strings.TrimSpace(d.Query) == "" { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't happen. Can you reproduce this scenario? |
||
| return "", true, nil | ||
| } | ||
|
|
||
| p := parser.New() | ||
| stmts, _, err := p.ParseSQL(d.Query) | ||
| if err != nil { | ||
| return "", false, err | ||
| } | ||
|
|
||
| rename := &ast.RenameTableStmt{} | ||
| for _, stmt := range stmts { | ||
| current, ok := stmt.(*ast.RenameTableStmt) | ||
| if !ok { | ||
| return "", false, errors.New("unexpected statement in rename-tables event") | ||
| } | ||
| rename.TableToTables = append( | ||
| rename.TableToTables, | ||
| current.TableToTables..., | ||
| ) | ||
| } | ||
|
|
||
| query, err := Restore(rename) | ||
| return query, false, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tests/integration_tests/rename_atomic/conf/changefeed.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # The changefeed enables redo storage for the redo apply phase and routes | ||
| # every table to `${table}_routed`, so each upstream rename generation maps | ||
| # to a distinct downstream generation. | ||
|
|
||
| [consistent] | ||
| level = "eventual" | ||
| storage = "file:///tmp/tidb_cdc_test/rename_atomic/redo" | ||
| flush-interval = 1000 | ||
| meta-flush-interval = 200 | ||
|
|
||
| [filter] | ||
| rules = ['rename_atomic.*'] | ||
|
|
||
| [sink] | ||
| [[sink.dispatchers]] | ||
| matcher = ['rename_atomic.*'] | ||
| target-schema = 'rename_atomic' | ||
| target-table = '{table}_routed' |
22 changes: 22 additions & 0 deletions
22
tests/integration_tests/rename_atomic/data/create_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| CREATE DATABASE IF NOT EXISTS rename_atomic; | ||
| USE rename_atomic; | ||
| CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t2 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t3 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t4 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t5 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t6 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t7 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t8 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t9 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t10 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t11 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t12 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t13 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t14 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t15 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t16 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t17 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t18 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t19 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); | ||
| CREATE TABLE t20 (id INT PRIMARY KEY AUTO_INCREMENT, value INT); |
21 changes: 21 additions & 0 deletions
21
tests/integration_tests/rename_atomic/data/rename_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| RENAME TABLE | ||
| rename_atomic.t1 TO rename_atomic.s1, | ||
| rename_atomic.t2 TO rename_atomic.s2, | ||
| rename_atomic.t3 TO rename_atomic.s3, | ||
| rename_atomic.t4 TO rename_atomic.s4, | ||
| rename_atomic.t5 TO rename_atomic.s5, | ||
| rename_atomic.t6 TO rename_atomic.s6, | ||
| rename_atomic.t7 TO rename_atomic.s7, | ||
| rename_atomic.t8 TO rename_atomic.s8, | ||
| rename_atomic.t9 TO rename_atomic.s9, | ||
| rename_atomic.t10 TO rename_atomic.s10, | ||
| rename_atomic.t11 TO rename_atomic.s11, | ||
| rename_atomic.t12 TO rename_atomic.s12, | ||
| rename_atomic.t13 TO rename_atomic.s13, | ||
| rename_atomic.t14 TO rename_atomic.s14, | ||
| rename_atomic.t15 TO rename_atomic.s15, | ||
| rename_atomic.t16 TO rename_atomic.s16, | ||
| rename_atomic.t17 TO rename_atomic.s17, | ||
| rename_atomic.t18 TO rename_atomic.s18, | ||
| rename_atomic.t19 TO rename_atomic.s19, | ||
| rename_atomic.t20 TO rename_atomic.s20; |
21 changes: 21 additions & 0 deletions
21
tests/integration_tests/rename_atomic/data/rename_tables_2nd.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| RENAME TABLE | ||
| rename_atomic.s1 TO rename_atomic.r1, | ||
| rename_atomic.s2 TO rename_atomic.r2, | ||
| rename_atomic.s3 TO rename_atomic.r3, | ||
| rename_atomic.s4 TO rename_atomic.r4, | ||
| rename_atomic.s5 TO rename_atomic.r5, | ||
| rename_atomic.s6 TO rename_atomic.r6, | ||
| rename_atomic.s7 TO rename_atomic.r7, | ||
| rename_atomic.s8 TO rename_atomic.r8, | ||
| rename_atomic.s9 TO rename_atomic.r9, | ||
| rename_atomic.s10 TO rename_atomic.r10, | ||
| rename_atomic.s11 TO rename_atomic.r11, | ||
| rename_atomic.s12 TO rename_atomic.r12, | ||
| rename_atomic.s13 TO rename_atomic.r13, | ||
| rename_atomic.s14 TO rename_atomic.r14, | ||
| rename_atomic.s15 TO rename_atomic.r15, | ||
| rename_atomic.s16 TO rename_atomic.r16, | ||
| rename_atomic.s17 TO rename_atomic.r17, | ||
| rename_atomic.s18 TO rename_atomic.r18, | ||
| rename_atomic.s19 TO rename_atomic.r19, | ||
| rename_atomic.s20 TO rename_atomic.r20; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FixRenameTablesQueryis not a good name, maybeBuildAtomicRenameTablesQueryis more appropriate?