Skip to content

[Bug]: Plain ON DUPLICATE KEY UPDATE skips incoming NOT NULL validation without PRE_INSERT #33537

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 a plain INSERT ... ON DUPLICATE KEY UPDATE plan without PRE_INSERT, MatrixOne omits NOT NULL validation of the raw incoming row when duplicate arbitration chooses the UPDATE branch. It executes the update without warning; MySQL raises ERROR 1048 and preserves the old row.

CREATE TABLE t(id INT PRIMARY KEY,x INT NOT NULL,v INT);
INSERT INTO t VALUES(1,1,10);

INSERT INTO t VALUES(1,NULL,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 1048; final row (1,1,10)

Using ON DUPLICATE KEY UPDATE x=1,v=VALUES(v) still succeeds on MatrixOne and fails with 1048 on MySQL. An ordered two-action statement also diverges:

INSERT INTO t VALUES(1,NULL,1),(1,2,2)
ON DUPLICATE KEY UPDATE v=t.v*10+VALUES(v);
-- MatrixOne: v=1012
-- MySQL: ERROR 1048; v remains 10

Expected Behavior

Plain ODKU should validate the raw incoming row's NOT NULL constraints before applying a duplicate UPDATE action, as MySQL does.

Steps to Reproduce

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

Additional information

The divergence reproduced for PK- and UK-selected duplicates, VALUES, INSERT SET, INSERT SELECT, composite 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 plain divergence remains with sql_mode=''; MySQL still raises 1048 for the invalid incoming row, while the IGNORE and valid controls match. It is plan-shape-dependent: AUTO_INCREMENT PK and composite PK controls reject the row on MatrixOne (with diagnostic 3819 rather than 1048), preserving the old data. Type conversion, VARCHAR length, DECIMAL range, and DATE validation still run, so this is not a blanket absence of incoming validation.

This is distinct from #33527, which concerns NULL produced by the UPDATE action expression and IGNORE's action filtering versus MySQL's implicit-default write. Here the raw incoming row is NULL in an unrelated NOT NULL column and plain ODKU omits its pre-arbitration validation.

Read-only source inspection: pkg/sql/plan/bind_insert.go:6311-6353,6389-6410 only plans PRE_INSERT for IGNORE filling or other key-shape needs in this path. ODKU NOT NULL assertions at 513-588,3514-3515,4213-4214,4278-4279 cover updated columns only. The DEDUP join then merges the old row with the update expression, so the final write check sees x=1, not raw x=NULL. 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. modified the milestones: MO-202611, MO-202612 on Dec 1, 2026
  4. added a commit that references this issue on Dec 2, 2026
    f0c32a6
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