Repository navigation
fix: align rowids for nullable index updates - #26347
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
ck89119
left a comment
There was a problem hiding this comment.
Reviewed the complete diff at 285c39c.
The nullable-index UPDATE paths now apply the same compaction bitmap to the index key, primary key, and Rowid vectors. I checked single-column and composite unique indexes, the single-column secondary-index path, the composite secondary-index control path, empty/all-survive/mixed selections, operator buffer reuse, selection-vector ownership, and error cleanup. No actionable correctness or lifecycle issues found.
Local validation passed: focused race stress (100 repetitions per new regression test), full race runs for both owning operator packages, pkg/sql/util tests, build, vet, and diff checks. The latest applicable CI run is green.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 031e2b711e1f98a830032b0c000e48614339bf69; recommendation: APPROVE, with no blocking findings. GitHub prevents this authenticated account from approving because XuPeng-SH is also the PR author. The nullable-row bitmap is now applied consistently to index key, primary key, and Rowid vectors; empty/all-filtered and composite non-unique control paths preserve vector lengths and row identity. Selection-slice pooling is returned on errors, and operator buffer reuse remains safe. Focused update-alignment tests passed under -race -count=20; full preinsertunique, preinsertsecondaryindex, and sql/util packages passed under race.
## What changed - Compact update RowIDs with the same NULL bitmap already used for unique-index keys and primary keys. - Apply the same alignment rule to single-column secondary-index preinsert; keep the composite secondary-index behavior unchanged. - Preserve the existing `UnionBatch` fast path when no indexed value is NULL. - Add white-box coverage for single/composite indexes and mixed/all/zero surviving rows. - Reuse the existing multi-table `update_index` BVT data to reproduce the SQL-visible failure without adding redundant fixtures. ## Root cause During an UPDATE of a nullable unique index, the index key and primary-key vectors discard rows whose indexed value becomes NULL, but the RowID vector was copied without the same compaction. The duplicate-check pipeline could therefore compare a surviving key with the RowID of a different row and reject a legal self-update as a duplicate. ## User impact Fixes false `Duplicate entry` errors for batch updates where one indexed row becomes NULL while other indexed rows retain their existing keys. ## Performance and risk - The common no-NULL path still uses the original bulk `UnionBatch`; the added branch only checks whether the bitmap is empty. - Local 8K-RowID microbenchmark, 5 runs: original bulk path 2.296 µs/op vs guarded no-NULL path 2.300 µs/op, both 0 alloc/op (difference within measurement noise). - A 25%-NULL batch takes about 20.6 µs per 8K rows, 35 B/op and 1 alloc/op; this work is required only when compaction is needed, and the selection buffer is pooled. - No schema, wire, storage, public API, concurrency, or lifecycle changes. - Pooled selections are returned on both success and error paths. ## Validation - `go build` for the modified Go packages - `go vet` for the modified Go packages - deterministic CGo test wrapper over `preinsertunique`, `preinsertsecondaryindex`, and `sql/util` - targeted race tests, 20 repetitions - `make ARCHSIMD=0 build-with-prebuilt-native` - real-server BVT: `update_index.test` passes 148/148 - regression oracle: clean latest `main` fails the reproducer with `Duplicate entry` (143/148 after cascading failures), while this change passes 148/148 Fixes matrixorigin#26334
## What changed - Compact update RowIDs with the same NULL bitmap already used for unique-index keys and primary keys. - Apply the same alignment rule to single-column secondary-index preinsert; keep the composite secondary-index behavior unchanged. - Preserve the existing `UnionBatch` fast path when no indexed value is NULL. - Add white-box coverage for single/composite indexes and mixed/all/zero surviving rows. - Reuse the existing multi-table `update_index` BVT data to reproduce the SQL-visible failure without adding redundant fixtures. ## Root cause During an UPDATE of a nullable unique index, the index key and primary-key vectors discard rows whose indexed value becomes NULL, but the RowID vector was copied without the same compaction. The duplicate-check pipeline could therefore compare a surviving key with the RowID of a different row and reject a legal self-update as a duplicate. ## User impact Fixes false `Duplicate entry` errors for batch updates where one indexed row becomes NULL while other indexed rows retain their existing keys. ## Performance and risk - The common no-NULL path still uses the original bulk `UnionBatch`; the added branch only checks whether the bitmap is empty. - Local 8K-RowID microbenchmark, 5 runs: original bulk path 2.296 µs/op vs guarded no-NULL path 2.300 µs/op, both 0 alloc/op (difference within measurement noise). - A 25%-NULL batch takes about 20.6 µs per 8K rows, 35 B/op and 1 alloc/op; this work is required only when compaction is needed, and the selection buffer is pooled. - No schema, wire, storage, public API, concurrency, or lifecycle changes. - Pooled selections are returned on both success and error paths. ## Validation - `go build` for the modified Go packages - `go vet` for the modified Go packages - deterministic CGo test wrapper over `preinsertunique`, `preinsertsecondaryindex`, and `sql/util` - targeted race tests, 20 repetitions - `make ARCHSIMD=0 build-with-prebuilt-native` - real-server BVT: `update_index.test` passes 148/148 - regression oracle: clean latest `main` fails the reproducer with `Duplicate entry` (143/148 after cascading failures), while this change passes 148/148 Fixes matrixorigin#26334
## What changed - Compact update RowIDs with the same NULL bitmap already used for unique-index keys and primary keys. - Apply the same alignment rule to single-column secondary-index preinsert; keep the composite secondary-index behavior unchanged. - Preserve the existing `UnionBatch` fast path when no indexed value is NULL. - Add white-box coverage for single/composite indexes and mixed/all/zero surviving rows. - Reuse the existing multi-table `update_index` BVT data to reproduce the SQL-visible failure without adding redundant fixtures. ## Root cause During an UPDATE of a nullable unique index, the index key and primary-key vectors discard rows whose indexed value becomes NULL, but the RowID vector was copied without the same compaction. The duplicate-check pipeline could therefore compare a surviving key with the RowID of a different row and reject a legal self-update as a duplicate. ## User impact Fixes false `Duplicate entry` errors for batch updates where one indexed row becomes NULL while other indexed rows retain their existing keys. ## Performance and risk - The common no-NULL path still uses the original bulk `UnionBatch`; the added branch only checks whether the bitmap is empty. - Local 8K-RowID microbenchmark, 5 runs: original bulk path 2.296 µs/op vs guarded no-NULL path 2.300 µs/op, both 0 alloc/op (difference within measurement noise). - A 25%-NULL batch takes about 20.6 µs per 8K rows, 35 B/op and 1 alloc/op; this work is required only when compaction is needed, and the selection buffer is pooled. - No schema, wire, storage, public API, concurrency, or lifecycle changes. - Pooled selections are returned on both success and error paths. ## Validation - `go build` for the modified Go packages - `go vet` for the modified Go packages - deterministic CGo test wrapper over `preinsertunique`, `preinsertsecondaryindex`, and `sql/util` - targeted race tests, 20 repetitions - `make ARCHSIMD=0 build-with-prebuilt-native` - real-server BVT: `update_index.test` passes 148/148 - regression oracle: clean latest `main` fails the reproducer with `Duplicate entry` (143/148 after cascading failures), while this change passes 148/148 Fixes matrixorigin#26334
What changed
UnionBatchfast path when no indexed value is NULL.update_indexBVT data to reproduce the SQL-visible failure without adding redundant fixtures.Root cause
During an UPDATE of a nullable unique index, the index key and primary-key vectors discard rows whose indexed value becomes NULL, but the RowID vector was copied without the same compaction. The duplicate-check pipeline could therefore compare a surviving key with the RowID of a different row and reject a legal self-update as a duplicate.
User impact
Fixes false
Duplicate entryerrors for batch updates where one indexed row becomes NULL while other indexed rows retain their existing keys.Performance and risk
UnionBatch; the added branch only checks whether the bitmap is empty.Validation
go buildfor the modified Go packagesgo vetfor the modified Go packagespreinsertunique,preinsertsecondaryindex, andsql/utilmake ARCHSIMD=0 build-with-prebuilt-nativeupdate_index.testpasses 148/148mainfails the reproducer withDuplicate entry(143/148 after cascading failures), while this change passes 148/148Fixes #26334