Skip to content

[Bug]: ON DUPLICATE KEY UPDATE skips CHECK validation for discarded incoming rows #33536

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

98b2097

Other Environment Information

  • Isolated MatrixOne single-node runtime, git_version()='98b20975'.
  • Comparator: isolated MySQL 8.0.46 with its default strict sql_mode.
  • Reproduced in independent databases in two rounds on both engines; fresh-connection readbacks matched across rounds.

Actual Behavior

For INSERT ... ON DUPLICATE KEY UPDATE (ODKU), MatrixOne does not validate a CHECK constraint against the raw incoming row when duplicate arbitration chooses the UPDATE branch. If the UPDATE leaves the CHECK column unchanged or restores it to a valid value, MatrixOne executes the update without an error or warning. MySQL validates the incoming row before applying the duplicate-update action.

CREATE TABLE t(
  id INT PRIMARY KEY,
  x INT,
  v INT,
  CONSTRAINT ck CHECK(x>0)
);
INSERT INTO t VALUES(1,1,10);

INSERT INTO t VALUES(1,-1,20)
ON DUPLICATE KEY UPDATE v=VALUES(v);
SELECT * FROM t;
MatrixOne: success, 2 affected rows, no warning; final row (1,1,20)
MySQL:     ERROR 3819; final row (1,1,10)

With INSERT IGNORE, MatrixOne still executes the update without warning and stores (1,1,20); MySQL emits warning 3819, skips the action, and retains (1,1,10).

Explicitly repairing the merged row with ON DUPLICATE KEY UPDATE x=1,v=VALUES(v) does not change the divergence: MySQL still rejects the invalid incoming row.

An ordered same-key discriminator changes final data:

INSERT IGNORE INTO t VALUES(1,-1,1),(1,2,2)
ON DUPLICATE KEY UPDATE v=t.v*10+VALUES(v);
-- MatrixOne: v=1012 (both actions execute)
-- MySQL:     v=102  (invalid first action is skipped)

Expected Behavior

The raw incoming row should undergo CHECK validation before its duplicate UPDATE action is eligible, matching MySQL's ERROR/warning 3819 behavior.

Steps to Reproduce

  1. Run the SQL above on MatrixOne.
  2. Compare statement status, warnings, affected rows, and fresh final rows with MySQL 8.0.46.
  3. A fully valid ordered control (1,2,1),(1,3,2) produces v=1012 on both engines.

Additional information

This is distinct from #33523. In #33523, the final UPDATE row itself is CHECK-invalid and is persisted after warning 3819. Here, the raw incoming row is invalid but the final row is valid; MatrixOne omits incoming validation and its corresponding warning entirely.

The divergence reproduced for VALUES, INSERT SET, INSERT SELECT, plain/IGNORE, unrelated-column updates, explicit repair, no-op updates, multi-column CHECK, AUTO_INCREMENT PK, composite PK/UK, split PK/UK conflicts (both engines select the PK target in the legal control), and SQL PREPARE. In explicit transactions, COMMIT preserves the shown final-row divergence while ROLLBACK restores identical rows on both engines; valid writes before and after the rejected MySQL statement remain committable. The same plain/IGNORE divergence remains with sql_mode=''; valid controls still match, so this is not specific to STRICT_TRANS_TABLES. Incoming FK handling does not share this CHECK-specific divergence.

Read-only source inspection: pkg/sql/plan/bind_insert.go:3393-3453 covers pre-dedup CHECK for IGNORE/load-ignore rather than ODKU's UPDATE node; final-only CHECK eligibility at 3551-3571,4166-4181 excludes the existing duplicate target, so the raw invalid image is never asserted. No product source was modified during testing.

Activity

  1. added
    kind/bug
    on Dec 1, 2026
  2. added theissue type on Dec 1, 2026
  3. added this to the MO-202612 milestone on Dec 1, 2026
  4. LeftHandCold commented on Dec 2, 2026

    @LeftHandCold
    Collaborator

    Confirmed on 4.2-dev. The regression first appears in #33324. Its direct parent 70bb7b3515 returns MySQL error 3819 and preserves the pre-statement rows. The CI binary for c590b9b (same Git tree as merge 47e43f24a5) and release branch 6a905c7e66 accept the discarded invalid input. #31979's direct parent already exhibits the regression.

    A batch shows the application impact:

    CREATE TABLE ck(id INT PRIMARY KEY, x INT, v INT, CONSTRAINT positive CHECK(x>0));
    INSERT INTO ck VALUES (1,1,10);
    INSERT INTO ck VALUES (2,1,30),(1,-1,40)
      ON DUPLICATE KEY UPDATE v=VALUES(v);
    SELECT id,x,v FROM ck ORDER BY id;

    Parent and v4.2.9 reject the invalid candidate. On the #33324 build, the batch succeeds and another CN reads both (1,1,40) and (2,1,30). The inverse control is important: a valid input followed by an UPDATE assigning x=-99 must still fail after the fix. The release-branch patch will retain that final-row check. The separate main-branch coverage in this issue remains applicable.

  5. added
    severity/s0
    and removed on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions