Skip to content

Bound the fetches of the experimental ReaderExecutor by the request map, not by read_until - #125606

Merged
CheSema merged 20 commits into
masterfrom
reader-executor-fetch-bound
Nov 13, 2026
Merged

CheSema merged 20 commits into
masterfrom
reader-executor-fetch-bound

Conversation

@CheSema

@CheSema CheSema commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

The experimental ReaderExecutor capped each fetch at read_until, the end of the current task. Now read_until limits only what is served. A fetch is bounded by the window and by the request map from #122250: it stops at the end of the map run that holds the position, and reads through holes up to reader_executor_min_bytes_for_seek. A held GET ends there too. A fetch that ends inside a filesystem cache segment continues to the bytes that the map still wants in that segment, because the segment fills only from its committed front.

New counter ReaderExecutorBytesOutsideRequestMap. Known limit: the map is per part, so readers that share a split part can fetch past their share; a per-reader map comes later.

Related: #122250
Related: #115816

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

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

…read_until`

`read_until` now limits only what a window serves. A fetch stops at the end of the
request-map run (holes up to `reader_executor_min_bytes_for_seek` are read through),
and so does a held GET. Adds `ReaderExecutorBytesOutsideRequestMap`.
…em cache segment

The segment fills only from its committed front, so the hole is read in any case;
reading it in the same fetch saves a request.
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a68db8]

Summary: ✅


AI Review

Summary

The PR bounds experimental ReaderExecutor fetches by request-map runs, separates fetching from the read_until serve bound, and continues held GETs across their old bounds. Reviewing head 4a68db886878f85c44e9039922af95534fd1ee90 leaves one previously reported performance regression below. No genuinely new inline findings were identified.

Missing context / blind spots
  • ⚠️ No local ClickHouse build or executable was available; regression tests were inspected but not executed locally.
  • ⚠️ The Cloud-only multi-buffer reader referenced by the latest 04327 change is absent from this checkout. A source-byte comparison for Compact column reads in Cloud would establish the cost hidden by changing this fixture to Wide parts.
Findings

❌ Blockers

  • src/IO/ReaderExecutor.cpp:788–800 — Bounded callers without a request map now fetch unrelated bytes. [dismissed by author -- https://github.com/Bound the fetches of the experimental ReaderExecutor by the request map, not by read_until #125606#discussion_r4538456785] The author deferred migrating these callers to a follow-up; the regression remains when use_reader_executor is enabled. Parquet::Prefetcher::readImpl and Iceberg::readIcebergDeletionVector still supply only setReadUntilPosition. Without a map, requestRunEnd returns the file end, so max_fetch ignores that bound. With default sizes and no caches or held connections, three isolated 64 KiB reads at offsets 0, 32 MiB, and 64 MiB in a 128 MiB file fetch 24 MiB instead of 192 KiB, with the same three requests. Distant seeks or destruction discard the extra bytes. Preserve the fetch bound for unmapped callers, or migrate the affected bounded-read callers in this change.
Tests
  • ⚠️ Add a focused regression asserting source bytes for sparse bounded reads without a map, including destruction after a single bounded read. The current tests establish that extra bytes can be reused, but do not protect callers that discard them.
Final Verdict

Status: ❌ Block — preserve bounded I/O for existing unmapped callers and cover the sparse/discarded-read case. The dismissed thread was neither reopened nor replied to; no duplicate inline review was posted.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. labels Oct 13, 2026
Comment thread src/IO/ReaderExecutor.cpp Resolved
Without caches, the plan keeps the window's unserved bytes in memory,
so the separate no-cache path is not needed.
@CheSema
CheSema marked this pull request as ready for review October 13, 2026 12:19
Comment thread src/IO/ReaderExecutor.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a68db886 with master c65bdd819 (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.58, programs/clickhouse-keeper ×0.61 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.7 s 10.3 s +6.9 s (+207%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.1 s +5.1 s (+258%)
Compile time of recompiled translation units

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

Job report

Comment thread src/IO/ReaderExecutor.cpp Resolved
Comment thread src/IO/ReaderExecutor.cpp Resolved
Comment thread src/IO/ByteRangeSet.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. and removed comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. labels Oct 15, 2026
Comment thread src/IO/ReaderExecutor.cpp Resolved
@PedroTadim

Copy link
Copy Markdown
Member

I found an issue with use_reader_executor on tests randomization. AI says this PR is the fix. Can you add this test case in the PR?

The table is on the s3 policy of tests/config/config.d/s3_storage_policy_by_default.xml (a cache disk over S3; MinIO is enough). It fails on every run, from a single query, with a cold or a warm cache:

CREATE TABLE gap (k UInt64, v UInt64) ENGINE = MergeTree ORDER BY k
SETTINGS storage_policy = 's3', min_bytes_for_wide_part = 0;
INSERT INTO gap SELECT number, cityHash64(number) FROM numbers(1000000);

SELECT sum(v) FROM gap WHERE k < 20000 OR k > 900000
SETTINGS use_reader_executor = 1, reader_executor_use_long_connections = 1,
    reader_executor_window_size = 131072, remote_filesystem_read_method = 'read';
Code: 33. DB::Exception: ReaderExecutor: source ended at 7174271 of 8034571 bytes for data/kqt/...: While reading or decompressing ... (CANNOT_READ_ALL_DATA)

It returns the right sum (6709815352311253830) without reader_executor_use_long_connections, without the filesystem cache, or with the legacy read path.

PedroTadim added a commit that referenced this pull request Oct 15, 2026
With it on, two bugs fail tests:
- `use_reader_executor` with `local_filesystem_read_method = 'mmap'` reads stale bytes of a
  rewritten same-size local file (`05055_backup_lock_file_non_atomic_backend`); fix in
  #113617.
- `reader_executor_use_long_connections` sizes the held GET from the read position but opens it
  at the fetch start, so a fetch from a cache segment's committed front ends before the position:
  `ReaderExecutor: source ended` (`04513`, `05182`); fixed by
  #125606.
`reader_executor_use_long_connections` and its dependency on `use_reader_executor` go with it.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/IO/ReadPlan.h Resolved
Comment thread src/IO/ReadPlan.h Resolved
Comment thread src/IO/ByteRangeSet.h Resolved
Comment thread src/IO/ReaderExecutor.cpp Resolved
Comment thread src/IO/ReaderExecutor.cpp Resolved
Comment thread src/IO/ReaderExecutor.cpp Resolved
A column stream of a Compact part (the multi-buffer reader on object storage) gets a request map that spans the chunks of the other columns, so `DeliveredBytes` is less than `BytesFromSource`. The `reader_executor_min_bytes_for_seek = 0` workaround did not address it.
@CheSema
CheSema added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit 06eaf9d Nov 13, 2026
204 checks passed
@CheSema
CheSema deleted the reader-executor-fetch-bound branch November 13, 2026 19:34
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-not-for-changelog This PR should not be mentioned in the changelog 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