Skip to content

[Bug]: INSERT IGNORE does not ignore NOT NULL violations (statement aborts with 3819 instead of warning 1048) #30906

Closed

Description

@XuPeng-SH

Description

INSERT IGNORE suppresses some error classes but not NOT NULL violations. A single NULL in a NOT NULL column aborts the whole statement with a hard error, so a multi-row batch that MySQL would load partially (skipping the bad rows with warnings) inserts nothing here.

MySQL documents ER_BAD_NULL_ERROR (1048) among the errors that IGNORE downgrades to a warning:

mysql> insert ignore into ig(u,nn,c) values(2,null,1);
Query OK, 0 rows affected, 1 warning
Warning (Code 1048): Column 'nn' cannot be null

MatrixOne:

mysql> insert ignore into ig(u,nn,c) values(2,null,1);
ERROR 3819 (HY000): constraint violation: Column 'nn' cannot be null

Multi-row, one bad row kills the batch:

insert ignore into ig(u,nn,c) values(10,10,1),(11,null,1),(12,12,1);
-- ERROR 3819 (HY000): constraint violation: Column 'nn' cannot be null

MySQL: rows 10 and 12 are inserted, row 11 is skipped with a warning.

What does work (so this is a gap, not a missing feature)

Measured on the same build, same table:

INSERT IGNORE case MO result MySQL
duplicate unique key warning 1062, row skipped ✅ same
FK violation (1452) row skipped, no error ✅ same
CHECK (c>0) violation row skipped ✅ warning + skip
'12abc' into int coerced to 12, row inserted ✅ warning + insert
NULL into NOT NULL ERROR 3819, statement aborts ❌ warning 1048, row skipped
out-of-range tinyint (300) ERROR 1690 ❌ warning + clamp

So the ignore machinery is wired up (duplicate/FK/coercion paths honour it) — the NOT NULL check simply bypasses it.

White-box pointers

  • pkg/sql/colexec/constraint_util.go:108 — BatchDataNotNullCheck(vecs, attrs, tableDef, ctx) returns moerr.NewConstraintViolation(... "Column '%s' cannot be null") unconditionally; it takes no duplicate-handling / IGNORE mode.
  • pkg/sql/colexec/insert/insert.go:235 — checkExternalNotNull has the same shape for external tables.
  • The error is reported as 3819 (check-constraint violation) rather than 1048 (ER_BAD_NULL_ERROR), so even the error class hides the fact that this is a NOT NULL, not a CHECK, failure.

Impact

Bulk-load scripts and sync jobs commonly use INSERT IGNORE precisely to tolerate a few bad rows. Here one NULL turns a partially-successful batch into a total failure, and the operation must be re-run row by row.

Expected behaviour

Under IGNORE, a NULL in a NOT NULL column should skip the row and publish warning 1048 (ER_BAD_NULL_ERROR); the statement should succeed and report the skipped count, matching the duplicate/FK behaviour that already works.

Versions

MatrixOne main @ 3ad9adbb4c (2026-10-22), macOS arm64, local mo-service -launch.

Related

Activity

  1. added
    kind/bug
    on Oct 23, 2026
  2. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    Collaborator

    Confirming, plus one detail that raises the severity: a single bad row aborts the entire multi-row batch, so INSERT IGNORE cannot be used as a bulk-load dirty-data filter at all.

    CREATE TABLE ig2 (a INT NOT NULL);
    INSERT IGNORE INTO ig2 VALUES (1),(NULL),(2);
    • MO: ERROR 3819 (HY000): constraint violation: Column 'a' cannot be null — 0 rows inserted
    • MySQL 8.0.45: statement succeeds, SELECT COUNT(*), GROUP_CONCAT(a) FROM ig2 → 3, 1,0,2 (the NULL row is coerced to 0 under non-strict, or skipped under strict — either way the other two rows are kept)

    Because the whole statement rolls back, the common ETL pattern "INSERT IGNORE a 10k-row staging batch, let bad rows drop on the floor" fails completely: one malformed row and you lose the other 9,999 good rows. On MySQL the same statement loads the good rows.

    This is a distinct consequence from the error-code mismatch (3819 vs warning 1048): it's not just the wrong code, it's all-or-nothing batch semantics instead of per-row skip.

    Also note the same pattern applies to other IGNORE-covered violations (type truncation, out-of-range) per the related issues — the batch-level abort makes them all unusable for bulk loads.

  3. added
    severity/s0
    ai-easy
    and removed on Oct 28, 2026
  4. gouhongshen commented on Nov 6, 2026

    @gouhongshen
    Contributor

    PR #32299 is trying to fix this issue.

  5. added a commit that references this issue on Nov 6, 2026
  6. gouhongshen commented on Nov 6, 2026

    @gouhongshen
    Contributor

    PR #32299 has merged and is awaiting manual validation. The issue remains open.

  7. XuPeng-SH commented on Nov 6, 2026

    @XuPeng-SH
    ContributorAuthor

    转 QA 验证:#32299 已合入 main

    • 合并 SHA:647eaf9dd36d4b8521114e5dedb9d99d4c148c68;最终 PR head:53237d88e55ab7d9e01d8c8a673210c7c6a84200;合并时间:2026-11-06 21:53 UTC。
    • 修复 INSERT IGNORE 对可填充类型的 NOT NULL 违规:在约束消费者/写入之前,把违规 NULL 调整为类型隐式默认值,每个调整单元发布 1048,保留批次中的有效行。CHECK、unique、FK、锁键及索引维护使用调整后的值,覆盖 VALUES、INSERT SELECT、LOAD 和 external 写入。
    • 原 issue 对普通 NOT NULL NULL 行使用了“跳过”描述;本修复的主要语义是填默认值,不是一律丢弃。旧 QA 评论中的 MySQL 示例 1,NULL,2→1,0,2 也应一起对照,不能仅凭“语句不报错”验收。
    • 当前完整 3 条 issue 评论已读,最新作者记录为 merged_pending_validation。此前唯一保留研发原因是 PR 未合并,现已解除。BINARY 填充、constant-NULL 物化、external replacement 释放和 aliased nullable sibling 破坏的旧 review finding 均有后续修复及批准,不继续把旧反例当作最终修订反例。这是产品语义缺陷,按普通 QA 转测,保持 open,不适用 CI flaky 关闭规则。

    证据及未测范围:

    • 作者报告 pre-fix→fixed 对照、相关 executor/planner 正常及 focused race、gofmt/vet/lint、原 issue BVT 386/386(两种 run 模式)及后续 BINARY/LOAD/外部生命周期回归通过。后续外部所有权与 alias 修订沿用未变 planner/BVT 输入的早期证据,不能把所有项目都写成最终 head 重新执行。
    • 最近明确批准针对 20b8f90,复用该 head 的 build/UT/SCA/coverage/PROXY/PESSIMISTIC BVT 摘要;复审没有新跑 Go/native 或 SQL,原始运行日志未提供。最终 head 已不同,Mergify 合并记录另显示 CI Required 成功。
    • 本轮仅核对远端状态、完整 issue/PR 讨论及返回补丁;补丁增删行数与元数据一致,但缺文件路径清单,不能宣称独立完整审计 29 个文件。没有本地实测,不宣称验收通过或完全 MySQL 兼容。

    保留边界:

    建议 QA:

    1. 原单行及多行批次同时核对 affected rows、1048 警告数量/内容与存储值,覆盖 VALUES、INSERT SELECT、LOAD 和 strict 对照。
    2. 验证填值后 CHECK/FK/unique 及后续严格 INSERT 的一致性,特别是 NOT NULL DEFAULT(abs(NULL)) 的 UNIQUE:首行保留,重复行 1062,索引可见且后续同值严格 INSERT 仍拒绝。
    3. 覆盖 BINARY(n) 的 HEX/LENGTH 与普通空字符串赋值对照、低精度浮点零值、constant-NULL broadcast、依赖/生成默认值,以及 NULL 主键及无默认类型边界。
    4. external LOAD 通过真实 Projection→writer 多批次检查 nullable 源列仍保持 NULL、每个目标独立填充/告警;成功、写失败和部分填充失败均归还借用 slot、释放 replacement/detach 内存。

    按流程移除研发负责人,改派唯一 Ariznawlll。

  8. slyunnn commented on Nov 11, 2026

    @slyunnn

    Regression and extended verification for #30906 (2026-11-11)

    Verification Environment

    • Frozen latest main at test start, 45917e803f2915f6f0838b2b2fe9f591fc5b6018, fix(plan): fold contradictory same-column predicates to near-zero estimates (#32502).
    • Fresh CPU binary with matching verified native-library inputs. Runtime git_version()=45917e803f through Proxy 6001, CN1 16001 and CN2 16002. All three endpoints executed the issue checks.
    • Co-hosted 2 CN / 1 TN / 1 Log service / Proxy, macOS arm64, Go 1.27.1.
    • PyMySQL text protocol and JDBC BVT. Actual Go database/sql + go-sql-driver/mysql, interpolateParams=false, supplied native prepared-statement evidence for MIN/MAX parameter changes and physical-index role changes.

    What Was Covered

    • OK — Existing 399/399 SQL statements passed per endpoint. Original single/multi-row batches retain valid rows, fill offending NULL cells with implicit type defaults and report 1048.
    • OK — The BVT covers stored values/warnings, type defaults, nullable siblings, BINARY padding, strict controls, INSERT SELECT/LOAD, unique/CHECK/FK interactions, default expressions and primary-key boundaries.
    • OK — Real writable file-stage external LOAD ... IGNORE imported 17,000 rows per endpoint. All rows were compared against an independent expected list. Exactly 4 adjusted cells produced 4 warnings 1048, and their nullable siblings remained NULL.
    • OK — Targeted external writer tests cover replacement ownership, alias detachment, write-failure cleanup and partial-fill failure. These failure-injection checks are component evidence.
    • Not covered — External INSERT IGNORE is rejected before assignment even for entirely valid data. Ordinary external INSERT and external LOAD IGNORE work. This separate general admission defect is tracked as [Bug]: writable external tables reject valid INSERT IGNORE VALUES and SELECT with 20313 #32512.
    • Not covered — Live external write-failure injection, GPU execution, and the separate range-clamping/ODKU issues.

    Findings

    • Associated fix fix: make INSERT IGNORE tolerate NOT NULL violations, merge 647eaf9dd36d4b8521114e5dedb9d99d4c148c68 is included in the frozen main. PR #32299
    • Expected ordinary NOT NULL behavior under IGNORE is implicit-default filling. The independent external INSERT IGNORE admission defect also rejects non-NULL VALUES and SELECT, so its error precedes the repaired assignment boundary. Related to #32512

    MOTR / BVT Coverage

    • Reused the maintained product BVT described above. Existing coverage is sufficient, so no duplicate MOTR case was added.
    • Combined weekly branch passed 9 cases with -j 5 --repeat 2 through each endpoint, 54/54 executions total. The new cases use separate databases, roles and connections, with no global-variable changes. This is runner concurrency.
    • Targeted product tests recorded 199 test/subtest passes across 7 packages with selected tests. The independent forced-two-CN aggregate fixture also passed.

    Final Conclusion

    Fixed for the original issue contract on the verified build and paths.

    Large-data regression — A batch boundary check is required. The 17,000-row external load crosses reader batches and checks all stored rows; larger arbitrary data is unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions