Repository navigation
docs(design): row selection with bitmaps and RemapList - #33183
Merged
Merged
Conversation
Design and implementation plan for replacing row-selection index lists (sels) with bitmaps, and consolidating sort, gather and bucket remaps into one RemapList type. Issue matrixorigin#33181. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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? |
1 of 7 tasks
fengttt
added a commit
that referenced
this pull request
Nov 28, 2026
… PR 1) (#33213) ## What type of PR is this? - [ ] API-change - [ ] BUG - [ ] Improvement - [ ] Documentation - [x] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #33181 ## What this PR does / why we need it: PR 1 of the row-selection plan in `docs/design/20261124-row-selection-bitmap-remaplist.md` (#33183). It adds the bitmap primitives that later PRs use to replace `[]int64` sels with bitmaps. No caller is converted yet. **Stacked on #33144** (pool-owned bitmaps). Until #33144 merges, this diff also contains #33144's commits. The commits of this PR are the last three on the branch. ### Design doc update - RemapList lives in its own package, `pkg/common/remaplist`, as `remaplist.List` (decision 5). `InvertInto` writes into a `List` the caller owns. - Review corrections: - `InitWithSize` already reuses its words on #33144. - Leak checks are pool `CurrNB()` tests. - The ascending-sels assertion is new work: `Shrink` does not check today. - New primitives are Gobra-verified. ### Bitmap primitives (`pkg/common/bitmap/bitmap_select.go`, Gobra-verified) Contracts are stated in terms of `Has`, the ghost "row is set" predicate. | Primitive | Proven behaviour | Replaces | | --- | --- | --- | | `InitWithBools(values, nulls, mp)` | row `r` is set iff `values[r]` is true and `r` is not in `nulls` | bool predicate → sels → `InitWithRows` | | `InitDeposit(base, sel, mp)` | row `r` is set iff `r` is in `base` and `sel` holds `r`'s rank in `base` | per-row rank/select loops over a delete mask | | `KeepFirstN(k)` | a row stays iff it was set and fewer than `k` set rows lie below it | positional split of sels | | `Word(i)`, `NumWords()` | bit `b` of `Word(i)` is row `64i+b` | per-row `Contains` / iterator in gather loops | ### Vector and Batch - `Vector.UnionByMask` / `Batch.UnionByMask` append the selected rows of a source without building a row list. - They handle const sources, a source that is the destination itself (or a window of it), varlen area pre-growth, and NULLs. - The loop is word-at-a-time, and full words copy 64 rows at once. - `Shrink` asserts strictly increasing, non-negative sels in race builds. ### Benchmarks (8192 rows, 0 allocations for the new paths) | | new | path it replaces | | --- | --- | --- | | `InitWithBools` vs bools → sels → `InitWithRows` | 3.3–4.6 µs | 8.2–12 µs | | `UnionByMask` vs `ToI64Array` + `Union`, 50% selected | 2.6–2.9 µs | 3.0–3.7 µs | | same, 95% selected | 5.3–5.5 µs | 6.1–6.8 µs | ### Gobra verification - **Results:** - `gobra/verify.sh`: all 70 runs verified, including the 7 members of `bitmap_select.go`. - `pkg/container/nulls/gobra/verify.sh`: 0 errors. - Vacuity check (`assert false` planted at the entry and exit of every new and restructured member): caught in all 22 variants. - **Split file:** `bitmap_select.go` is verified with `bitmap.go` loaded. Runs for `bitmap.go`'s own members leave it out, so the new members don't change existing proofs' context. - **Existing proofs made robust:** `removeOrderedWord`/`removeOrdered` and `removeMaskWord`/`removeMask` passed or failed depending on unrelated edits elsewhere, and even on the directory Gobra ran in, with identical files. - Their output relation is now a named ghost function (`RemoveRel`, `RemoveMaskRel`), so each check matches one term. - All four verify from every directory tried. - **Split proofs:** `KeepFirstN` timed out after 40 minutes as a single method. It is split into the helper `keepLowBits` and the heap-free lemma `keepFirstRows`, and each part verifies in minutes. `InitDeposit` is split the same way, with the lemmas `depositWordRows` and `depositStep`. - **Bit loops:** the loops over set bits use `TrailingZeros64` plus `&^`, because the bit model has no axiom for `w & -w`. Benchmarks are unchanged. - `pkg/common/bitmap/gobra/README.md` documents the proofs and these lessons. ### Testing - **Unit tests:** - Every bitmap primitive is compared against a per-row model, with read-only shifted views as inputs and the pool's `CurrNB()` back to zero. - `UnionByMask` is compared against `Union(sels)` across fixed widths 1/2/4/8/16/32/24 bytes and varchar (inline and out-of-line values), with NULLs, const sources, self-aliasing, and masks longer than the source. - **Packages:** `go test` passes for `pkg/common/bitmap`, `pkg/container/{nulls,vector,batch}` and `pkg/objectio`. `go build ./...` and `go vet` are clean. - **Race build:** the race tests pass for all 21 packages that call `Shrink`, and the new ascending assertion never fires. 🤖 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.
Issue #33181
What
Adds
docs/design/20261124-row-selection-bitmap-remaplist.md, the design and implementation plan for #33181. The plan has two parts:selslist 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.RemapListtype for reordering. Sort permutations, join gathers, hash buckets and inverse maps move into one type with one gather kernel.The doc covers:
RemapListAPI;This PR changes documentation only.
🤖 Generated with Claude Code