Repository navigation
Text index: remove left-over roaringish from the positions merge path - #121976
Conversation
|
Workflow [PR], commit [5785d2d] Summary: ❌
AI ReviewSummaryThis PR replaces the leftover roaringish positions accumulation with direct blocked-position re-encoding on both the build and merge paths. The on-disk layout still looks consistent and CI is all green, but I do not think the review is clean yet: the new per-source interleaving branch in PR Metadata
Findings
Final VerdictLLVM Coverage ReportMeasured on commit 5785d2d.
Changed lines: Changed C/C++ lines covered: 192/205 (93.66%) · Uncovered code |
Previously, the merge decoded every positional source whole into roaringish entries, remapped their doc ids, sorted all of them and re-encoded. With this PR, left-over roaringish is completely removed from the code base and merge postings segment by segment for every source. The merge queue reports which source each emitted row id came from, and that source's next position lists are streamed block by block into the positions encoder in merged order. Nothing is sorted or materialized per token. The build side streams per-document lists into the same encoder. The on-disk format is unchanged, and merging interleaved positional parts should be faster.
7bfef8f to
7e972d5
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (-25.39 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units29 translation units recompiled, 279 s compile time in total, 29 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
|
||
| if (positions) | ||
| { | ||
| if (run_length != 0 && window_sources[bit] != run_source) |
There was a problem hiding this comment.
This source-tracking branch only gets stressed when postings from different parts actually interleave after the row-id remap. The existing merge coverage in tests/queries/0_stateless/02346_text_index_phrase_search.sql merges disjoint id ranges, so window_sources never has to alternate within the same token and this bookkeeping can regress unnoticed.
Please add a focused stateless test that inserts odd/even ids into separate parts (or any other layout that forces interleaving after OPTIMIZE FINAL) and validates hasPhrase before and after the merge.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
| if (!sorted) | ||
| { | ||
| std::sort(first, last); | ||
| last = std::unique(first, last); |
There was a problem hiding this comment.
Why can positions be non-unique?
There was a problem hiding this comment.
mostly because of array and map containers that reset position to 0 at each element. e.g. ['hello world', 'hello']. hello comes at position 0 twice.
There was a problem hiding this comment.
That looks strange, because it may give false positives. Also, it looks like hasPhrase does not support arrays, and positions cannot be used anyhow. I also see PR #121300, but we will need to properly support positions at the edges of tokens from adjacent array elements to avoid false positives. Maybe it's simpler just to disable positions with arrays.
There was a problem hiding this comment.
Ah, I see, the support was added in #120859 with a hint mode.
There was a problem hiding this comment.
It looks like we need something like this: https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/position-increment-gap. Then we can answer hasPhrase queries on top of arrays with exact direct reads and the slop parameter value up to the fake gap value.
There was a problem hiding this comment.
yes, we support hasPhrase in hint mode for array inputs, but we can implement "position increment gap" similar for enabling the exact mode. It would be really helpful.
So far, there shouldn't be any false-position with the current implementation. I'll have a look into implementing "position increment gap" in follow-ups to enable the exact mode.
| size_t offset = writeVarUIntTo(block_begin, num_exceptions); | ||
| for (UInt32 value : exceptions) | ||
| offset += writeVarUIntTo(block_begin + offset, value); |
There was a problem hiding this comment.
For the follow-up: maybe it's better to just save frequencies as pfor block. I remember that when I checked the sizes of the frequency arrays for BM25 compressed with pfor and the sizes of the position exceptions, the plain pfor block was smaller even for blocks with a few exceptions. Probably the decode speed will also be better.
Resolve conflicts with ClickHouse#121976 (streaming merge of text index positions): take `PositionsMerge` from master and drop the per-source capture of pre-remap row ids (`captureRowIdsForPositions`, `readAndAppendPositions`, `flushPositions`); keep the BM25 term-frequency path of `PostingsMergeQueue` alongside the positions source tracking. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
@ahmadov @CurtizJ — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |

The roaringish based positions support was dropped by #111550, however merge path decoded every positional source whole into roaringish entries, remapped their doc ids, sorted all of them and re-encoded.
With this PR, left-over roaringish is completely removed from the code base and merge postings segment by segment for every source. The merge queue reports which source each emitted row id came from, and that source's next position lists are streamed block by block into the positions encoder in merged order. Nothing is sorted or materialized per token. The build side streams per-document lists into the same encoder.
The on-disk format is unchanged, and merging interleaved positional parts should be faster.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Remove left-over roaringish from the code base.
Workflow [PR]
Sync PR [sync-upstream/pr/121976]
Version info
26.10.1.1668-master(included in26.10and later)