Repository navigation
Description
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:
CompactSingleIndexColorSerialWithCompactedreturns the bitmap for
nullable index rows.CompactPrimaryColapplies that bitmap to the primary-key vector.UnionBatchcopies the entire Rowid input and does not apply the bitmap.
Locations:
pkg/sql/colexec/preinsertunique/preinsertunique.gopkg/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
[-][Bug]: nullable single-column index UPDATE keeps Rowid from filtered NULL row[/-][+][Bug]: nullable index UPDATE keeps Rowid from filtered NULL row[/+]fix: align rowids for nullable index updates (#26347)
Ariznawlll commentedon Aug 3, 2026
测试版本
main820ee12144439c5b63c03b261f4330ec0364fdb3原问题验证
围绕 nullable index 的 Rowid 对齐问题,构造单列 UNIQUE、复合 UNIQUE 和普通二级索引三张表;每张表均先写入两行,再在同一条 UPDATE 中将一行索引键更新为
NULL,另一行保留有效索引键。执行后查询索引键为20的记录,均只返回保留键的第二行;没有出现误报重复键或索引结果错行。Happy Path 覆盖
(a,b):一行a变为NULL后,另一行(20,21)仍可正确读取。NULL后,另一行键20保持可读。20查询,仅返回预期的存活行。NULL的行原索引键重新插入新行,复合 UNIQUE 和单列 UNIQUE 均成功,证明不存在残留索引项。Unhappy Path 覆盖
(20,21)和20分别再次插入,均稳定返回ERROR 1062。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),与本用例无关。测试结论
测试通过。
fix: align rowids for nullable index updates (matrixorigin#26347)
fix: align rowids for nullable index updates (matrixorigin#26347)
fix: align rowids for nullable index updates (matrixorigin#26347)