Repository navigation
fix(hashbuild): bound collected runtime-filter keys - #32191
Conversation
Collect unique join keys in aligned batches of at most 8192 rows instead of growing one vector for the whole build. Preflight row and encoded-size limits, admit metadata capacity, and roll back partial appends across columns and chunks. Preserve the ordinary IN wire format by merging bounded sorted runs directly into the final encoding. Publish membership keys as one immutable reference-counted chunked payload, retain it across lazy readers, and build one complete exact membership structure for native and host readers. Cover chunk boundaries, hash-table uniqueness, byte-size refusal, allocation rollback, SQL key domains, payload ownership, and CPU native membership construction.
Keep a received key payload alive while validating its required membership contract, then transfer that reference to the received-filter list or release it on rejection. Verify lazy-reader references, diagnostic forwarding, exactly-once cleanup after close errors, concurrent Close calls, and rejection of retired payload owners.
Use the existing HashBuild and HashmapBuilder receiver conventions for the new chunked publication helpers so the full staticcheck gate remains clean.
Sort fixed-width IN keys directly in the admitted wire buffer and cache variable-width merge heads. Reuse trusted local encoder output, keep single membership frames inline, and pack multiple frames into bounded backing arenas to avoid per-frame allocator overhead. Reserve bounded PK key capacity only when complete input cardinality is known and eligible for the filter. Keep variable-width size preflight cheap when a conservative area bound fits, preserve typed empty collections for all-NULL builds, and verify every fixed-width ordering against the existing vector sorter.
Exercise contiguous and selected key appends with a small byte ceiling, preserving column slots and values across short chunks and checking final allocation-account cleanup. Verify that partially constructed reader sets release acquired payload references and close remaining readers even when an earlier Close fails.
Join append and rollback errors after attempting every column restoration, then release the entire collected-key owner if a checkpoint cannot be restored. This prevents optional-filter fallback or retry from observing partially restored keys. Add small injected failure coverage for both error identities and zero retained charge, plus an 8193-key SQL membership regression comparing PRE with exact search before Top-K.
Choose the merge comparator once and compare heap positions without copying run descriptors. Copy each variable-width backing area once, then rebase sorted descriptors into the final admitted IN encoding, preserving shared values and avoiding per-key payload copies. Cover shared-area framing and cleanup, and use keyed decimal fixtures for static analysis.
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: da199198011d4dbfa399e8f129aee9dbcc28e986
Assessment: approve
Aligned key batches reuse Vector accounting, and immutable payloads reuse buffer leases. The batch and row directories are justified by bounded collection and complete membership before Top-K. No actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 63 changed files, affected producers/consumers, design and complete discussion; saved the change map, ownership audit and discussion assessment.
-
Isolation preflight and frozen-head native CPU build passed; native input/output manifests verify provenance.
-
Full CPU suites passed for keycodec, docfilter, runtimefilter, indexplugin/search and hashbuild. Race suites passed for keycodec, docfilter and indexplugin/search.
-
Concurrent-close and partial-construction tests each passed 100 race repetitions. Production-builder probes passed for 16,385-key IN publication and composite casts across three chunks; focused IVF/storage tests passed.
-
validation-report.json reconciles commands, logs and terminal receipts. Supplied frozen-head CI reports successful UT, SCA, native builds and multi-CN BVT.
Limitations:
-
Combined consumer and compiler-only checks exceeded 600-second build/link limits before test execution; compiler cases were not executed locally.
-
CUDA execution and end-to-end performance measurements were not independently validated.
-
The local native profile disables jemalloc C++ overloads; its C API remains enabled.
✅ Merged into
|
Backport matrixorigin#32191 to 4.2-dev to stop HashBuild runtime-filter key vectors from growing across the entire build. Collect unique keys in aligned chunks of at most 8,192 rows, splitting earlier at payload and encoding byte limits. Preserve component slots and keep hash insertion as the sole uniqueness authority. Admit chunk directories and scratch before allocation, roll back failed multi-column appends, and discard collections with invalid checkpoints rather than retrying or publishing partial keys. Keep the ordinary IN wire format and single-chunk fast path. Sort fixed-width keys in the final admitted encoding and merge variable-width sorted runs without constructing a whole-build vector. Materialize composite keys per aligned chunk. Publish membership keys as one immutable, reference-counted payload. Adapt the existing 4.2-dev IVF/fulltext TVFs to consume every chunk into one reader filter, retaining keys through use and releasing them on error, reset and free. Preserve the release's exact non-integer IVF predicate and its global 8 MiB limit: required membership must be complete or return an error, never silently become approximate or partial. Do not import main's vectorscan/index-plugin reader refactor or change the native filter ABI. Include the small capacity-reservation helper needed to account for Go-backed key metadata on this release, and the existing main bitmap range-mask correction needed to clear NULL/grouping bits during append rollback at word boundaries. Retained build-row storage, JoinMap row addressing, planner thresholds, allocator limits, disk formats and spill policy are unchanged. (cherry picked from commit 692c8e1)
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [x] Code Refactoring ## Which issue(s) this PR fixes: Related to #30125. Backport of #32191. ## What this PR does / why we need it: Bound HashBuild runtime-filter key collection to aligned chunks of at most 8,192 rows, with earlier splits for component-vector byte limits. This avoids growing one key vector across the entire build. The ordinary path collects newly inserted hash groups; HashOnPK retains the existing primary-key uniqueness assumption. Account for chunk metadata, roll back failed multi-column appends, and reject invalid checkpoints without publishing partial keys. Keep the ordinary IN encoding and single-chunk fast path. Numeric runs are copied and sorted in the final admitted buffer; other sorted runs are merged without a whole-build vector. Inline runs whose key ranges are already ordered can use the same admitted buffer and bulk-copy path. Integrate the 4.2-dev composite-primary-key filter from #32400: convert components in probe-key order for each chunk, use the converted vectors for bounds and encoding, and turn an out-of-range optional filter into whole-filter PASS. A cancellation already observed at that fallback remains an error. Publish membership keys as one immutable, reference-counted payload and adapt the existing 4.2-dev IVF/fulltext consumers to visit all chunks. IVF may use a complete exact SQL predicate or a tagged reader filter, according to the existing key-type contract. Required non-integer IVF membership retains the 8 MiB global literal-list limit and fails rather than becoming partial or approximate. The release keeps its existing TVF architecture and native filter ABI. The rebase also adapts the #32243 optional-collection failure tests to the chunked owner, preserving PASS, complete JoinMap, wide-key lookup, and accounting checks. It retains the author's concurrent merge fixes and fixture cleanup. ## Validation of the rebased production tree - Normal and race suites for the 12 changed/affected CPU packages; HashBuild, runtimefilter and the planner were rerun after the last production change. The exact two-CN role-grant fixture was also run under `-race -short`. - Four focused lifecycle tests each passed 100 `-race` repetitions: ordered-run cancellation and cleanup, composite narrowing, next-chunk admission failure, and cross-chunk rollback. HashBuild also passed `-short -covermode=set` (74.7% of that package's statements; this is not changed-code coverage). - An embedded SQL differential test verified an actual `serial(cast(...), ...)` composite-PK runtime-filter plan with 9,000 build keys; enabled, disabled, out-of-range and NULL controls returned the same 9,000 matches. The input exceeded one chunk, but the SQL experiment did not instrument per-operator chunk count; white-box tests explicitly construct and validate multiple chunks. - The repository's IVF membership BVT ran twice in normal comparison mode on one isolated CN after SQL and ISCP readiness: 44/44 statements each time, zero ignored, with both test databases verified absent after each run. - Incremental `gofmt`, `molint`, and golangci-lint 2.6.2 passed over the changed package closure. The additional planner scan reports three `checkrecover` items at identical lines on the unmodified 4.2-dev baseline. Tests used Go 1.26.6 and CPU native libraries; a rebuild from the same tracked native sources produced an identical libmo executable-code section. ## Performance and limits In a local pinned-CPU microbenchmark comparing the rebased code immediately before and after the ordered-inline optimization, three-sample medians for ordered composite keys changed from 1.156/1.190 ms to 0.880/0.907 ms at 8,193 rows and from 10.341/10.101 ms to 7.537/7.755 ms at 65,536 rows (direct/cast respectively). Single-chunk controls also varied 4–8%, so these are local measurements, not a general speedup claim. Randomly interleaved 65,536-row cases changed by +2.4%/+1.4% in another three-sample comparison. Chunking still increases Go allocations: the 65,536-row cast fixture used about 111 allocations on the 4.2-dev baseline and 359 here. Go allocation figures exclude MPool/native memory. CUDA, mixed-version rollout, multi-gigabyte workloads, peak MPool/native memory and end-to-end OLAP performance were not independently validated in this run. The author previously reported full-repository SCA and additional 100-run ownership stress on the earlier PR revision; those reports are historical evidence, not new-head CI results. Design: [bounded HashBuild key collection and 4.2-dev integration](https://github.com/aunjgr/matrixone/blob/91c9bbf26c012fab1cc8a4a4e7bb2f73373d7977/docs/design/hashbuild-key-batches.md). --------- Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #30125.
What this PR does / why we need it:
HashBuild currently collects runtime-filter keys into one growing vector per key component. These vectors span the entire build and can reach the single-allocation ceiling independently of retained join batches.
Collect keys in aligned batches of at most 8,192 rows, splitting earlier at actual payload and encoding byte limits. Preserve component slots and leave uniqueness decisions to the hash table. Admit chunk-directory storage before allocation and restore the previous tail after an append failure. Join rollback failures with the original error, finish remaining cleanup, and discard invalid collections rather than retrying or publishing partially restored keys.
Preserve the ordinary IN wire format and single-chunk fast path. Encode fixed-width runs directly into the final admitted buffer and sort there. For variable-width runs, bulk-copy each area once and merge/rebase the sorted descriptors, preserving shared values without a whole-build temporary vector or per-key payload copies. Evaluate composite-key expressions per aligned batch with reusable executors.
Publish membership keys as one complete, immutable, reference-counted chunked payload. Retain ownership through compiler receipt and lazy-reader lifetimes, and consume all chunks into one membership structure. Native integer filters choose their representation from the global key range/cardinality and populate it in bounded batches. Non-integer IVF prefilters retain an exact sorted row directory using the source primary-key comparison domain, preserving required filtering before Top-K.
Keep allocation provenance and cleanup for collected vectors, directories and encoded payloads. Optional size/admission refusal may fall back to PASS; required membership cannot be silently disabled. Empty sets, missing filters, PASS and DROP remain distinct. Retained build-row storage, JoinMap row addressing, planner thresholds, allocator limits and spill policy are unchanged.
Validation
Design: bounded HashBuild key collection.