Skip to content

Use a page cache lookahead of one block for text index files read out of file order - #125770

Merged
CurtizJ merged 12 commits into
masterfrom
page-cache-adaptive-lookahead
Nov 4, 2026
Merged

CurtizJ merged 12 commits into
masterfrom
page-cache-adaptive-lookahead

Conversation

@antonio2368

@antonio2368 antonio2368 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

The text index reads its dictionary, postings and positions out of file order. On a page cache miss, CachedInMemoryReadBufferFromFile requests up to page_cache_lookahead_blocks blocks but fills only one, so the next seek abandons the request with data in flight. The remote connection then cannot be reused (S3: DiskConnectionsReset; distributed cache: the connection is dropped), so a text index search could open a new connection for almost every miss.

Query-time readers now open these streams with a lookahead of one block. The sparse index, the merge of text indexes and the column streams keep the normal lookahead. The new setting use_page_cache_lookahead_for_text_index restores it for the text index streams.

Changelog category (leave one):

  • Improvement

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

Text index searches through the userspace page cache no longer reset a remote connection on almost every cache miss: the text index files that are read out of file order now use a page cache lookahead of one block. The new setting use_page_cache_lookahead_for_text_index restores the normal lookahead.

🤖 Generated with Claude Code


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

Version info

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

…one block

The text index reads its dictionary blocks in the order of token cardinality,
and its postings and positions token by token, so the reads jump forward and
backward in the file. On a miss, `CachedInMemoryReadBufferFromFile` extends
the read limit of the underlying buffer over up to `page_cache_lookahead_blocks`
uncached blocks but fills only one, so for these files the next seek abandons
the request with data still in flight. The remote connection then cannot be
reused: an S3 HTTP connection is reset in `atConnectionDestroy`
(`DiskConnectionsReset`), and a distributed cache connection is dropped. A
text index search could open a new connection for almost every page cache
miss.

Open the dictionary, postings and positions streams of query-time readers
with a lookahead of one block. The sparse index, which is read from the
start, and the merge of text indexes, which reads sequentially, keep the
normal lookahead, and so do the column streams of the query. The new setting
`use_page_cache_lookahead_for_text_index` restores the normal lookahead for
the text index streams.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b1a5207]

Summary: ✅


AI Review

Summary

The PR limits userspace page cache lookahead to one block for query-time text index dictionary, postings, and positions streams, reducing abandoned remote requests. Sparse-index reads, index merges, and column streams retain normal lookahead; use_page_cache_lookahead_for_text_index restores it for the affected streams. No actionable findings remain. The earlier concerns about additional requests for long contiguous reads are an accepted tradeoff with an explicit setting to restore the previous behavior.

Missing context / blind spots
  • ⚠️ CI for b1a52073a2b729b4d8ccf23f67d316a1c87ecd9c is still running, and targeted integration jobs are pending. A passing test_text_index_lookahead run will confirm the latest fixture change that pins posting_list_codec = 'none'. No local build or tests were run during this review.
Final Verdict

✅ Approve — no code changes requested. Merge remains subject to completion of CI.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 14, 2026
The test runs `SYSTEM DROP PAGE CACHE`, which the style check requires to be
`no-parallel`. A page cache drop from another test would also change the
counts the test checks.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125770&sha=latest&name_0=PR
PR: #125770

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 14, 2026
The stateless servers in CI have no page cache: `page_cache_max_size`
is 0 by default, and `tests/config` does not set it. So
`05394_text_index_page_cache_lookahead_s3` read directly from S3, had no
`PageCacheMisses`, and failed in all flaky check jobs.

Check the same three queries in `test_userspace_page_cache`, whose server
already has an S3 disk and a page cache, and delete the stateless test.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125770&sha=latest&name_0=PR
PR: #125770

Co-Authored-By: Claude Opus 5.5 <[email protected]>
antonio2368 and others added 2 commits October 15, 2026 11:04
…search

`readAllPostingsForToken` reads every block of a token in file order, so with a
lookahead of one block each page cache miss became a separate remote request.
Its local stream now keeps the normal lookahead; the per-token cursor streams still
read one block at a time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nly patterns

`analyzeDictionaryForPatterns` reads dictionary blocks in ascending ranges, in file
order, so with a lookahead of one block each page cache miss became a separate remote
request. The dictionary stream now keeps the normal lookahead when the condition has
no search tokens; a condition with search tokens still reads one block at a time,
because `analyzeDictionaryForTokens` visits the blocks in token-cardinality order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b1a52073a with master 3b3f22da1 (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Compile time of recompiled translation units

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

Job report

…ex reads

Reverts the normal lookahead for the whole posting-list reads of phrase search
(`readAllPostingsForToken`) and for the dictionary of conditions with only patterns.
These reads are in file order, but each list or range is followed by a seek to an
unrelated offset, or the stream is dropped, so a longer lookahead abandons a request
with data in flight at the end of every list or range. The same change for the
exhaustive reads of `ReadFromTextIndexCount` gave one `DiskConnectionsReset` per token
in `test_text_index_lookahead`. With one block, only lists or ranges longer than one
page cost more requests, and those reuse the connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@rschu1ze rschu1ze left a comment

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.

CC: @CurtizJ

antonio2368 and others added 2 commits October 16, 2026 09:24
…akeTextIndexInputStream`

Each comment at a call site now gives only the reason for its value, with
the prefix `use_page_cache_lookahead: `. The mechanism is described once in
`TextIndexUtils.h` and `makeTextIndexReaderSettings`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@antonio2368
antonio2368 requested a review from rschu1ze October 23, 2026 08:41
@antonio2368

Copy link
Copy Markdown
Member Author

@CurtizJ could you please take a look. I know it seems a bit hacky, but a more complete solution would probably be setting exact ranges to read which is a bit more complex.
The issue is random jumps when reading from dictionary or postings which doesn't play well with lookahead reads into userspace page cache.

@CurtizJ CurtizJ self-assigned this Nov 2, 2026
Comment thread src/Core/Settings.cpp Resolved
antonio2368 and others added 2 commits November 2, 2026 15:59
…ndexInputStream`

The overload no longer assumes its caller is the index merge, which reads
every substream in file order. It now takes the same defaulted argument as
the part overload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CurtizJ
CurtizJ added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 3, 2026
antonio2368 and others added 2 commits November 3, 2026 14:27
#127489 changed the default of
`text_index_posting_list_codec` to `pfor`. The compressed postings take fewer
page cache blocks, so the default query had only 83 page cache misses and the
`misses >= 100` assertion failed in the merge queue. The test is about the
lookahead, not the codec, so keep the postings uncompressed.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=gh-readonly-queue/master/pr-125770-3b3f22da1d188310dfaf55af6b993fa8477e7bf4&sha=6ba1096d6fd295909fd5b518f171b6578c0ec2dc&name_0=MergeQueueCI
PR: #125770

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CurtizJ
CurtizJ added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit 7e74600 Nov 4, 2026
186 checks passed
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-improvement Pull request with some product 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.

4 participants