Skip to content

[Bug]: external scan ignores a NULL append failure and can publish a short column #29262

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

66da387

Other Environment Information

  • Hardware parameters:
  • OS type:
  • Others: code inspection of origin/main. No duplicate open issue for external NULL append, materializeOneRow, or object-writer unmatched column length.

Actual Behavior

CSV, JSONLINE, and Kafka external scans build off-heap batches (External.Prepare, pkg/sql/colexec/external/external.go around 252–263, vector.NewOffHeapVecWithType).

Two production paths discard the error from vector.AppendBytes and still return success:

  • materializeOneRow fills a missing trailing field with NULL and ignores the error (external.go 1545), then returns nil.
  • getColData does the same for a NULL or empty field (external.go 1593–1596).

AppendBytes of a NULL goes through appendOneFixedWithSource → extendWithBitmaps → growData → MPool.Grow(..., offHeap=true). For an off-heap block owned by that pool, Grow returns moerr.NewMPoolCapacityNoCtxf when the temporary peak exceeds GlobalCap or mp.Cap (pkg/common/mpool/mpool.go 1559–1568). A failed extend does not publish the row (vector.go appendOneFixedWithSource: length is updated only after extendWithBitmaps returns nil).

getOneRowData only rolls a partial row back when materializeOneRow returns an error (external.go 1434–1442). A swallowed append leaves err == nil, including in error-tolerant mode, so there is no rollback.

CsvReader.makeBatchRows (reader_csv.go 233–242) and KafkaReader.ReadBatch (reader_kafka.go 473–481) then set bat.SetRowCount(bat.Vecs[0].Length()) and return nil. External.Call publishes that batch (external.go 418–425).

Consequences when the failed append is a query-pool capacity error:

  1. If column 0 grew and a later NULL or missing field did not, RowCount() includes the row and the later vector is shorter. insert_table unions each vector by its own Length() but sets the written batch's row count from input.Batch.RowCount() (pkg/sql/colexec/insert/insert.go 556–566). txnTable.Write keeps that row count via CopyBatch (pkg/sql/util/util.go 44–67).
  2. objectWriterV1.addBlock is the only length check in the tree. On a mismatch it Debug logs and continues, then BlockHeader().SetRows uses column 0's length (pkg/objectio/writer.go 801–810 and 867). A later successful flush therefore persists the short column under the longer row count.
  3. If the failed append is column 0, RowCount() stays at the old length while later columns that did append are longer. The row is omitted from the published count, and those extra values ride along in the marshaled column.

Non-NULL conversions in getColData return the append error, so this is specific to NULL, empty, and missing trailing fields. Those are normal CSV and Kafka rows, not a corrupt file.

Expected Behavior

A capacity error from AppendBytes should fail materializeOneRow. The scan should not publish the batch, and INSERT / LOAD DATA should not write it. Error-tolerant mode should see that error and roll the row back, then fail the statement if the replacement row cannot be appended either.

Steps to Reproduce

White-box, on the commit above:

  1. Build an off-heap external batch with two columns the same way External.Prepare does.
  2. Use a query MPool whose cap is large enough for the first row and too small for the next geometric Grow of column 1.
  3. Append one complete non-NULL row so both vectors have length 1 and column 1's buffer is full.
  4. Call getOneRowData with a second CSV record whose column 0 is non-NULL and whose column 1 is NULL (or whose line is shorter than the attribute list).
  5. Observe getOneRowData returns nil, Vecs[0].Length()==2, Vecs[1].Length()==1.
  6. Run that batch through insert_table's union + SetRowCount(input.Batch.RowCount()), then objectWriterV1.addBlock. Observe a nil error, a debug "unmatched length" line, and BlockHeader rows equal to 2 while column 1's vector length is 1.

The same getOneRowData path is used by LOAD DATA, external table scan, and Kafka scan.

Additional information

Not the same bug as #29256 (multi_update tombstone batches) or #29257 (CN sinker objects orphaned when a later error skips registration). This one returns success from the scan and the object writer accepts the mismatched lengths.

Activity

  1. added
    kind/bug
    on Sep 22, 2026
  2. added theissue type on Sep 23, 2026
  3. added this to the MO-202609 milestone on Sep 23, 2026
  4. self-assigned this
    on Sep 23, 2026
  5. added a commit that references this issue on Sep 24, 2026
    ac46f1a
  6. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地源码定向 UT(Go 1.26.5,macOS arm64)
    • 测试日期:2026-09-27

    原问题验证

    该问题依赖内部 reader 生命周期或 I/O 故障注入,公开 SQL 无法稳定制造目标失败点。已在最新 main 上运行对应定向测试 TestExternalNullAppendFailureIsReturned,连续 3 次通过。

    Happy Path 覆盖

    1. external scan 正常 NULL append 路径保持列长度一致。

    Unhappy Path 覆盖

    1. 注入 NULL append 失败后错误向上传播,未发布 short column。

    白盒验证

    确认修复提交 ac46f1a09bfeee21a83cf511625b44d5fb7f1093 是当前 main 的祖先,并直接执行该提交新增的定向测试,结果 3/3 PASS。

    回归测试

    回归已落在 MatrixOne UT:TestExternalNullAppendFailureIsReturned。未加入 MOTR,因为该场景必须注入内部 reader/I/O 失败,SQL 黑盒无法可靠触发;按覆盖矩阵应保留在 UT 层。

    测试证据

    • MatrixOne main commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 修复提交:ac46f1a09bfeee21a83cf511625b44d5fb7f1093
    • 定向 Go 测试:3/3 PASS

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions