Repository navigation
perf(table_scan,filter): keep the row selection a bitmap through scan and filter (#33181 PR 3) - #33236
Merged
Conversation
A bitmap now carries the pool that owns its words. Words are allocated off-heap from that pool and returned by Free; Reset frees them too and keeps the pool. A bitmap without a pool is read-only: every write panics and growth returns an error. Creating functions (InitWithSize, InitWith, Clone, Filter, InitWithRows, InitWithInvertedBits) take the pool and return errors. InitView makes a zero-copy, read-only view of a bitmap's rows with a bit shift. Readers of read-only bitmaps mask at Len, so a view sharing a word with later rows never exposes them; Marshal and the C word accessors write clean, unshifted words. Vectors: the null bitmap uses the vector's pool and Vector.Free releases it. Window's nulls are a view of the source's bitmap instead of a Go-heap copy, a read-only decode references the encoded null bytes instead of cloning them, and the stream decoder reads straight into pool words. DetachNulls gives a window that must outlive its source (an Arrow prefix whose lease moves) its own copy. A nullable function result reserves its null capacity when it is prepared, so an admission failure is an error rather than a panic in an in-place write. ResetWithSameType keeps the bitmap's words for reuse. Every bitmap user now has a pool and a matching Free: bloom filters, TAE batch deletes (windows get views), row selections and dedup bitmaps, objectio's bitmap pool, join matched bitmaps and their mailboxes, the join map's delete rows, filter and table-scan selections, deletion and multi-update block bitmaps, the integer IN operator (now with a free hook) and function temporaries. The unused tae/compute.ShuffleByDeletes is removed. Tests that pinned "null bitmaps are Go-owned and uncharged" now assert that they are charged and that accounts drain to zero. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with matrixorigin#33115 (vector test consolidation) and matrixorigin#33127/matrixorigin#33133 (dedupjoin captured-vector owner pool): carry the read-only-NULL fixture to minmax_test.go, keep the pool-owned bitmap tests in mpool_test.go, and free both the captured vectors (with their owner pool) and the worker's matched/captured bitmaps in freeWorkerJoinMsg. Port upstream's new tests to the pool-taking bitmap API. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- bitmap_mem.go: use util.UnsafeSliceCast for the word/byte views, as molint checkunsafe forbids importing unsafe in this file (SCA). - TestChaos1 read view.Deletes after view.Compact(), which now releases the deletes bitmap, so the count was always 0. Count first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Gobra: - bitmap core: all 63 per-member runs verify; nulls verifies against the new pool-owned bitmap contracts (bitmap_mem.gobra, mpool stub). - verify.sh caps each Gobra JVM at 2 GB (GOBRA_JAVA_OPTS) and sizes VERIFY_JOBS from available memory, so parallel runs no longer exhaust RAM. Leak review fixes: - objectio.BitmapPool: free bitmaps allocated on pool overflow (regression from pool-owned bitmaps); test proves the pool returns to baseline. - tae Scan/HybridScanByBlock: close a partly built batch on error; fixes a use of a closed batch in ReadMergeSettingsBatch. - frontend convertRowsIntoBatchInLocation, batch.OwnReadOnlyVectors: free partial results on error. - blockio: release a discarded bitmap; hashbuild: free IgnoreRows before reallocating; vector.WindowInto rejects a target owning its nulls; remove unused anode.FillBlockView (aliased delete bitmap). Docs: mo-dev skill reference bitmap-memory.md (ownership model, G-BITMAP). Co-Authored-By: Claude Opus 5.5 <[email protected]>
- HybridScanByBlock: a Scan failure and a tombstone failure close the partly built batch and return nil; an error before Scan keeps the caller's batch. baseObject.Scan and HybridScanByBlock share closeBatchOnError. - batch.OwnReadOnlyVectors frees the replaced originals (one owning its nulls) when a later Dup fails. - vector.WindowInto rejects a read-only target that owns its nulls. - frontend convertRowsIntoBatch frees earlier columns when a later one fails to convert. Each test fails on the code before the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…33183) Issue matrixorigin#33181 ## What Adds `docs/design/20261124-row-selection-bitmap-remaplist.md`, the design and implementation plan for matrixorigin#33181. The plan has two parts: - **Bitmap as the only row selection.** Every `sels` list that selects rows (ascending, unique) becomes a bitmap, following the existing batch-selection model: the producer owns the bitmap and lends it to consumers through the batch. - **One `RemapList` type for reordering.** Sort permutations, join gathers, hash buckets and inverse maps move into one type with one gather kernel. The doc covers: - the four row-selection representations in use today, and the conversions between them on the hot paths; - a classification of the call sites; - the ownership rule: one owner, one allocation and one free per query; - the bitmap primitives to add, and the `RemapList` API; - an 11-PR plan, with a benchmark for each step; - risks and open questions. This PR changes documentation only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
- RemapList is remaplist.List in pkg/common/remaplist (decision 5); the location open question is closed. InvertInto writes into an owned List. - InitWithSize already reuses words on matrixorigin#33144; PR 1 drops it. - New bitmap primitives in bitmap.go carry Gobra contracts. - Leak checks are pool CurrNB tests (there is no bitmapleak build), and the ascending-sels assertion is new (Shrink does not check today). Issue matrixorigin#33181 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…33181 PR 1) Bitmap (pkg/common/bitmap/bitmap_select.go): - InitWithBools: build a selection from a bool predicate and its nulls a word at a time (8192 rows: 3.7us vs 12.4us for bools -> sels -> InitWithRows; 0 allocs). - InitDeposit: map a selection over a base's set rows back to base positions (the "compose" of the design; delete mask -> physical rows). - KeepFirstN: keep the k lowest set rows. - Word / NumWords: word access for word-at-a-time loops over a selection. All read other bitmaps through the verified bitsFrom, so read-only views work. They are outside the Gobra proof for now. Vector/Batch: - UnionByMask appends the selected rows of a source without a row list; handles const sources, self/window aliasing, varlen area pre-growth and NULLs. 8192 int64 rows: 2.6us vs 3.3us (50% selected), 5.1us vs 6.5us (95%) for ToI64Array + Union. - Shrink asserts strictly increasing, non-negative sels in race builds. Tests compare every primitive with a per-row model, including read-only shifted views and pool CurrNB back to zero. Issue matrixorigin#33181 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rigin#33181 PR 1) The row-selection primitives move from the unverified bitmap_select.go into the Gobra-verified core. bitmap_select.go now carries contracts and proofs and is verified by gobra/verify.sh with bitmap.go loaded; runs for bitmap.go's own members leave it out, so new members do not change the proof context of existing ones. Proven (in terms of Has): - InitWithBools: row r set iff values[r] && r not in nulls. - InitDeposit: row r set iff r in base and sel holds r's rank in base. - KeepFirstN: a row stays iff it was set and fewer than k set rows lie below it (word loop in keepLowBits, rank facts in lemma keepFirstRows). - Word, NumWords, depositBits. Loops over set bits use TrailingZeros64 + &^ (the bit model has no axiom for w & -w); benchmarks are unchanged. Existing proofs made robust: removeOrderedWord/removeOrdered and removeMaskWord/removeMask passed or failed depending on unrelated edits and even on the directory Gobra ran in (identical files). Their output relation is now named (RemoveRel, RemoveMaskRel), so each check matches one term; all four verify from every directory tried. Results: gobra/verify.sh 70/70 runs verified; nulls verify 0 errors; vacuity (assert false at entry and exit) caught in all 22 variants of the new and restructured members. Issue matrixorigin#33181 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shrink takes strictly increasing sels; the race build asserts it since matrixorigin#33181 PR 1. TestVarlenaAreaDisjointLifecycle duplicated a descriptor with Shrink([0, 0]); Shuffle is the API for repeated rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… PR 2) The storage read path turned every block's delete mask into a []int64 with ToI64Array and then called Shrink(neg) per column. It now passes the mask to ShrinkByMask: BlockDataReadInner (both full-read paths), blockDataReadWithFilter, BlockDataReadBackup, and TAE CompactByBitmap. shrinkFixedByMask works a word at a time: removing rows copies each run of kept rows at once, keeping rows moves a full word with one copy. 8192 int64 rows, 1% deleted: 2.1 us vs 3.9 us for ToI64Array + Shrink; 30% deleted: even. No allocations; the per-block delete list is gone. Tests: ShrinkByMask against Shrink over types, sizes, densities, offsets and both directions; backup read with tombstones and no commit column; ordered-limit fallback read with a row-id column; CompactByBitmap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…3181 PR 2) UnionBatch copied a fixed-width range with one copy but set its NULLs one row at a time with Contains and Add. For 8192 nullable int64 rows that was 14 us of a 16 us append. Bitmap.OrShifted(b, src, dst, cnt) sets row dst+k for every set row src+k of b, a word at a time: each destination word takes its source rows with one bitsFrom, masked to the range. It is in the Gobra-verified core (bitmap_select.go): row r is set exactly when it was set or dst <= r < dst+cnt and b has row r-dst+src. gobra/verify.sh: all 72 runs verified; nulls: 0 errors. BenchmarkUnionBatchNullable (8192 int64, 1 in 17 NULL): 15.8 us -> 1.35 us, no allocations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ay lists Bitmap.Word goes through the general unaligned loader, about 4.5 ns a word, so UnionByMask spent 630 ns on the 128 words of an 8192-row mask with one row set. OwnedWords returns an owned bitmap's words (nil for a read-only view); the vector's maskReader indexes them and falls back to Word for views. Correct because owned bitmaps keep the verified TailClear invariant. One set row: 640 ns -> 142 ns. Search results stay []int64: measured against a gather by an existing list, a mask gather is slower at every density (1 row: 4 vs 142 ns; 4096 rows: 1.1 vs 1.9 us), the producers build lists natively, and the tombstone chain stops early on an empty list. The design doc records the measurements and narrows decision 1 accordingly. Also: TestUnionBatchNullsAtOffsets, BenchmarkUnionBatchNullable and TestMaskGatherWithViewMask. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comments at ReadFilterSearchFuncType, engine.DataSource.ApplyTombstones and blockio.ReadDataByFilter: the rows are kept as a sorted list on purpose for now, with a pointer to the measurements in the design doc. The design doc marks the decision as to be re-examined later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 25, 2026
PR 1 (matrixorigin#33213) and PR 2 (matrixorigin#33232) are squash-merged into main, so this merge keeps only PR 3's own changes. Main's matrixorigin#33184 moved a published selection into the batch that carries it (OwnSelection / FreeSelection, SetSelection(sel)); PR 3 keeps that ownership and its word-wise bitmaps: - filter: the selected path builds its rows into the view's own selection with InitWithBools and ANDs later predicates through one filter-owned scratch bitmap (pred), which the compacting path also gathers by. Reset and Free return pred to its pool, as main already does for the view's selection. - table_scan: keep, pred and dep stay scan-owned scratch; reset now frees them too, so their words go back to the execution's pool. - blockio: publishBatchSelection fills output.OwnSelection from the mask (InitWith) or the list (InitWithRows); the caller-owned publish bitmap is gone, and with it the test case where the mask was that bitmap. - vector: unionVarlenByMask keeps PR 3's word loop with PR 2's review fix: the area is always sized by the selected payload, never by len(w.area). - Tests: batch.New and the two-argument SetSelection are gone on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt
marked this pull request as ready for review
November 28, 2026 21:15
fengttt
requested review from
LeftHandCold,
XuPeng-SH and
aptend
as code owners
November 28, 2026 21:15
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? |
Contributor
|
This pull request is merged. |
Contributor
|
mo-bot review · Commit: "interrupted" |
fengttt
added a commit
to fengttt/matrixone
that referenced
this pull request
Nov 28, 2026
…181-pr4 upstream/main's tree equals PR 3's head (f856983), which this branch already contains, so the tree is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt
added a commit
that referenced
this pull request
Nov 29, 2026
… PR 4) (#33266) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #33181 ## What this PR does / why we need it: PR 4 of the row-selection plan in `docs/design/20261124-row-selection-bitmap-remaplist.md`. Expression evaluation takes the selection as a bitmap. This removes the last per-batch conversion on the scan, filter and projection path: expanding the selection bitmap to `[]bool` for `Eval`. PRs 1–3 (#33213, #33232, #33236) and #33144 have merged, so the diff is this PR only. ### Changes - **`Eval` takes a bitmap.** `ExpressionExecutor.Eval` and `EvalWithoutResultReusing` take `sel *bitmap.Bitmap` instead of `[]bool`. nil still selects every row. - Filter, projection and table_scan pass their selection bitmaps directly. - `ExternalRoutineEval` (added upstream since this PR was drafted) takes the bitmap too: its strict row-count check uses `Len`, and membership uses `Contains`. - `Batch.SelectionMask` (which called `ExpandBools`) is removed. - **Branch selections are bitmaps.** IF, CASE, COALESCE and JSON ELT build the rows each branch is evaluated on in two bitmaps owned by the executor. They are allocated from the executor's pool on first use, re-initialized per batch, and freed in `Free`. - COALESCE narrows the remaining rows by each argument's NULL bitmap, a word at a time. - **Gather and scatter by mask.** `evalSelectedRows` gathers row-aligned inputs with `UnionByMask` and scatters the compact result back with the new `Vector.ScatterByMask`. - `ScatterByMask` is the inverse of `UnionByMask`. Fixed-width values go a word at a time, and the unselected rows are marked NULL a run at a time. - Variable-length types are scattered a row at a time. - **No per-call `FunctionSelectList` copy.** A kernel is called only when every row is selected, since partial selections are compacted first. So it receives one constant all-rows list. - The list stays non-nil. Some kernels choose their path by whether it is nil: string `=` takes a varlena fast path, and `arithmetic.go` treats nil like a partial selection. - The kernels' own masking paths are no longer reached from the executor. Removing them is part of PR 6. ### Benchmark `BenchmarkEvalSelection`: one 8192-row batch, µs, PR 3 → PR 4. Both builds were run alternately, pinned to the same cores, and the table shows the minimum. | expression | all rows | half | tenth | | --- | --- | --- | --- | | `a + b` | 52.9 → 52.8 | 218 → 84 | 29.7 → 19.7 | | `IF(a > 0, a + b, b)` | 317 → 207 | 573 → 257 | 94 → 63 | | `CASE` with two conditions | 294 → 202 | 750 → 282 | 144 → 73 | | `COALESCE(a, b)` | 84 → 40 | 250 → 55 | 38 → 14 | ### Tests - `TestScatterByMaskInvertsUnionByMask`: across types, row counts, densities and NULL rates, scattering the `UnionByMask` gather of a source restores every selected row and makes the others NULL. - `TestScatterByMaskConst`: constant, constant NULL and varchar NULL sources, and an error when the source has too few rows. - Existing tests now build selections with a `boolSelection([]bool)` helper. Test mocks of `ExpressionExecutor` take the new signature. - Unit tests and `-race` pass for colexec, filter, projection, table_scan, vector, batch and plan, and for the operator packages whose mocks changed. - PR 3's BVT run on a 2-CN dev cluster found no regressions. Every failure there was an environment difference: tracing off, `AUTO_ID_CACHE` off, loopback services, optimistic suites, timezone, or leftover state. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
fengttt
added a commit
to fengttt/matrixone
that referenced
this pull request
Nov 29, 2026
… into sels-bitmap-33181-pr5 PR 3 and PR 4 were squash-merged upstream after this branch was cut from PR 4's draft. The tree is upstream/main plus this branch's one commit (e88c27d). Upstream removed Batch.Attrs (matrixorigin#33199), so the offset window copy no longer copies attribute names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt
added a commit
that referenced
this pull request
Nov 29, 2026
…R 5) (#33267) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #33181 ## What this PR does / why we need it: PR 5 of the row-selection plan in `docs/design/20261124-row-selection-bitmap-remaplist.md`. The remaining operator and frontend sites that built an ascending row list one row at a time, then shrank or copied by it, now use a selection bitmap. PRs 1–4 (#33213, #33232, #33236, #33266) and #33144 have merged, so the diff is this PR only. ### Changes - **DML operators.** Each bitmap is allocated once by the operator and freed in `Reset` and `Free`. - INSERT IGNORE's NULL primary key filter keeps the complement of the PK NULL bitmap. - DELETE's row-id dedup (`FilterRowIdForDel`) fills a bitmap. - MULTI_UPDATE's target and ODKU filters. - PREINSERT's target selector. - PREINSERT_UNIQUE's accepted rows. - LOCK_OP's SKIP LOCKED rows. - **Other operators.** - The CTE cache (`cteaccount.CacheBatch`) takes the inserted rows as a bitmap. - TIME_WINDOW's non-NULL time rows. - The Iceberg delete filter uses `InitWithBools`. - OFFSET copies the contiguous tail with `UnionWindow` instead of copying the batch and shrinking it. - **Scan fallback filter.** `table_scan`'s `evalFilter` works on the same bitmaps as the main path and returns a `Mask`. Its scratch bitmaps come from the process pool, so they are not charged to the scan's output memory account. - **Frontend.** The `SHOW VARIABLES` and `SHOW COLLATION` WHERE filters share a new `colexec.InitBoolSelection` helper and shrink by mask. - **Faster `InitWithBools`.** It packs eight bools per multiply, about 4× faster. That code uses `unsafe`, which Gobra can't check, so it is trusted through a contract in `bitmap_pack.gobra`. `TestPackBools` checks the code against that contract. The Gobra README lists it in the trusted base. All 72 Gobra runs verify. ### Bugs fixed - **IVF-FLAT TopK residual path** (`blockDataReadWithSelectedFilterTopK`). It read only the `Sels` form of a filter result, so a `Mask` result would have dropped rows. A new test case fails without the fix. No existing case reached that path. - **SHOW WHERE filters.** They ignored NULLs, and a constant condition such as `WHERE 1` kept only the first row. ### Benchmark `BenchmarkBooleanFilterSelection`: the scan's fallback filter on one 8192-row batch, µs, PR 4 → PR 5. Both builds were run alternately, pinned to the same cores, and the table shows the minimum. | filter result | PR 4 | PR 5 | | --- | --- | --- | | all rows true | 12.0 | 2.0 | | a quarter NULL | 31.9 | 21.5 | | all false | 2.15 | 2.06 | | two thirds true | 8.9 | 10.2 | The two-thirds case is about 15% slower: shrinking a 1-byte column in place by mask costs more there than by list. A table-based variant only helped at 90% density, so it was left out. Two cases of this benchmark failed on both branches because the input was built in the wrong memory pool. That is fixed. ### Deferred to PR 6 These are forced when the list APIs are removed: - Set operators' per-row flags. A bitmap would need an offset-aware copy, with no clear gain. - Join gathers. These belong to the RemapList track (PR 10). - `data_branch_hashdiff`. Some of its lists come from conflict checks, and one relies on ORDER BY. - Storage and TAE sites. ### Tests - `TestPackBools`, a test for `InitBoolSelection`, and `mask=true` variants plus a `storage_selection_residual` case in `TestBlockDataReadWithFilterAppliesVectorTopKAfterResidual`. - Unit tests and `-race` pass for bitmap, colexec, deletion, multi_update, preinsert, preinsertunique, lockop, mergecte, cteaccount, timewin, table_scan, offset, filter and blockio. Frontend unit tests pass. - golangci-lint is clean. - BVT has not been run for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #33181
What this PR does / why we need it:
PR 3 of the row-selection plan in
docs/design/20261124-row-selection-bitmap-remaplist.md. The selection now stays a bitmap from blockio through the scan filter, the filter operator and projection. Compaction gathers by the bitmap.#33213 (PR 1), #33232 (PR 2) and #33144 are merged; this diff is PR 3 alone. It is merged with main after #33184, which moved a published selection into the batch that carries it (
OwnSelection/FreeSelection); this PR keeps that ownership. The filter's and the scan's scratch bitmaps go back to the execution's pool inReset, as the published selection already does.Conversions removed
Before this PR, the filtered scan converted the selection at every hop. Two of those conversions are gone:
[]int64(compactPredicateRows).InitWithRows).SelectionRows→Union.The remaining conversion, expanding the bitmap to
[]boolforEval, is PR 4.Scan filter (
table_scan,blockio,engine)engine.ReaderFilterResultgainsMask, the kept rows as a bitmap over the input rows.Selsstays for producers that build a list: membership, exact scan, andApply.CountandRowListread either form.ReaderFilterRequest.RowListgives the loaders that read by list a buffer reused across blocks. Those are the late columns and membership's physical row map; storage search results stay lists (see perf(blockio): apply delete masks with ShrinkByMask (#33181 PR 2) #33232).Selectbuilds the mask withInitWithBools.InitDeposit.UnionByMask.InitWithRows.Filter operator, projection, compaction
InitWithBools, a word at a time.Andon a scratch bitmap, where it used to iterate andRemoverow by row.compactByMask, which usesUnionByMask, orShrinkByMaskin place on its own batch;Batch.CompactInto, which loses its row scratch;compactInto.UnionByMask's NULL and varlen loops work a word at a time, with no per-row closure. A NULL slot's varlena descriptor is cleared.Benchmarks (8192 rows, PR 2 → PR 3, no allocations either way)
BenchmarkFilterBlockFlat(a > 10 keeps 45%, 1 in 13 NULL, compacted)BenchmarkFilterBlockSelected(same, selected output)BenchmarkReaderSelectOne(one predicate, 1 in 11 NULL)BenchmarkReaderSelectTwo(chain of two)Decode the selection once per multi-column gather (commit
e237de3502)TPC-H SF100 profiles showed q12 slower than main: the scan's mask gather in
gatherSelectedColumnsandcompactIntocost 153 s of CPU against 93 s on main. A mask gather walks the set bits of the mask once per column, and that bit loop costs about 0.5 ns per bit, so per column it is about 2× slower than a gather by row list.bitmap.AppendRows), reuses it across blocks inselectionState, and gathers every column withUnion.With the fix applied across the stack, a full ABBA run gives a sum of per-query bests of 123.7 s vs 124.4 s for main (−0.6%): q12 −3.9%, q19 −2.5%, 132/132 golden results on both.
Testing
TestCompactIntoGathersThroughRowListcheckscompactIntoagainstUnionover the selected rows, for several columns (row-list path: int64 and short/long varchar with NULLs, a nil and an empty column) and for one column (mask path).TestSelectionGatherRowscovers the fallback to the mask when a selected row lies past the source.TestSelectReaderFilterMaskMatchesApply: the scan's mask keeps the same rows as the list-basedApplypath over eight predicate chains (partial, all-true, none, NULLs, constant TRUE, FALSE and NULL).TestValidateReaderFilterResultMaskcovers mask validation.TestFilterConstantConditions: constant conditions on both filter paths, alone and after a partial predicate.go testpasses forpkg/sql/colexec/..., blockio, readutil, disttae,pkg/container/..., ivfflat and bitmap.🤖 Generated with Claude Code