-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Bug#102586: multi-table DELETE with ON DELETE CASCADE breaks row-based replication #719
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
Open
matanbaruch
wants to merge
10
commits into
mysql:trunk
Choose a base branch
from
matanbaruch:bug102586-multi-table-delete-fk-cascade
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05415aa
Bug#102586 ON DELETE CASCADE breaks with RBR and multiple-table DELETE
matanbaruch 23e360a
Bug#39857308: Harden GitHub Actions and stabilize PR CI
RidhaOracle baeaf45
Merge branch 'trunk' into bug102586-multi-table-delete-fk-cascade
matanbaruch 6416dfc
Fix pre-existing clang-format violations in the files touched by this…
matanbaruch 6a37612
Cover all modifying referential actions, transitively, and multi-tabl…
matanbaruch b1f9b04
Handle engine-managed referential actions and diamond-shaped FK graphs
matanbaruch da35310
Merge remote-tracking branch 'upstream/trunk' into bug102586-multi-ta…
matanbaruch 25600d8
Consider tables read by subqueries when checking referential actions
matanbaruch facf677
Merge remote-tracking branch 'upstream/trunk' into bug102586-multi-ta…
matanbaruch d83d32d
Retrigger CI
matanbaruch 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
mysql-test/suite/rpl/r/rpl_multi_table_delete_fk_cascade.result
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,53 @@ | ||
| include/rpl/init_source_replica.inc | ||
| Warnings: | ||
| Note #### Sending passwords in plain text without SSL/TLS is extremely insecure. | ||
| Note #### Storing MySQL user name or password information in the connection metadata repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START REPLICA; see the 'START REPLICA Syntax' in the MySQL Manual for more information. | ||
| [connection master] | ||
| # | ||
| # ON DELETE CASCADE | ||
| # | ||
| CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB; | ||
| CREATE TABLE t2 ( | ||
| id INT PRIMARY KEY, | ||
| parent_id INT, | ||
| FOREIGN KEY (parent_id) REFERENCES t1(id) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB; | ||
| INSERT INTO t1 VALUES (1), (2); | ||
| INSERT INTO t2 VALUES (1, 1), (2, 1), (3, 2); | ||
| DELETE p, c FROM t1 p LEFT JOIN t2 c ON c.parent_id = p.id WHERE p.id = 1; | ||
| SELECT * FROM t1 ORDER BY id; | ||
| id | ||
| 2 | ||
| SELECT * FROM t2 ORDER BY id; | ||
| id parent_id | ||
| 3 2 | ||
| include/rpl/sync_to_replica.inc | ||
| include/diff_tables.inc [master:test.t1, slave:test.t1] | ||
| include/diff_tables.inc [master:test.t2, slave:test.t2] | ||
| [connection master] | ||
| DROP TABLE t2, t1; | ||
| # | ||
| # ON DELETE SET NULL, which is not deferred and not affected | ||
| # | ||
| CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB; | ||
| CREATE TABLE t2 ( | ||
| id INT PRIMARY KEY, | ||
| parent_id INT, | ||
| FOREIGN KEY (parent_id) REFERENCES t1(id) ON DELETE SET NULL | ||
| ) ENGINE=InnoDB; | ||
| INSERT INTO t1 VALUES (1), (2); | ||
| INSERT INTO t2 VALUES (1, 1), (2, 1), (3, 2); | ||
| DELETE p, c FROM t1 p LEFT JOIN t2 c ON c.parent_id = p.id WHERE p.id = 1; | ||
| SELECT * FROM t1 ORDER BY id; | ||
| id | ||
| 2 | ||
| SELECT * FROM t2 ORDER BY id; | ||
| id parent_id | ||
| 2 NULL | ||
| 3 2 | ||
| include/rpl/sync_to_replica.inc | ||
| include/diff_tables.inc [master:test.t1, slave:test.t1] | ||
| include/diff_tables.inc [master:test.t2, slave:test.t2] | ||
| [connection master] | ||
| DROP TABLE t2, t1; | ||
| include/rpl/deinit.inc | ||
89 changes: 89 additions & 0 deletions
89
mysql-test/suite/rpl/t/rpl_multi_table_delete_fk_cascade.test
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,89 @@ | ||
| # ==== Purpose ==== | ||
| # | ||
| # Check that a multi-table DELETE which names both a foreign key parent table | ||
| # and a child table with a cascading delete rule does not break row-based | ||
| # replication. | ||
| # | ||
| # ==== Implementation ==== | ||
| # | ||
| # 1. On the source, run a multi-table DELETE covering a parent table and its | ||
| # ON DELETE CASCADE child. | ||
| # 2. Synchronize the replica and compare both tables. Before this fix the | ||
| # applier stopped with ER_KEY_NOT_FOUND: the parent row was deleted while | ||
| # the join was still scanning, so the cascade removed the child rows on the | ||
| # replica before the logged child row events were applied. | ||
| # 3. Repeat with an ON DELETE SET NULL child, which replicates correctly and | ||
| # is covered here so the difference stays visible. | ||
| # | ||
| # ==== References ==== | ||
| # | ||
| # Bug#80821: Replication breaks if multi-table DELETE is used in conjunction | ||
| # with Foreign Key | ||
| # Bug#102586: Foreign Key ON DELETE CASCADE breaks with RBR and multiple-table | ||
| # DELETE | ||
| # | ||
| ############################################################################### | ||
| --source include/have_binlog_format_row.inc | ||
| --source include/rpl/init_source_replica.inc | ||
|
matanbaruch marked this conversation as resolved.
Outdated
|
||
|
|
||
| --echo # | ||
| --echo # ON DELETE CASCADE | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB; | ||
| CREATE TABLE t2 ( | ||
| id INT PRIMARY KEY, | ||
| parent_id INT, | ||
| FOREIGN KEY (parent_id) REFERENCES t1(id) ON DELETE CASCADE | ||
| ) ENGINE=InnoDB; | ||
|
|
||
| INSERT INTO t1 VALUES (1), (2); | ||
| INSERT INTO t2 VALUES (1, 1), (2, 1), (3, 2); | ||
|
|
||
| DELETE p, c FROM t1 p LEFT JOIN t2 c ON c.parent_id = p.id WHERE p.id = 1; | ||
|
|
||
| SELECT * FROM t1 ORDER BY id; | ||
| SELECT * FROM t2 ORDER BY id; | ||
|
|
||
| --source include/rpl/sync_to_replica.inc | ||
|
|
||
| --let $diff_tables= master:test.t1, slave:test.t1 | ||
| --source include/diff_tables.inc | ||
| --let $diff_tables= master:test.t2, slave:test.t2 | ||
| --source include/diff_tables.inc | ||
|
|
||
| --let $rpl_connection_name= master | ||
| --source include/connection.inc | ||
| DROP TABLE t2, t1; | ||
|
|
||
| --echo # | ||
| --echo # ON DELETE SET NULL, which is not deferred and not affected | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB; | ||
| CREATE TABLE t2 ( | ||
| id INT PRIMARY KEY, | ||
| parent_id INT, | ||
| FOREIGN KEY (parent_id) REFERENCES t1(id) ON DELETE SET NULL | ||
| ) ENGINE=InnoDB; | ||
|
|
||
| INSERT INTO t1 VALUES (1), (2); | ||
| INSERT INTO t2 VALUES (1, 1), (2, 1), (3, 2); | ||
|
|
||
| DELETE p, c FROM t1 p LEFT JOIN t2 c ON c.parent_id = p.id WHERE p.id = 1; | ||
|
|
||
| SELECT * FROM t1 ORDER BY id; | ||
| SELECT * FROM t2 ORDER BY id; | ||
|
|
||
| --source include/rpl/sync_to_replica.inc | ||
|
|
||
| --let $diff_tables= master:test.t1, slave:test.t1 | ||
| --source include/diff_tables.inc | ||
| --let $diff_tables= master:test.t2, slave:test.t2 | ||
| --source include/diff_tables.inc | ||
|
|
||
| --let $rpl_connection_name= master | ||
| --source include/connection.inc | ||
| DROP TABLE t2, t1; | ||
|
|
||
| --source include/rpl/deinit.inc | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.