Skip to content

[Bug]: nullable index UPDATE keeps Rowid from filtered NULL row #26334

Closed

Description

@Ariznawlll

Description

For an UPDATE input batch with a nullable index key, preinsertunique and the
single-column path of preinsertsecondaryindex compact the index key and
primary-key vectors but copy the complete Rowid vector.

This affects:

  • nullable single-column unique indexes;
  • nullable composite unique indexes;
  • nullable single-column secondary indexes.

The composite non-unique secondary-index path is a control case: it retains
NULL-containing rows and keeps all vectors aligned.

The affected paths produce vectors with different lengths and associate the
surviving index entry with the Rowid of the filtered NULL row.

Environment

  • Branch: main
  • Commit: cad24c348791e5f05e517e0a49111d965ddb48c5

Minimal case

Use a two-row UPDATE batch:

row primary key first index column second index column Rowid
1 10 NULL 100 rowid-1
2 20 200 201 rowid-2

For the single-column case, only the first index column is configured. For the
composite case, both index columns are configured.

Expected result

For a unique index, the NULL-containing row is filtered and every output
vector remains aligned:

  • index key: one serialized entry for (200, 201)
  • primary key: [20]
  • Rowid: [rowid-2]
  • all vector lengths: 1

Actual result

The output batch reports one row, but its vectors are:

  • index key: one serialized entry (length 1)
  • primary key: [20] (length 1)
  • Rowid: [rowid-1, rowid-2] (length 2)

The first visible Rowid is therefore rowid-1, which belongs to the filtered
NULL row rather than the surviving index entry.

The single-column tests reproduced the result 3/3 times in both affected
packages. The composite unique-index test also reproduced it 3/3 times:

go test ./pkg/sql/colexec/preinsertunique \
  -run TestAuditCompositeNullableUpdateKeepsAlignedRowID \
  -count=3 -v

expected Rowid vector length: 1
actual Rowid vector length:   2

The composite non-unique secondary-index control passed 3/3 and retained two
aligned rows:

go test ./pkg/sql/colexec/preinsertsecondaryindex \
  -run TestAuditCompositeNullableUpdateKeepsAllRowsAligned \
  -count=3 -v

Code path

The affected operators follow the same pattern:

  • CompactSingleIndexCol or SerialWithCompacted returns the bitmap for
    nullable index rows.
  • CompactPrimaryCol applies that bitmap to the primary-key vector.
  • UnionBatch copies the entire Rowid input and does not apply the bitmap.

Locations:

  • pkg/sql/colexec/preinsertunique/preinsertunique.go
  • pkg/sql/colexec/preinsertsecondaryindex/preinsertsecondaryindex.go

Impact

Nullable index maintenance during UPDATE can construct an internally
inconsistent batch and pair a surviving index key/primary key with the Rowid
of a different row. Downstream index maintenance can therefore act on the
wrong row.

Activity

  1. added this to the MO-202607 milestone on Jul 28, 2026
  2. added
    kind/bug
    on Jul 28, 2026
  3. added theissue type on Jul 28, 2026
  4. changed the title [-][Bug]: nullable single-column index UPDATE keeps Rowid from filtered NULL row[/-] [+][Bug]: nullable index UPDATE keeps Rowid from filtered NULL row[/+] on Jul 28, 2026
  5. self-assigned this
    on Jul 28, 2026
  6. added
    severity/s0
    and removed on Jul 28, 2026
  7. added a commit that references this issue on Jul 29, 2026
    2e3808e
  8. Ariznawlll commented on Aug 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:820ee12144439c5b63c03b261f4330ec0364fdb3
    • 部署方式:本地 current-main MatrixOne 集群,使用 SQL 黑盒方式验证
    • 测试日期:2026-08-03

    原问题验证

    围绕 nullable index 的 Rowid 对齐问题,构造单列 UNIQUE、复合 UNIQUE 和普通二级索引三张表;每张表均先写入两行,再在同一条 UPDATE 中将一行索引键更新为 NULL,另一行保留有效索引键。执行后查询索引键为 20 的记录,均只返回保留键的第二行;没有出现误报重复键或索引结果错行。

    Happy Path 覆盖

    1. 复合 UNIQUE (a,b):一行 a 变为 NULL 后,另一行 (20,21) 仍可正确读取。
    2. 单列 UNIQUE:一行变为 NULL 后,另一行键 20 保持可读。
    3. 普通二级索引:更新后按索引键 20 查询,仅返回预期的存活行。
    4. 将已变为 NULL 的行原索引键重新插入新行,复合 UNIQUE 和单列 UNIQUE 均成功,证明不存在残留索引项。

    Unhappy Path 覆盖

    1. 对仍被存活行占用的 (20,21) 和 20 分别再次插入,均稳定返回 ERROR 1062。
    2. 两次重复键失败后,再查询存活键计数均为 1,确认失败操作未破坏已更新数据或索引状态。

    白盒验证

    不适用。本问题的可观察症状是 SQL UPDATE 后索引键与行记录不一致;本次以公开 SQL 语义构造黑盒回归,覆盖多表 UPDATE、唯一索引、普通二级索引及失败原子性。

    回归测试

    已加入 motr 的 14_issue_regression:

    测试证据

    执行 ./motr --config <local-config> --branch main --repeat 3 14_issue_regression.issue_26334_nullable_index_update,3 轮均为 23/23 成功,共 69/69。随后运行完整 14_issue_regression,新增用例为 23/23 成功;整套唯一失败为已有的 issue_24824_update_correlated_subquery(当前 main 返回 ERROR 1093),与本用例无关。

    测试结论

    测试通过。

  9. added 3 commits that reference this issue on Sep 17, 2026
    4ead5c9
    c61f2c0
    8b5000c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions