Skip to content

[Subtask]: Apply parent-side foreign key actions during REPLACE #24951

Closed

Description

@ck89119

Parent Issue

Parent issue: #24918

Detail of Subtask

Make REPLACE apply parent-side foreign key semantics as delete-then-insert when a conflicting parent row is replaced.

The parent issue includes two representative cases:

  • ON DELETE RESTRICT: replacing a referenced parent row should fail because the old parent row is deleted before the new row is inserted.
  • ON DELETE CASCADE: replacing a referenced parent row should delete the old parent row, cascade-delete child rows, then insert the new parent row.

MatrixOne currently replaces the parent row successfully and leaves child rows unchanged in both cases.

Describe implementation you've considered

Model the conflicting-row removal part of REPLACE as a real delete for parent-side FK checks/actions, then perform the insert of the replacement row. Add BVT coverage for RESTRICT and CASCADE, and preserve atomicity when the delete action rejects the statement.

Additional information

Parent context: #24918, section 3.2.

MySQL reference: https://dev.mysql.com/doc/refman/8.4/en/replace.html

Activity

  1. added this to the MO-202606 milestone on Jun 12, 2026
  2. self-assigned this
    on Jun 12, 2026
  3. added
    severity/s0
    on Jun 12, 2026
  4. added
    severity/s1
    and removed
    severity/s0
    on Jun 30, 2026
  5. modified the milestones: MO-202606, MO-202607 on Jun 30, 2026
  6. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    Collaborator

    motr 黑盒回归补充

    已将该子任务加入 motr PR #75:

    • 用例:issue_24951_replace_parent_fk_actions.test
    • Happy Path:无冲突父行插入;ON DELETE CASCADE 替换父行后删除全部引用子行并插入新父行。
    • Unhappy Path:ON DELETE RESTRICT 拒绝被引用父行的替换;失败后父、子表数据均保持不变,并验证会话可继续使用。
    • MatrixOne main@607a9263616ea883ac02c052529d2aa4c62ac051 连续 3/3 通过(66/66 statements)。
    • 修复前 6c0d12dfc3c3c8cab7439beaa8efb00b8349a599 复现失败:RESTRICT 场景被错误允许。

    注:当前 MatrixOne 对父表 FK 拒绝返回既有错误码 20101;本 issue 的验收重点是 RESTRICT/CASCADE 语义与原子性。

  7. removed
    severity/s1
    on Aug 6, 2026
  8. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:`main`
    • commit:`ae12701a888fac102e9641cc7cbb8706527366d8`
    • 部署方式:本地 1CN/1TN/1Log,MySQL 协议
    • 测试日期:2026-08-25

    原问题验证

    在父表执行 `REPLACE`,分别覆盖 `ON DELETE CASCADE` 与 `ON DELETE RESTRICT`。连续 3 个独立轮次中,父表替换均不再遗漏应执行的父侧外键动作。

    Happy Path 覆盖

    1. `CASCADE`:替换父行后父表精确为 `(1,'new')`,关联子行数为 `0`。
    2. `RESTRICT`:无子行时替换成功,父行更新为目标值。
    3. 受限失败后执行正常查询和后续合法替换均成功,连接和会话可继续使用。

    Unhappy Path 覆盖

    1. `RESTRICT` 且存在引用子行时,`REPLACE` 返回明确的外键错误;父表仍为 `(1,'old')`、子表记录仍在,未出现部分写入。

    白盒验证

    不适用;该缺陷的可观察 SQL 语义、错误和失败原子性已由黑盒断言覆盖。

    回归测试

    已存在稳定的 motr PR #75 回归:issue_24951_replace_parent_fk_actions.test。该场景覆盖 CASCADE、RESTRICT、失败原子性和恢复执行,不需要大数据量测试。

    测试证据

    • latest main 独立执行 `3/3` 通过。
    • 回归用例已合入 motr `main`,文件链接如上。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions