Repository navigation
Description
Problem
For INSERT IGNORE ... ON DUPLICATE KEY UPDATE, an update expression that produces NULL for a NOT NULL column follows different adjusted-value semantics from MySQL.
MatrixOne emits warning 3819 and filters the update action, preserving the old value. MySQL 8.0.46 emits warning 1048, adjusts NULL to the type's implicit default, and applies the update. With multiple ordered actions for the same key, this also changes subsequent calculations and the final stored non-NULL value.
This is separate from ordinary INSERT IGNORE incoming-row handling and from direct UPDATE IGNORE: the divergence is in the ODKU update-action expression.
Environment
- MatrixOne: official
main, commit98b20975b74cb3915d671cbbdeb1f652ed28c220 - Runtime check:
git_version() = '98b20975' - MySQL control: 8.0.46
- Both sides used their default SQL mode containing
STRICT_TRANS_TABLES - Each case was run twice on each engine in independent databases, with deterministic results and fresh-connection readback
Minimal reproduction
CREATE TABLE t(id INT PRIMARY KEY, v INT NOT NULL);
INSERT INTO t VALUES(1,10);
INSERT IGNORE INTO t VALUES(1,11),(2,20)
ON DUPLICATE KEY UPDATE v=NULL;
SHOW WARNINGS;
SELECT * FROM t ORDER BY id;MatrixOne:
Query OK, 1 row affected, 1 warning
Warning 3819 Column 'v' cannot be null
id v
1 10
2 20
MySQL 8.0.46:
Query OK, 3 rows affected, 1 warning
Warning 1048 Column 'v' cannot be null
id v
1 0
2 20
The valid sibling insert succeeds on both sides. The divergent duplicate-key action is not merely an affected-rows or diagnostic difference: MatrixOne stores 10, while MySQL stores the adjusted value 0.
Ordered-action discriminator
CREATE TABLE t(id INT PRIMARY KEY, v INT NOT NULL);
INSERT INTO t VALUES(1,10);
INSERT IGNORE INTO t VALUES(1,-1),(1,5)
ON DUPLICATE KEY UPDATE
v=CASE WHEN VALUES(v)<0 THEN NULL ELSE v+VALUES(v) END;
SHOW WARNINGS;
SELECT * FROM t;MatrixOne:
Query OK, 0 rows affected, 2 warnings
Warning 3819 Column 'v' cannot be null
Warning 3819 Column 'v' cannot be null
id v
1 10
MySQL 8.0.46:
Query OK, 4 rows affected, 1 warning
Warning 1048 Column 'v' cannot be null
id v
1 5
MySQL adjusts the first action to 0, then computes 0+5. In MatrixOne, after the first action produces NULL, the later v+5 action also evaluates to NULL and is filtered, leaving the original value 10.
Two controls isolate this from generic CASE or ordered-action handling:
- Replacing the second branch with independent
VALUES(v)produces final value5on both engines; only the warning code differs. - An all-valid chain using
v=v+VALUES(v)produces14on both engines with no constraint warning.
Additional coverage
The same old-value versus adjusted-default divergence reproduced for:
DECIMAL(10,2):10.50versus0.00VARCHAR(10):'old'versus''BINARY(4):b'old\x00'versus four zero bytes- Expressions
v=v+NULLandv=COALESCE(NULL,NULL) INSERT IGNORE ... SELECT ... ON DUPLICATE KEY UPDATE v=NULL- A composite primary key with the ordered NULL-then-restore chain
Positive controls:
- Incoming
VALUES(v)=NULLstores0with warning 1048 on both engines. - Assigning NULL to a nullable column stores NULL on both engines without a warning.
v=DEFAULTuses the declared default on both engines without a warning.- Non-IGNORE ODKU rejects the statement and preserves the old rows on both engines, although MatrixOne uses 3819 and MySQL uses 1048.
White-box pointers
At the tested commit:
pkg/sql/plan/bind_insert.go:513-543selects potentially-NULL ODKU update expressions for action-level NOT NULL validation.pkg/sql/plan/bind_insert.go:546-588buildsisnotnull(action_value)and wraps it with_check_constraint_assertas a barrier filter.
Consequently, IGNORE uses the CHECK-style warning/filter path: warning 3819 plus action removal. It does not use the ordinary incoming-row implicit-default adjustment path. This also explains why incoming VALUES(v)=NULL works while a constant or computed NULL update expression diverges.
Expected behavior
For MySQL-compatible IGNORE semantics, a NULL produced by an ODKU assignment to a fillable NOT NULL column should be adjusted to the same implicit default as the corresponding incoming-row path, emit warning 1048, and allow subsequent ordered actions to observe that adjusted value.
If a different ODKU adjustment policy is intentional, it needs an explicit compatibility decision; the current behavior is observably different in stored results, not only diagnostics.
Related issues / deduplication
- [Bug]: INSERT IGNORE does not ignore NOT NULL violations (statement aborts with 3819 instead of warning 1048) #30906 covers ordinary
INSERT IGNOREincoming NOT NULL rows. Its incoming-row adjustment works in the positive control above; its discussion leaves ODKU and UPDATE as separate scope. - [Bug]: UPDATE IGNORE invalid conversions error instead of updating adjusted values #25365 concerns direct
UPDATE IGNOREadjusted values, not ODKU update actions. - [Bug]: DML assignment casts must honor bounds and SQL-mode adjustment semantics #27340 is broader DML assignment-conversion tracking, but does not contain this ODKU NOT NULL reproduction or the ordered-action acceptance case.
- Exact open+closed searches for
"ON DUPLICATE KEY UPDATE" "NOT NULL"andODKU 3819returned no existing issue at filing time.
Activity