Skip to content

Use posting list cursors in the trivial count from the text index - #123294

Merged
CurtizJ merged 8 commits into
ClickHouse:masterfrom
CurtizJ:text-index-count-lazy-cursors
Oct 4, 2026
Merged

CurtizJ merged 8 commits into
ClickHouse:masterfrom
CurtizJ:text-index-count-lazy-cursors

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Related: #122555

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Optimized SELECT count() queries answered from a text index with a compressed posting list codec (bitpacking, pfor).


Workflow [PR]
Sync PR [sync-upstream/pr/123294]

Version info

  • Merged into: 26.10.1.1497-master (included in 26.10 and later)

CurtizJ and others added 2 commits October 1, 2026 15:41
…dexCount`

The trivial count from the text index materialized the posting lists of
the multi-block tokens into Roaring bitmaps, even for compressed
(`bitpacking`, `pfor`) postings. In lazy apply mode it now applies the
cursors of `MergeTreeIndexTextPostingListCursor` (union or leapfrog /
brute-force intersection) window by window to a reusable byte filter
over the row range that can contain matches, and counts the set bytes.

`lazyUnionPostingLists` and `lazyIntersectPostingLists` now return
whether any byte of the filter may be set, so windows without matches
skip `countBytesInFilter`.

`ReadFromTextIndexCount` also reports the rows of the answered parts as
read rows and sets the approximate total rows for progress.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The multi-token counts over `pfor` postings go through the posting-list
cursors. Disable `use_text_index_postings_cache` so that every run reads
the postings.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [72520c0]

Summary: ❌

job_name test_name status info comment
Build (amd_fuzzers) FAIL
Build ClickHouse FAIL cidb IGNORED

AI Review

Summary

This PR moves ReadFromTextIndexCount onto the lazy posting-list cursor path for compressed text-index postings and adds correctness coverage for bitpacking / pfor, but the current review state still falls short of the user-facing Performance Improvement claim for both codecs: the direct before/after evidence in the PR still only covers pfor.

PR Metadata
  • Changelog category: Performance Improvement is appropriate for the code change.
  • Changelog entry: required, but currently too broad for the evidence in the PR. It claims the speedup for both bitpacking and pfor, while the added benchmark coverage still measures only pfor.
  • Exact replacement if you do not add a bitpacking benchmark: Optimized SELECT count()queries answered from a text index with a compressedpfor posting list codec.
Findings
  • 💡 Nits
    • [tests/performance/text_index_trivial_count.xml:17] [dismissed by author -- https://github.com/Use posting list cursors in the trivial count from the text index #123294#discussion_r4166884669] The only new benchmark table here is text_index_trivial_count_pfor; text_index_trivial_count still uses the default none codec. That leaves the bitpacking half of the Performance Improvement / Changelog entry contract without direct measurement.
      Suggested fix: either add a bitpacking benchmark/table here or narrow the user-facing claim to pfor.
Tests
  • ⚠️ Add one focused before/after measurement for a bitpacking table on the same count() workload if the PR intends to keep claiming both codecs. The new stateless test proves correctness on bitpacking, but not the claimed speedup.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: either benchmark the bitpacking path and keep the current claim, or narrow the PR title / Changelog entry to the already-measured pfor path.

LLVM Coverage Report

Measured on commit 72520c0.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 204/209 (97.61%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 1, 2026
@CurtizJ CurtizJ changed the title Count text index matches with posting-list cursors in the trivial count from the text index Use posting list cursors in the trivial count from the text index Oct 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

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
  • StressHouse run: 18a18c4b-217b-4506-9db5-6b3adab4dde8
  • MIRAI run: 7a411793-7d05-4197-81c0-0526be41af59
  • PR check IDs:
    • clickbench_3138566_1791079426
    • clickbench_3138579_1791079426
    • clickbench_3138585_1791079426
    • tpch_adapted_1_official_3138601_1791079426
    • tpch_adapted_1_official_3138622_1791079426
    • tpch_adapted_1_official_3138637_1791079426

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 72520c04b with master a55efadaa (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 98cee6e8d; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

6 object files changed (+20.87 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/ReadFromTextIndexCount.cpp.o 311.30 KiB 331.83 KiB +20.53 KiB (+6.60%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

9 translation units recompiled, 38 s compile time in total, 9 of them have a recent master baseline.

Job report

Parts in the test have ~1M rows, so with the default `text_index_posting_list_block_size`
every posting list of the `pfor` table fits in a single block and is counted by the bitmap
path in both binaries. Lower the block size so the posting-list cursors are exercised.

Related: ClickHouse#123294

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CurtizJ and others added 2 commits October 2, 2026 14:19
It is moved to a separate branch `text-index-count-read-rows-progress`.

Related: ClickHouse#123294 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`false` guarantees that no row of the window is set, `true` may be a false
positive, e.g. in `intersectBruteForce` when no row survives the final pass.

Related: ClickHouse#123294 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@CurtizJ CurtizJ self-assigned this Oct 3, 2026
`QueryBuilder::addRowsRange` already folds the token row ranges by search
mode (hull for `Any`, overlap for `All`) and fails the query on an empty
overlap, so the manually computed cursor range is redundant. The check for
an empty `All` posting list is also covered by `is_failed`, because
`QueryBuilder::addPostings` fails the query as soon as the intersection
becomes empty.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@CurtizJ

CurtizJ commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

Perf tests:
Screenshot 2026-10-03 at 23 12 03

# Conflicts:
#	src/Processors/QueryPlan/ReadFromTextIndexCount.cpp
@CurtizJ
CurtizJ added this pull request to the merge queue Oct 4, 2026
Merged via the queue into ClickHouse:master with commit 2493c46 Oct 4, 2026
147 of 149 checks passed
@CurtizJ
CurtizJ deleted the text-index-count-lazy-cursors branch October 4, 2026 12:41
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
CurtizJ added a commit to CurtizJ/ClickHouse that referenced this pull request Oct 4, 2026
…e-lazy-cursors-once

Conflicts in `MergeTreeIndexTextPostingListCursor` with
ClickHouse#123294: keep the raw-pointer
cursors with `LazyPostingsStats` and make the lazy union and intersection
return whether any row of the window may be set.

`ReadFromTextIndexCount` now sorts its cursors and chooses the intersection
algorithm once per part, as `MergeTreeReaderTextIndex` does.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
aschoube pushed a commit to aschoube/ClickHouse that referenced this pull request Oct 8, 2026
CurtizJ added a commit to CurtizJ/ClickHouse that referenced this pull request Oct 12, 2026
Report `RangesInDataPart::getRowsCount` instead of the rows of the whole part, the
same as `ReadFromMergeTree`: the text index may prune granules inside a part at
plan time, and then `read_rows` and the `READ_ROWS` quota must count only the
rows of the selected granules.

Addresses the review comment from ClickHouse#123294 (comment)

Renumber the test to 05371 because 05319 is taken on master, and pin the index
granularity, since the reported rows now depend on it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CurtizJ added a commit to CurtizJ/ClickHouse that referenced this pull request Oct 14, 2026
`TextIndexCountSource` emits one row per part, so auto progress counted one
read row per part. Report the rows of the answered part instead and set the
total rows approximation.

Extracted from ClickHouse#123294

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants