Skip to content

fix: align rowids for nullable index updates - #26347

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/26334-nullable-index-rowid
Jul 29, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/26334-nullable-index-rowid

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

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 #26334

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@ck89119 ck89119 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@XuPeng-SH
XuPeng-SH merged commit 2e3808e into main Jul 29, 2026
5 of 8 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/26334-nullable-index-rowid branch July 29, 2026 04:52
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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

This branch was previously deployed

1 inactive deployment
ci — 83ce92f2 Deployed Jul 29, 2026 by XuPeng-SH via Matrixone Utils CI / Coverage #43219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants