Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
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
- Run the SQL above on MatrixOne.
- Compare statement status, warnings, affected rows, and fresh final rows with MySQL 8.0.46.
- A fully valid ordered control
(1,2,1),(1,3,2)producesv=1012on 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
LeftHandCold commentedon Dec 2, 2026
Confirmed on
4.2-dev. The regression first appears in #33324. Its direct parent70bb7b3515returns MySQL error 3819 and preserves the pre-statement rows. The CI binary forc590b9b(same Git tree as merge47e43f24a5) and release branch6a905c7e66accept the discarded invalid input. #31979's direct parent already exhibits the regression.A batch shows the application impact:
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 assigningx=-99must 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.[4.2-dev] Reject invalid incoming CHECK values before duplicate-key u…
fix(sql): validate offered rows before ODKU arbitration (#33687)
test(sql): align ODKU CHECK cases with input validation (#33691)