Skip to content

[Bug]: Multi-table DELETE … JOIN deletes all rows instead of only matched rows #25098

Closed

Description

@dengn

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

v4.0.0-rc3

Commit ID

8.0.30-MatrixOne-v4.0.0-rc3

Other Environment Information

  • Hardware parameters: N/A
  • OS type: N/A
  • 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 ON a.id = b.id;
SELECT COUNT(*) FROM d1;   -- MatrixOne: 0 (table emptied)

Expected Behavior

Only rows of d1 that have a match in d2 are deleted:

SELECT COUNT(*) FROM d1;   -- MySQL: 1 (only id=1 deleted)

Steps to Reproduce

CREATE TABLE d1 (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 ON a.id = b.id;
SELECT COUNT(*) FROM d1;   -- MySQL: 1   MatrixOne: 0

Additional information

Impact: data loss for the common "delete rows that have a match in another table" pattern.

Background: dengn/php-tester#1.

Activity

  1. 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
  2. added
    kind/bug
    on Jun 23, 2026
  3. fengttt commented on Jun 23, 2026

    @fengttt
    Contributor

    Oh, this is a real, serious one. Someone work on it NOW.

  4. added theissue type on Jun 23, 2026
  5. added this to the MO-202606 milestone on Jun 24, 2026
  6. added
    severity/s0
    and removed
    severity/s0
    on Jun 24, 2026
  7. added 3 commits that reference this issue on Jun 24, 2026
    9fd1b7d
    8169ec8
    b51d354
  8. aunjgr commented on Jun 30, 2026

    @aunjgr
    Contributor

    PR will merge today.

  9. assigned and unassigned on Jun 30, 2026
  10. Ariznawlll commented on Jun 30, 2026

    @Ariznawlll
    Collaborator

    Verified on latest origin/main at 86d5526c2bb699ee2c52b26a9525e51fb1f963e3 (fix: DELETE with JOIN deletes all rows instead of only matched rows (#25125)).

    Validation SQL:

    drop database if exists issue_25098_verify;
    create database issue_25098_verify;
    use issue_25098_verify;
    
    create table d1(id int);
    create table d2(id int);
    insert into d1 values (1), (2), (3);
    insert into d2 values (1), (3);
    
    delete a from d1 a join d2 b on a.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.

  11. Ariznawlll commented on Jul 1, 2026

    @Ariznawlll
    Collaborator

    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:

    1. Minimal case
    create table d1(id int);
    create table d2(id int);
    insert into d1 values (1), (2), (3);
    insert into d2 values (1), (3);
    delete a from d1 a join d2 b on a.id = b.id;
    select * from d1 order by id;

    Result: only 2 remains. DELETE affected 2 rows.

    1. Duplicate RHS matches
    create table d1(id int, v int);
    create table d2(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 on a.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions