Skip to content

Text index: fill posting lists folded at analysis once per read - #122896

Merged
ahmadov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai-text-index-fill-folded-once-per-read
Oct 16, 2026
Merged

ahmadov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai-text-index-fill-folded-once-per-read

Conversation

@groeneai

@groeneai groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122557
Related: #122597

Changelog category (leave one):

  • Performance Improvement

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

Text index direct read is faster for token searches whose tokens each match at most text_index_posting_list_block_size rows in a part (with the defaults, every token search on parts of up to about one million rows), outside the lazy posting list apply mode: the result column is filled once for all rows of a read from the posting list built during the index analysis, instead of once per granule.

Description

When the index analysis has read the whole posting list of every token of a search (each list is one block), the text index reader still clipped that per-part list to every granule, flattened and scattered it, although one read covers a run of granules. Such columns are now skipped in the per-granule loop and filled once per read. The lazy mode, the default for compressed posting lists, keeps its cursor over the flattened postings. Multi-block tokens, phrase and fallback searches keep the current code. The new profile event TextIndexFilledFromFoldedPostings counts the fills. Based on the analysis and patch by @ snelheidai.

On x86 release builds, against an A/A control, searches on 8192-row granules run 3-7% faster at one thread with 32-63% less text index read time, and index-bound reads of a 10M-row part 22-38% faster. On 1M-row granules a read is one granule, so the work is unchanged; unchanged paths stay within the noise. Peak memory grows by up to 0.75 MiB at four threads on 8192-row granules (the row id buffer now spans a read), and not at one thread.

A new test compares with evaluation without the index (dense and sparse tokens, reads of one granule and of many, reverse order, several parts, lazy mode, arrays, a multi-block control) and checks the event; a sweep of 1386 predicate and setting combinations over three codecs matched master.

A window-wise bit expansion on top (the posted patch's fill) cut up to another 47% of read time and about 4 MiB at four threads on 1M-row granules, but was 4-13% slower where a token matches about 8% of rows and up to 54% slower to read isolated granules, so it is not included.

Independent of #122597: the two change disjoint paths.

Measurements

Crossover effect FIX/BASE over 20 paired rounds, postings cache off; "within" = inside the A/A noise.

query wall, 1 / 4 threads index read, 1 / 4 threads
count(), sum(ts), hasToken(msg, 'ERROR') (25%), 11 parts of 1.8M rows, 8192-row granules -5.9% / -5.3% -37% / -37%
hourly count(), same search -5.9% / -5.7% -38% / -37%
hourly count(), hasAnyTokens(msg, ['timeout', 'ERROR']) -5.0% / within -41% / -41%
hasToken(msg, 'panic') (0.1%) -6.3% / within -59% / -57%
one 20M-row part, hasToken(msg, 'timeout') (5%) -4.9% / within -63% / -36%
one 10M-row part, count() without the count optimization, hasAnyTokens over 8% of rows -38% / -11% -75% / -66%
5 isolated granules within -14% / -13%
1M-row granules within 4% (instructions -0.2%) -1..-9%
multi-block and mixed tokens, count from the index, no index within (instructions within 0.1%) within

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.81-master (included in 26.11 and later)

groeneai and others added 3 commits September 29, 2026 12:11
A text index virtual column whose tokens the index analysis folded completely
(every posting list is one block) is now skipped in the per-mark loop of
`readRows` and filled once for all rows of the read from the folded postings,
in both `materialize` and `lazy` modes. The `lazy` direct fill from folded
postings becomes unreachable and is removed. The new ProfileEvent
`TextIndexFilledFromFoldedPostings` counts these fills.

Based on the analysis and patch by @ snelheidai, ClickHouse#122557 (issuecomment-5887340898).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The stateless test compares direct read with evaluation without the index
over single-block posting lists: dense and sparse tokens, reads of one
granule and of many, reverse order, several parts, lazy mode, arrays and a
multi-block control, and checks `TextIndexFilledFromFoldedPostings` so the
new path is known to run. The performance test covers dense, sparse and
`pfor` searches on parts of about 910000 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove three comments that restate the code or the getFoldedPostings contract, and the duplicate pointer in buildPostingsForMark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Sep 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits).

# Sev Finding Verdict Evidence / action
1 💡 The test header mentions 65536-row ranges, which only a window-wise fill would care about AGREE, not blocking The shapes stay valid correctness cases; no change
2 💡 The performance test queries take 4-6 ms AGREE, not blocking perf.py gives queries under 20 ms up to 30 runs; the test reaches the new path (159 fills per query)
3 💡 buildPostingsForMark still runs per granule when every column is filled once per read AGREE, not blocking Constant per granule; no measured regression

Severity: 💡 nit.

Session id: cron:clickhouse-review-slot-9:20260929-134300

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63c3809]

Summary: ✅


AI Review

Summary

This PR fills text-index virtual columns once per contiguous read when the analyzer has fully folded the required posting lists, while preserving the existing lazy, phrase, and fallback paths. The current diff has no actionable findings; the reported measurements support the performance claim.

Missing context / blind spots
  • ⚠️ CI for head 63c38099c5d5f5199c4f8090c8ee92e3a57d696a is pending. The focused stateless test passed 50 runs on preceding revision 51a5866c37b313aa0ea8901a29469e6edea8404a; current-head CI still needs to confirm the revised lazy-mode expectation. No local build or tests were run.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI requirements still apply.

@groeneai
groeneai requested review from CurtizJ and ahmadov September 29, 2026 14:35
@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 29, 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 Sep 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 63c38099c5d5f5199c4f8090c8ee92e3a57d696a was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR changes only the text index reader: when the posting lists folded during index analysis fully answer the search, it fills the virtual column for all rows of a read at once, instead of building posting lists for every granule. It also adds a profile event and new tests. None of the five flagged improvements (ClickBench Q18, Q33, Q34 and TPC-H Q1, Q7, between -10.5% and -21.8%) touch a text index, every PR median is inside master's recent range, and all five queries are historically noisy, so all five are downgraded to not sure. The benefit this PR targets should show up in the new text_index_single_block_postings performance test, not in ClickBench or TPC-H.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 18 not_sure 891 798 -10.5% <0.0001 This PR changes only the text index reader, and the ClickBench table has no text index, so this query never runs the changed code. The -10.5% sits inside master's recent range for this noisy query.
⚠️ 33 not_sure 1153 993 -13.9% <0.0001 Q33 is a GROUP BY over a table with no text index, so the changed reader code is never used. The -13.9% is inside master's recent range for this noisy query.
⚠️ 34 not_sure 1136 997 -12.2% <0.0001 Q34 is a GROUP BY like Q33 and does not read through a text index. The -12.2% matches the shift on Q33 and is inside master's recent range.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 64 52 -18.8% <0.0001 TPC-H tables have no text indexes, so this change cannot affect Q1. The -18.8% is a 12 ms shift on a noisy query and stays inside master's recent range.
⚠️ 7 not_sure 78 61 -21.8% <0.0001 Q7 joins tables that have no text index, so the changed reader is never used. The -21.8% is a 17 ms shift and stays inside master's recent range.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 976f1138-37b5-4c99-9928-e0a94e89c4bf
  • MIRAI run: 0bf2db0a-273d-4d7c-b96f-119ad13b896f
  • PR check IDs:
    • clickbench_951249_1791761850
    • clickbench_951262_1791761849
    • clickbench_951268_1791761850
    • tpch_adapted_1_official_951278_1791761850
    • tpch_adapted_1_official_951285_1791761849
    • tpch_adapted_1_official_951319_1791761849

@ahmadov ahmadov self-assigned this Sep 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b6660aa

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_llvm_coverage, 1/8) / test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds master-side: since #122681 a read decodes manifest bounds only for the columns its filter uses, so the log line the assertion at line 337 waits for is never written. It failed on every true-master run from 2026-09-29 10:59Z until the fix merged, and on 66 pull requests today. This PR changes only the text index reader #122895 (mine, merged 16:58Z), absent from the tree this run built, merged master @ 1335efa
Mergeable Check, PR rollups, red only because of the row above #122895 (mine, merged)

146 of 149 check runs passed or were not selected, Finish Workflow is green and CH Inc sync passed. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20260929-183205

# Conflicts:
#	src/Common/ProfileEvents.cpp
#	src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp
#	src/Storages/MergeTree/MergeTreeReaderTextIndex.h
@@ -0,0 +1,41 @@
<test>
<settings>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use substitutions to get rid of duplication.

<substitutions>
        <substitution>
           <name>codec</name>
           <values>
               <value>none</value>
               <value>pfor</value>
           </values>
        </substitution>
    </substitutions>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 63c3809: both tables now come from one codec substitution.

@@ -0,0 +1,188 @@
-- { echo }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not echo the whole SQL queries into the reference. Instead group relevant SELECT queries under a title by SELECT '....'; Keep the titles brief and short.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 63c3809: the queries are no longer echoed, and the results are grouped under short SELECT '...' titles.


const PostingList * MergeTreeReaderTextIndex::getFoldedPostings(size_t column_idx) const
{
if (is_always_true[column_idx] || use_fallback[column_idx])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add check for use_lazy_mode here as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 63c3809: lazy mode keeps its cursor path for folded postings, and the test now expects the new profile event to stay 0 there (so the pfor arm of the perf test, lazy by default, is an unchanged control).

Lazy mode fills a fully folded column from the cursor over the flattened
postings, shared by the readers of the granule, so the fill once per read
now applies outside lazy mode only. The perf test runs both codecs through
a substitution, and the stateless test prints short titles instead of
echoing the queries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ahmadov
ahmadov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 7c3b66d Oct 16, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 27, 2026
…-intersect-per-container

Master builds `range_posting` lazily in `buildPostingsForMark` and skips
columns answered by the analyzer's folded postings (ClickHouse#122896); the
per-container path only runs when postings must still be read, so it is
disjoint from the folded one. `setIndexGranule` keeps only the reset of
`intersection_steps`: master moved the per-granule phrase results into
`phrase_streams` (ClickHouse#118885) and dropped `blocked_positions_scratch`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rorylshanks added a commit to rorylshanks/ClickHouse that referenced this pull request Nov 3, 2026
…n they need validation

`getFoldedPostings`, added on `master` by ClickHouse#122896, fills a virtual column
from the postings folded during index analysis. It did not know two
properties of `jsonPathValues` queries:

- A prefix lookup (`startsWith`, `LIKE 'abc%'`, key existence) has
  neither tokens nor patterns: its tokens are collected from the
  dictionary by `pattern_token_prefixes`. Such a query was answered with
  empty postings, so it matched no row.
- A query with dynamic fallback (e.g. `endsWith` over truncated values)
  has folded postings that also hold the candidate rows that still have
  to be validated on the column. They were taken as the result, so
  unvalidated rows matched.

Check `hasPatternLookup` as `classifyVirtualColumns` and
`buildPostingsForMark` already do, and do not use folded postings for
columns with dynamic fallback. Fixes the `Fast test` failures of
`04839_json_path_values_core`, `04840_json_path_values_dynamic`,
`04841_json_path_values_patterns`, `04842_json_path_values_collections`,
`04856_json_path_values_subcolumns` and
`04866_json_path_values_regressions`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114613&sha=df313397ce1ec1fa96b1c82f0ad3e87768aed83b&name_0=PR&name_1=Fast%20test
ClickHouse#114613

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... groeneai-origin-issue PR origin: picked up an external GitHub issue pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants