Skip to content

[Bug]: INSERT IGNORE ODKU skips NULL assignments to NOT NULL columns instead of storing adjusted defaults #33527

Todo

Description

@Ariznawlll

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, commit 98b20975b74cb3915d671cbbdeb1f652ed28c220
  • 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 value 5 on both engines; only the warning code differs.
  • An all-valid chain using v=v+VALUES(v) produces 14 on both engines with no constraint warning.

Additional coverage

The same old-value versus adjusted-default divergence reproduced for:

  • DECIMAL(10,2): 10.50 versus 0.00
  • VARCHAR(10): 'old' versus ''
  • BINARY(4): b'old\x00' versus four zero bytes
  • Expressions v=v+NULL and v=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)=NULL stores 0 with warning 1048 on both engines.
  • Assigning NULL to a nullable column stores NULL on both engines without a warning.
  • v=DEFAULT uses 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-543 selects potentially-NULL ODKU update expressions for action-level NOT NULL validation.
  • pkg/sql/plan/bind_insert.go:546-588 builds isnotnull(action_value) and wraps it with _check_constraint_assert as 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

Activity

  1. added
    kind/bug
    on Nov 30, 2026
  2. added theissue type on Nov 30, 2026
  3. added this to the MO-202611 milestone on Nov 30, 2026
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