Skip to content

[Bug]: INSERT IGNORE ... ON DUPLICATE KEY UPDATE aborts on FK violation and discards valid sibling inserts #33522

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues, including closed issues.

Open #33478 covers similar FK/IGNORE sibling loss for UPDATE/DELETE, and #30345 covered LOAD DATA IGNORE. Neither covers this INSERT IGNORE ... ON DUPLICATE KEY UPDATE action-stream path. #28254 is limited to missing warnings for rows already skipped correctly and does not cover this statement abort.

Branch Name

main

Commit ID

98b2097

Other Environment Information

  • Test date: 2026-11-30
  • Deployment: local standalone mo-service, 1 CN / 1 TN / 1 LogService, MySQL text protocol
  • Runtime identity checked with git_version()='98b20975' and SELECT 42
  • Comparator: MySQL 8.0.46, InnoDB

Description

When one INSERT IGNORE ... ON DUPLICATE KEY UPDATE batch contains both an FK-invalid duplicate UPDATE and a valid new sibling INSERT, MatrixOne raises error 1452 and rolls back the valid sibling operation.

MySQL instead downgrades the FK violation to warning 1452, skips only the invalid duplicate UPDATE, and commits the valid sibling INSERT.

Steps to Reproduce

CREATE TABLE fp(id INT PRIMARY KEY);
CREATE TABLE fc(
  id INT PRIMARY KEY,
  pid INT,
  v VARCHAR(20),
  CONSTRAINT fc_pid FOREIGN KEY(pid) REFERENCES fp(id)
);
INSERT INTO fp VALUES(1);
INSERT INTO fc VALUES(1,1,'old');

INSERT IGNORE INTO fc VALUES(1,999,'bad'),(2,1,'ok')
ON DUPLICATE KEY UPDATE pid=VALUES(pid),v=VALUES(v);

SHOW WARNINGS;
SELECT * FROM fc ORDER BY id;

The conflict is on the existing PRIMARY KEY id=1; the UPDATE list modifies only pid and v, not a PRIMARY KEY or UNIQUE KEY. This is therefore distinct from the documented restriction on ODKU assignments to PK/UK columns and from UK-only conflict arbitration.

Actual Behavior

Observable MatrixOne MySQL 8.0.46
Statement result Error 1452 Success
FK diagnostic Error 1452 Warning 1452
Fresh-connection rows (1,1,'old') only (1,1,'old'),(2,1,'ok')

MatrixOne discards the valid (2,1,'ok') sibling INSERT along with the invalid duplicate UPDATE.

Expected Behavior

Under IGNORE, the FK-invalid duplicate UPDATE should be skipped with warning 1452. The existing (1,1,'old') row should remain unchanged, and the valid sibling (2,1,'ok') should be inserted successfully.

Stability and Controls

  • Reproduced in two independent MatrixOne databases and two independent MySQL databases.
  • Readbacks used fresh connections before any positive control could alter the target rows.
  • Pure INSERT IGNORE without ODKU correctly skips the orphan row and inserts the valid sibling on both engines.
  • Fully valid ODKU FK updates and inserts succeed on both engines.
  • A subsequent valid positive-control ODKU statement succeeds on MatrixOne, confirming that the target failure is specific to the invalid action rather than a broken session.
  • Post-probe SELECT 42 succeeds; there is no panic, protocol failure, or availability failure.

Likely Mechanism from Read-only Source Inspection

  • ODKU constructs typed FK assertions over its action stream and final merged image: bind_insert.go, bind_insert.go.
  • The typed fk_no_referenced_row assertion returns NewErrFKNoReferencedRow2 directly. Unlike _check_constraint_assert, it has no statement-IGNORE warning/false-result branch: list_builtIn.go.
  • Filter execution propagates that error, aborting the statement rather than dropping only the offending action: filter.go.

The dynamic result and this source path agree. Regression coverage should check both the skipped invalid UPDATE and preservation of the valid sibling INSERT.

Activity

  1. added
    kind/bug
    on Nov 30, 2026
  2. self-assigned this
    on Nov 30, 2026
  3. added theissue type on Nov 30, 2026
  4. added this to the MO-202611 milestone on Nov 30, 2026
  5. added a commit that references this issue on Nov 30, 2026
    1dfcb9c
  6. XuPeng-SH commented on Nov 30, 2026

    @XuPeng-SH
    Contributor

    转测前验证:#33528 已合入 main@1dfcb9cf2e10ac9676411658f3eb8bc7。确认最终 merge 与实际受测的 b5946447 Git tree 均为 5d96125429ffb9e3e21482d905ed5c19e48af836;多 CN Proxy BVT 日志 确认使用该 revision 的共享 mo-service,实际运行 insert_ignore_constraint_actions.sql 86/86,无跳过。x86 UT 和两项 BVT 已通过;Required 仍因独立的 JED Coverage setup 超时 #33533 为红。未在本轮重跑旧版本,不作生产验收结论。

    原场景回归:FK 无效的重复更新发出 1452,拒绝动作不污染上一版已接受行,合法的同批插入保留;普通非 IGNORE 路径仍严格报错并回滚同批兄弟行。交接建议:QA 复核原 issue 的两个输入行与提交后的新连接读回。

  7. Ariznawlll commented on Dec 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在当前官方 main ba6081a1eaf7210acefd7181da5bfc07db10e8bc 完成原场景验收并关闭。

    • 运行时 git_version() 与精确源码 SHA 一致;binary SHA-256:a856cb87a5b5af72d1b4aa9536a13919e8b46c819adc5f25688d9742f98a0848。
    • 原始 ODKU batch 连续 3 轮通过:语句成功,warning 1452 保留;非法 duplicate UPDATE 被跳过,(1,1,'old') 不变,合法兄弟 (2,1,'ok') 提交;新连接完整行集严格匹配。
    • 纯 INSERT IGNORE、全合法 ODKU、非 IGNORE 严格错误及兄弟无副作用控制均通过;每轮 SELECT 42 和新连接健康检查通过。
    • 三项 Issue 合计原始场景及控制 9/9 PASS,验收开末官方 main SHA 未变化。
    • 独立 MOTR 回归已提交为 matrixorigin/motr#397,head dcb9259f9e7b8d0fe482c784a07fb524a9a0c540,本地 offline 967/967 PASS;未叠加旧 PR374/353。新 PR 的远端检查刚启动,不提前冒称全绿。

    证据:qa-33521-constraints/main-ba608/。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions