You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Multi-table DELETE … JOIN deletes all rows instead of only matched rows #25098
Others: Reproduced via cross-language ORM compatibility testing (PHP / Python / Java / Node.js) over the MySQL 8.0.30 wire protocol. The minimal repro below uses raw SQL so it is driver-independent.
Actual Behavior
A multi-table DELETE with a JOIN empties the target table instead of deleting only the matched rows.
DELETE a FROM d1 a JOIN d2 b ONa.id=b.id;
SELECTCOUNT(*) FROM d1; -- MatrixOne: 0 (table emptied)
Expected Behavior
Only rows of d1 that have a match in d2 are deleted:
SELECTCOUNT(*) FROM d1; -- MySQL: 1 (only id=1 deleted)
Steps to Reproduce
CREATETABLEd1 (id INT, n INT); CREATE TABLE d2 (id INT);
INSERT INTO d1 VALUES (1,1),(2,2); INSERT INTO d2 VALUES (1);
DELETE a FROM d1 a JOIN d2 b ONa.id=b.id;
SELECTCOUNT(*) FROM d1; -- MySQL: 1 MatrixOne: 0
Additional information
Impact: data loss for the common "delete rows that have a match in another table" pattern.
changed the title [-][correctness] Multi-table `DELETE … JOIN` deletes all rows instead of only matched rows[/-][+][Bug]: Multi-table DELETE … JOIN deletes all rows instead of only matched rows[/+]on Jun 23, 2026
Verified on latest origin/main at 86d5526c2bb699ee2c52b26a9525e51fb1f963e3 (fix: DELETE with JOIN deletes all rows instead of only matched rows (#25125)).
Validation SQL:
dropdatabase if exists issue_25098_verify;
createdatabaseissue_25098_verify;
use issue_25098_verify;
createtabled1(id int);
createtabled2(id int);
insert into d1 values (1), (2), (3);
insert into d2 values (1), (3);
delete a from d1 a join d2 b ona.id=b.id;
select*from d1 order by id;
Result:
+------+
| id |
+------+
| 2 |
+------+
Also verified another case with d1 = (1,2,3,4) and d2 = (2,4); after delete a from d1 a join d2 b on a.id = b.id, d1 correctly remained (1,3).
Conclusion: this issue is fixed on latest main; DELETE ... JOIN now deletes only matched rows instead of clearing the whole target table.
Verified on latest origin/4.0-dev at d7877e99d6405db471a5de9766e81ecd697167a1 ([4.0-dev] fix: DELETE with JOIN deletes all rows instead of only matched rows (#25134)).
Validation:
Minimal case
createtabled1(id int);
createtabled2(id int);
insert into d1 values (1), (2), (3);
insert into d2 values (1), (3);
delete a from d1 a join d2 b ona.id=b.id;
select*from d1 order by id;
Result: only 2 remains. DELETE affected 2 rows.
Duplicate RHS matches
createtabled1(id int, v int);
createtabled2(id int);
insert into d1 values (1,10), (2,20), (3,30), (4,40);
insert into d2 values (2), (2), (4), (4);
delete a from d1 a join d2 b ona.id=b.id;
select*from d1 order by id;
Result: (1,10) and (3,30) remain. DELETE affected 2 rows.
Conclusion: this issue is fixed on latest 4.0-dev.
Activity
[-][correctness] Multi-table `DELETE … JOIN` deletes all rows instead of only matched rows[/-][+][Bug]: Multi-table DELETE … JOIN deletes all rows instead of only matched rows[/+]fengttt commentedon Jun 23, 2026
Oh, this is a real, serious one. Someone work on it NOW.
fix: DELETE with JOIN now uses MULTI_UPDATE path
fix: DELETE with JOIN now uses MULTI_UPDATE path
fix: DELETE with JOIN now uses MULTI_UPDATE path
aunjgr commentedon Jun 30, 2026
PR will merge today.
Ariznawlll commentedon Jun 30, 2026
Verified on latest
origin/mainat86d5526c2bb699ee2c52b26a9525e51fb1f963e3(fix: DELETE with JOIN deletes all rows instead of only matched rows (#25125)).Validation SQL:
Result:
Also verified another case with
d1 = (1,2,3,4)andd2 = (2,4); afterdelete a from d1 a join d2 b on a.id = b.id,d1correctly remained(1,3).Conclusion: this issue is fixed on latest
main;DELETE ... JOINnow deletes only matched rows instead of clearing the whole target table.Ariznawlll commentedon Jul 1, 2026
Verified on latest
origin/4.0-devatd7877e99d6405db471a5de9766e81ecd697167a1([4.0-dev] fix: DELETE with JOIN deletes all rows instead of only matched rows (#25134)).Validation:
Result: only
2remains.DELETEaffected 2 rows.Result:
(1,10)and(3,30)remain.DELETEaffected 2 rows.Conclusion: this issue is fixed on latest
4.0-dev.