Skip to content

CI validation only: Bug#102586 multi-table DELETE FK cascade (do not merge) - #1

Closed
matanbaruch wants to merge 3 commits into
trunkfrom
bug102586-multi-table-delete-fk-cascade
Closed

CI validation only: Bug#102586 multi-table DELETE FK cascade (do not merge)#1
matanbaruch wants to merge 3 commits into
trunkfrom
bug102586-multi-table-delete-fk-cascade

Conversation

@matanbaruch

Copy link
Copy Markdown
Owner

Not for merge. This exists only to run the upstream CI workflows against the branch, because they cannot run on the real PR (mysql#719): every pull_request_target workflow refuses to check out fork code.

Same commit as mysql#719.

A multi-table DELETE that names both a foreign key parent table and a
child table with a cascading delete rule breaks row-based replication.
The replica applier stops with ER_KEY_NOT_FOUND.

The parent row is deleted while the join is still scanning, so the
cascade removes the child rows and logs row events for them. The
statement logs row events for the child rows it deletes itself as well.
On the replica the parent delete is applied first, its own cascade
removes the child rows, and the logged child events then cannot find
them.

Exclude a delete target from immediate deletion when deleting from it
cascades to another table in the same query, which defers the delete
until the join has finished. The check is added to both the classic
optimizer (GetImmediateDeleteTables) and the hypergraph optimizer
(IsImmediateDeleteCandidate).

Only ON DELETE CASCADE is considered. ON DELETE SET NULL updates the
child rows rather than deleting them, so they stay findable for the
logged events and replicate correctly. Deferring those deletes as well
would change which rows the statement removes.

This is the approach Zsolt Parragi contributed on Bug#80821 in 2019,
adapted to the current code: get_cascade_foreign_key_table_list() no
longer exists, so the cascade dependency is resolved from
TABLE_SHARE::foreign_key_parent instead.
@matanbaruch matanbaruch reopened this Aug 13, 2026
@github-actions github-actions Bot added Optimizer Changes touching optimizer code Tests Changes touching test code or test data Build Passed PR build passed MTR Failed MTR suite failed labels Aug 13, 2026
@github-actions github-actions Bot removed Build Passed PR build passed MTR Failed MTR suite failed labels Aug 21, 2026
… change

Format Check runs clang-format-18 over whole changed files. These three are
not clean under 18 on trunk, so the gate fails for any PR touching them.

Cosmetic only: a label space in sql_base.cc, one DBUG_LOG argument wrap in
sql_delete.cc, and two string literal joins in join_optimizer.cc.
@github-actions github-actions Bot added Build Passed PR build passed MTR Passed MTR suite passed labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Passed PR build passed MTR Passed MTR suite passed Optimizer Changes touching optimizer code Tests Changes touching test code or test data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant