Skip to content

fix(bitmap): address review comments of #33144 - #33231

Merged
fengttt merged 3 commits into
matrixorigin:mainfrom
fengttt:fix-33144-review
Nov 25, 2026
Merged

fengttt merged 3 commits into
matrixorigin:mainfrom
fengttt:fix-33144-review

Conversation

@fengttt

@fengttt fengttt commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #33030

What this PR does / why we need it:

This PR follows up on #33144 (bitmaps own their words through an mpool). That PR merged while review comments were still open: the CHANGES_REQUESTED reviews from iamlinjunhong and the mo-bot review, plus the Codex automated review. This PR addresses those comments. Each finding was checked against the merged code on main, and every confirmed one is fixed here.

Review findings addressed

Finding in #33144 Fix
Persisted dedup swallows probe errors (tae/tables/base.go, txnimpl/table.go). BatchDedup errors other than OkExpectedPossibleDup (bloom filter load, candidate bitmap allocation) were treated as "no key in this block". GetByFilter could then report an existing key absent, and DedupSnapByPK could miss a duplicate. Propagate the error in persistedGetDuplicatedRows, persistedContains and the workspace tombstone probe.
Composed views read past the source's end (bitmap_view.go). A view of a read-only bitmap extending past that bitmap's Len read its shared words beyond Len. Contains then disagreed with Count, and Marshal produced an encoding that Validate rejects. When the source is read-only, stop the view at the source's end. Owned sources keep clear tails, so their padded views are unchanged.
Reserved validity storage freed by Reset (json_numeric_comparison.go, also the empty-union resets). Reset() returned the result's reserved null storage, so later in-place Adds allocated and could panic at the pool cap. Clear() in the JSON/numeric comparison and the three <=> kernels in func_compare.go. nulls.Or of two empty inputs now clears the result in place and keeps its length and storage. The nulls Gobra proof was re-run: 0 errors.
Aggregate flush panics at pool cap (aggexec/result.go). Setting empty groups to NULL grew the bitmap in place. Reserve the null storage first with PreExtendNulls. flushAll now returns the error to Flush.
Vector.Allocated omits owned bitmap capacity (vector.go). CleanOnlyData keeps the pool-charged bitmap, but size-limited buffers did not see it. Count an owned null bitmap's capacity. A read-only bitmap still counts as zero.
CXCall hands a shifted window bitmap to Ptr, which panics (FillRawPtrLen, cxcall.go). For a read-only null bitmap, hand C a clean, unshifted copy, kept alive until the native call returns.
OwnReadOnlyVectors frees an original still referenced by a later alias (batch.go). Copy every read-only vector first. Only then replace all columns and free the originals. On a failed copy the batch is left unchanged and the copies made so far are freed.
Loaded block vectors leak when the destination delete bitmap cannot be allocated (tae/tables/pnode.go). Close the loaded vectors and call release on that exit. The merged delete bitmap is also reserved for every row the merge can set, so its Adds cannot fail.
Row-ID vector leaks when the visibility bitmap cannot be allocated (tae/tables/utils.go). Close the already-populated output vectors on that exit as well.

Also removed a duplicated doc comment on Bitmap.WordsCovering.

Not changed here

The P2 finding that Bitmap allocates its own words, contrary to the original text of #33030, is a design question, not a code defect. The follow-up comment on #33030 ("Give nulls a mpool") is what #33144 implements. That decision should be recorded on the issue.

Tests

New regression tests:

  • TestBitmapViewOfViewStopsAtSourceEnd (fails on main)
  • TestOrOfEmptyKeepsReservedStorage (fails on main)
  • TestFlushAllEmptyGroupNullsAtPoolCap
  • TestAllocatedCountsOwnedNulls
  • TestFillRawPtrLenShiftedWindowNulls (Ptr panics on main)
  • TestOwnReadOnlyVectorsLeavesBatchOnDupError, which replaces the old test and now places an aliased column around the column whose copy fails

The dedup error propagation and the two TAE scan cleanup paths have no fault-injection tests. Each would need a persisted TAE object whose probe or scan allocation fails.

Local runs, all passing: go test -tags matrixone_test over common/bitmap, container/{nulls,vector,batch}, sql/colexec/{aggexec,group,hashbuild,mergeorder,partition,projection,filter}, sql/colexec, sql/plan/function, vm/process, vm/engine/disttae, vm/engine/tae/{tables,containers,txn/txnimpl}. make static-check passes on the touched packages.

🤖 Generated with Claude Code

Reviews of matrixorigin#33144 (bitmaps own their words through an mpool) landed after
merge. Fixes for the confirmed findings:

- tae dedup: BatchDedup errors other than OkExpectedPossibleDup (bloom
  filter load, candidate bitmap allocation) were treated as "no key in
  block", so persistedGetDuplicatedRows, persistedContains and the
  workspace tombstone probe could miss an existing key. Propagate them.
- bitmap views: a view of a read-only bitmap past that bitmap's end read
  its shared words beyond Len, so Contains disagreed with Count and Marshal
  produced an invalid encoding. Stop such a view at the source's end.
- nulls: Or of two empty inputs, and the "<=> is never NULL" / JSON-numeric
  comparison kernels, reset the result's bitmap and so returned the
  validity storage the result had reserved; later in-place Adds then
  allocated and could panic at the pool cap. Clear in place instead
  (nulls Gobra proof re-run: 0 errors).
- aggexec: setting empty groups to NULL grew the bitmap in place and could
  panic; reserve it first and return the error from flushAll.
- vector: Allocated omitted owned null-bitmap capacity that CleanOnlyData
  keeps, so size-limited buffers under-counted retained pool memory.
- vector/cxcall: FillRawPtrLen called Ptr on a shifted window bitmap,
  which panics; hand native code a clean copy kept alive across the call.
- batch: OwnReadOnlyVectors freed an original still referenced by a later
  alias column when a copy failed; copy all first, then swap and free.
- tae scan: free loaded vectors, the row-ID vector and the I/O release on
  delete-bitmap allocation failure; reserve the merged delete bitmap so
  its Adds cannot fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 →

@mergify

mergify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 36529b1cf7e30144c3c611da38a6ee112b125e0f

"interrupted"

@fengttt
fengttt merged commit c7393cd into matrixorigin:main Nov 25, 2026
XuPeng-SH added a commit that referenced this pull request Nov 25, 2026
#33240)

## What type of PR is this?

- [x] BUG
- [x] Improvement
- [x] Test and CI

## Which issue(s) this PR fixes:

Related to #33030. Follow-up to #33144 and #33231.

## What this PR does / why we need it:

After bitmap allocations moved into mpool, converting frontend results
with NULLs could exhaust the pool while copying the temporary bitmap.
That copy panicked and bypassed cleanup of the partial batch. Set NULLs
on the destination vector and return allocation errors through the
existing batch cleanup. Extend the bitmap only through the word
containing the NULL row so rows in the same word can be marked without
another growth call. The physical word requirement is unchanged from
growing to the row itself. Columns without NULLs allocate no bitmap, and
an early isolated NULL does not reserve bitmap storage for the whole
column.

Workspace tombstone lookup returned probe errors from its lower layer,
but the caller ignored them and could classify a deleted primary key as
a live duplicate. Return the original error before dedup continues.
Propagate allocation failures while marking or publishing a deleted
candidate and release persisted block data and selection storage on
failure. Preserve partial filtering for the existing write-write
conflict path when candidate copyback succeeds.

Regression coverage includes pool limits and cleanup, word boundaries,
NULL versus empty values, a persisted workspace tombstone, cancellation
and missing objects, and the error returned when copying a delete back
during a write-write conflict.

Pinned local frontend microbenchmarks against the PR base (4096 rows,
six samples per revision, median):

| NULL distribution | INT64 time delta | VARCHAR time delta |
| --- | ---: | ---: |
| None | -0.4% | -3.4% |
| 1 in 97 | +3.7% | -1.8% |
| Half | -4.2% | -1.0% |
| All | -9.4% | -8.0% |

These are result conversion microbenchmarks. They do not measure
end-to-end query latency.

Validation:
- Frontend conversion regressions and the full frontend package passed
with `-race -tags matrixone_test`.
- TAE workspace tombstone/dedup regressions and full `txnimpl` race
passed. The optimization only touched frontend files.
- Incremental gofmt, go vet, molint, and golangci-lint passed for
frontend and txnimpl.
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 28, 2026
The branch was stacked on bitmap-mpool-ownership (matrixorigin#33144), which has
since been squash-merged into main with its review fixes (matrixorigin#33231). This
merge takes main for everything that branch carried, and keeps only this
PR's own changes on top: the row-selection primitives, UnionByMask, their
Gobra contracts, and the RemapList package decision in the design doc.

Adapted to main: Batch.UnionByMask rejects a selected batch (matrixorigin#33184), and
tests use NewWithSize (batch.New removed in matrixorigin#33199).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

No deployments
ci — 6d37bd41 Deployed Nov 25, 2026 by fengttt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants