Skip to content

Restore prefetch for small files read from object storage - #108872

Merged
fm4v merged 10 commits into
masterfrom
nik/fix-s3-small-file-prefetch
Jul 2, 2026
Merged

fm4v merged 10 commits into
masterfrom
nik/fix-s3-small-file-prefetch

Conversation

@fm4v

@fm4v fm4v commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Problem

Reading many small files from object storage via the s3() / azureBlobStorage() / … table functions (and object-storage reads in general) stopped prefetching and fell back to synchronous, latency-bound reads. On a single-threaded / low-concurrency read of lots of tiny files this is a large regression: every file is fetched with a blocking round-trip instead of being prefetched while the previous one is processed.

It shows up clearly in ProfileEvents: RemoteFSPrefetches drops to 0, RemoteFSUnprefetchedReads and SynchronousRemoteReadWaitMicroseconds rise, and AsynchronousRemoteReadWaitMicroseconds disappears.

Root cause

In StorageObjectStorageSource::createReadBuffer, the initial "prefetch the first part of the file" is issued only for small objects (use_prefetch implies object_too_small). It was additionally gated on !impl->supportsReadAt():

if (use_prefetch && impl && !impl->supportsReadAt())
{
    impl->setReadUntilEnd();
    impl->prefetch(DEFAULT_PREFETCH_PRIORITY);
}

Once the read buffer learned readBigAt (parallel positioned reads) in #71781, supportsReadAt() became true, so this branch was skipped and the small-object prefetch was silently lost. readBigAt/parallel reading only helps large objects; a tiny file (≤ 2 * max_download_buffer_size) cannot be meaningfully split, so it ended up with neither prefetch nor parallelism and read synchronously.

git bisect points to the merge of #71781 (first bad build 26.2.1.1291, last good 26.2.1.1290); the regression is present through master.

Reproduction

-- Write 100 tiny files to object storage
INSERT INTO FUNCTION s3('http://localhost:11111/test/tiny/f_{_partition_id}.tsv', 'TSV')
PARTITION BY (a % 100)
SELECT number AS a, toString(number) AS b FROM numbers(400000)
SETTINGS s3_truncate_on_insert = 1;

-- Read them back single-threaded (FORMAT Null forces a real read of every file;
-- count() can be answered without reading data and would not exercise the read path)
SELECT * FROM s3('http://localhost:11111/test/tiny/f_*.tsv', 'TSV', 'a UInt64, b String')
FORMAT Null
SETTINGS max_threads = 1, remote_filesystem_read_method = 'threadpool',
         remote_filesystem_read_prefetch = 1, enable_filesystem_cache = 0;

SYSTEM FLUSH LOGS query_log;
SELECT ProfileEvents['RemoteFSPrefetches'],
       ProfileEvents['RemoteFSUnprefetchedReads'],
       ProfileEvents['AsynchronousRemoteReadWaitMicroseconds'],
       ProfileEvents['SynchronousRemoteReadWaitMicroseconds']
FROM system.query_log
WHERE query_kind = 'Select' AND type = 'QueryFinish' AND current_database = currentDatabase()
ORDER BY event_time_microseconds DESC LIMIT 1;

Reading the same 100 tiny files (max_threads = 1):

build RemoteFSPrefetches RemoteFSUnprefetchedReads async read wait sync read wait
before #71781 (e.g. 25.12) 100 0 present ~0
after #71781 (26.2 … master) 0 400 ~0 present
with this fix 100 0 present ~0

Large objects are unaffected (they never take the small-object prefetch path).

Performance impact

The reads become synchronous and latency-bound, so the slowdown scales with object-store round-trip latency and the number of small files per query.

  • Synthetic repro above (100 tiny files, max_threads = 1, low-latency local object storage): wall time ~0.30s → ~0.56s (~1.8×), RemoteFSPrefetches 100 → 0.
  • On real S3 (a network round-trip per request) the effect is much larger: a workload ingesting many small row-format files via INSERT ... SELECT FROM s3(...) saw single-query latency rise roughly 4–5× (e.g. ~3–4s → ~15–17s), turning steady-state ingestion into a continuously growing backlog.

Raising max_threads only partially compensates — it parallelizes the now-synchronous per-file reads but does not restore prefetching.

Fix

Restore the small-object prefetch and make it coexist with readBigAt:

  1. Issue the initial prefetch for small objects regardless of supportsReadAt() (removing the !impl->supportsReadAt() gate), on the non-cached read path.
  2. Teach AsynchronousBoundedReadBuffer::readBigAt to consume a pending prefetch instead of requiring there be none: if the requested range is covered by the prefetched buffer (the common case for a fully prefetched small file) it is served straight from memory — so small Parquet/ORC/Arrow files benefit from the single prefetch too; otherwise the prefetch is dropped and the read falls back to the underlying positioned read.
  3. Skip the initial prefetch when the filesystem cache is active — the cache manages its own read-ahead and segment ranges, so an extra prefetch over it is redundant and interferes with that handling.

Sequential formats (TSV/CSV/JSONEachRow/Native/…) consume the prefetch via the normal sequential path; large objects are unaffected.

Changelog category (leave one):

  • Performance Improvement

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

Fixed a performance regression (introduced in #71781) where reading many small files from object storage via the s3() and other table functions stopped prefetching and fell back to synchronous reads, significantly slowing single-threaded / low-concurrency reads of lots of tiny files.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.410 (included in 26.7 and later)
  • Backported to: 26.6.2.25, 26.5.6.12, 26.4.5.97, 26.3.17.19

…ions

The s3()/object-storage table-function read path skipped the small-object
initial prefetch whenever the read buffer supported readBigAt, because the
prefetch was gated on `!impl->supportsReadAt()`. After #71781 added readBigAt
to the fs-cache buffer, reads of many tiny files became synchronous and
latency-bound (e.g. low-concurrency s3() ingestion of lots of small files).

readBigAt/parallel reading only helps large objects; `use_prefetch` already
implies the object is small, so restore the prefetch for that case.

Adds a stateless regression test.
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fe3a464]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) FAIL
Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR restores the initial small-object prefetch for object-storage reads and teaches AsynchronousBoundedReadBuffer::readBigAt to reuse an in-flight prefetch so tiny s3()/object-storage files stop falling back to synchronous reads. The sequential regression is covered, but the random-access path is still not safe: readBigAt now mutates shared prefetch state without synchronization even though the SeekableReadBuffer contract allows concurrent readBigAt calls, so the PR is not ready.

Findings

❌ Blockers

  • [src/Disks/IO/AsynchronousBoundedReadBuffer.cpp:480] readBigAt still violates the SeekableReadBuffer contract by racing on prefetch_future and last_prefetch_info. The method is const, advertises supportsReadAt(), and the random-access readers touched by this PR do issue parallel positioned reads: for example Parquet::Prefetcher::scheduleTask runs multiple reader->readBigAt calls on io_runner, while ORC and Arrow also expose async positioned reads. Two tasks can both observe prefetch_future.valid(), then race through get() and reset on the same std::future; best case this throws std::future_error, worst case it is UB. Suggested fix: serialize the one-time prefetch handoff (for example with a mutex or a small state machine so exactly one caller consumes or cancels the pending prefetch before the rest delegate to impl), or make the initial-prefetch path unreachable for readers that may issue concurrent readBigAt calls.
Tests
  • ⚠️ The new stateless test covers the sequential TSV regression only. After fixing the race above, add a focused random-access regression (unit test or small Parquet/ORC case) that forces a pending small-object prefetch and then issues concurrent readBigAt calls, so this contract break cannot regress silently.
Final Verdict

❌ Changes requested — the sequential tiny-file regression is fixed, but the current readBigAt prefetch handoff is still unsafe for concurrent random-access readers.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 29, 2026
@fm4v
fm4v requested a review from kssenii June 29, 2026 22:38
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🔴 AI verdict: degradation — 2 query(s) regressed out of 38 analysed

This PR changes only the object-storage table-function read path (small-file prefetch on s3()/file() plus positioned reads for Parquet/ORC/Arrow); it does not touch the native MergeTree query execution that both ClickBench and TPC-H exercise. Because none of the flagged queries run through the changed code, the ClickBench regressions (Q30, Q31), the ClickBench Q34 improvement, and the TPC-H Q8/Q16 deltas are downgraded as run-to-run variance rather than PR effects. The two TPC-H regressions Q4 (+224%) and Q7 (+783%) are large enough to stand under the hard trust rule, but they are also off-path and Q7's baseline was very noisy (71 ms median), so both should be re-checked manually before treating them as real.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 30 not_sure 240 277 +15.4% <0.0001 PR only changes object-storage table-function reads; ClickBench uses native MergeTree. Off-path, run-to-run variance.
⚠️ 31 not_sure 308 356 +15.4% <0.0001 Same off-path story as Q30: PR touches only s3()/file() small-file prefetch, not the native MergeTree path this runs.
⚠️ 34 not_sure 1455 1376 -5.4% 0.0029 Improvement off-path: PR changes only object-storage read prefetch, not the native MergeTree path Q34 executes.

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 regressed · ⚠️ 2 inconclusive

Flagged queries (4 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🔴 4 regression 326 1057 +224.2% <0.0001 io: Large delta held by hard trust rule, but PR touches only object-storage reads, not this TPC-H path; verify manually.
🔴 7 regression 71 627 +783.1% <0.0001 io: Held by hard trust rule; base was extremely noisy (71ms median) and PR is off-path, so verify before acting.
⚠️ 8 not_sure 168 210 +25.0% <0.0001 Off-path: PR changes object-storage table-function reads; TPC-H uses native tables. Run-to-run variance.
⚠️ 16 not_sure 100 50 -50.0% <0.0001 Off-path improvement; base measurements noisy. PR touches only object-storage reads, not this TPC-H path.

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: 53d6285d-d3c4-4e64-85f8-0abdbbeb1d93
  • MIRAI run: d637f292-41ae-42eb-b684-930ee94d8967
  • PR check IDs:
    • clickbench_625644_1782916422
    • clickbench_625651_1782916422
    • clickbench_625661_1782916422
    • tpch_adapted_1_official_625668_1782916422
    • tpch_adapted_1_official_625681_1782916422
    • tpch_adapted_1_official_625691_1782916422

fm4v added 2 commits June 30, 2026 11:46
Addresses review: the previous change issued the small-object initial prefetch
unconditionally, which tripped AsynchronousBoundedReadBuffer::readBigAt's
chassert(!prefetch_future.valid()) for small Parquet/ORC/Arrow files read via the
s3() table function, aborting the server.

Gate the prefetch on the format's access pattern instead of the buffer's
supportsReadAt() capability: random-access formats (which use readBigAt) skip the
prefetch; sequential formats (TSV/CSV/JSONEachRow/Native/...) get it back. Adds
FormatFactory::checkIfFormatHasRandomAccessInputCreator.
@kssenii kssenii self-assigned this Jun 30, 2026
Comment on lines +1286 to +1292
/// But only issue it for formats that read the object sequentially. Random-access formats
/// (Parquet/ORC/Arrow) probe `supportsReadAt()` and read via `readBigAt`, which must not run
/// while an initial prefetch is in flight (see AsynchronousBoundedReadBuffer::readBigAt).
/// Gate on the format's access pattern, not on the buffer's `supportsReadAt()` capability:
/// after the buffer learned `readBigAt`, gating on the capability disabled the prefetch for
/// sequential formats too (e.g. many tiny files via the s3() table function), making them
/// fall back to synchronous, latency-bound reads.

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.

May be a better way is to just support reading from prefetched buffer from readBigAt?
Since we prefetch only small files then readBigAt must read everything in a single read, so we can as well just copy what we have in prefetch into readBigAt memory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea — done in 49f4c07. Reverted the format-based gate and instead made AsynchronousBoundedReadBuffer::readBigAt consume a pending small-object prefetch: it serves the requested range straight from the prefetched buffer when it is covered (the common case for a fully prefetched small file), and otherwise drops the prefetch and falls back to impl->readBigAt. This keeps the unconditional small-object prefetch (so small Parquet/ORC/Arrow now benefit too) and removes the FormatFactory coupling.

I kept a coverage check + fallback rather than assuming full coverage: object_too_small allows objects up to 2 * max_download_buffer_size while the prefetch reads buffer_size bytes, so a small-but-not-tiny object may be only partially prefetched.

Per review (@kssenii): instead of gating the small-object prefetch by format,
keep prefetching all small objects and teach AsynchronousBoundedReadBuffer::
readBigAt to consume a pending prefetch - serve the requested range from the
prefetched buffer when it is covered (the common case for a fully prefetched
small file), otherwise drop the prefetch and fall back to a positioned read.

This also extends the prefetch benefit to small Parquet/ORC/Arrow files and
removes the FormatFactory coupling added in the previous revision.
/// readBigAt() and the sequential prefetch must not run against impl concurrently, so consume the
/// prefetch first: serve the requested range straight from the prefetched buffer when it is covered
/// (the common case for a fully prefetched small file), otherwise drop the prefetch and read directly.
if (prefetch_future.valid())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

readBigAt must remain safe for concurrent positioned reads, but this branch mutates prefetch_future and last_prefetch_info without synchronization. That is reachable in the current object-storage path: createReadBuffer starts the small-object prefetch for object_size <= 2 * max_download_buffer_size, while FormatFactory::wrapReadBufferIfNeeded can wrap the same buffer in ParallelReadBuffer for file_size >= 2 * max_download_buffer_size; at the equality boundary ParallelReadBuffer launches multiple workers that call input.readBigAt concurrently. Two workers can race on prefetch_future.valid / get / reset, which violates the SeekableReadBuffer contract and can surface as undefined behavior or std::future_error. Please either serialize the pending-prefetch handoff (for example, guard the future so exactly one readBigAt consumes it before the rest delegate to impl) or make the initial-prefetch and parallel/read-at paths non-overlapping.

fm4v added 2 commits June 30, 2026 18:29
- 04000: read with SELECT * FORMAT Null instead of count() (count() can be
  answered without reading the data via optimize_count_from_files and would
  not exercise the prefetch path).
- gtest_readbuffer_s3 HavingZeroBytes: disable remote_filesystem_read_prefetch
  so createReadBuffer() does not inject an automatic initial prefetch, which
  would change the manual prefetch/seek sequence the test asserts.
…ctive

The filesystem cache manages its own read-ahead and segment ranges, so issuing
an extra initial prefetch over a cached buffer is redundant and interferes with
it (this is what gtest_readbuffer_s3 HavingZeroBytes characterizes). Gate the
prefetch on !use_filesystem_cache; the non-cached s3()/object-storage read path
(the regression) still gets it. Reverts the previous gtest workaround.
@fm4v fm4v changed the title Fix lost prefetch for small files read via object storage table functions Restore prefetch for small files read from object storage Jul 1, 2026
SYSTEM FLUSH LOGS query_log;

-- Expect at least one prefetch per small file (> 0). Before the fix this was 0 (synchronous reads).
SELECT ProfileEvents['RemoteFSPrefetches'] > 0

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.

Better to also check RemoteFSPrefetchedReads -- to check that we actually read from prefetch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done — the test now also asserts RemoteFSPrefetchedReads > 0, so it verifies the prefetch is actually consumed, not just issued.

const size_t prefetch_end = result.file_offset_of_buffer_end;
const size_t prefetch_begin = prefetch_end - prefetched_bytes;

if (prefetched_bytes != 0 && range_begin >= prefetch_begin && range_begin + n <= prefetch_end)

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.

There is a case that n can be bigger than prefetched_bytes but prefetched data is still inside the requested range. If missing part is just tail range from already prefetched buffer, then we can copy prefetched buffer as whole and just make one more request for the missing suffix of the range.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point — handled in 686a95a. When the prefetch covers the head of the requested range but not all of it, readBigAt now copies the covered prefix from the prefetched buffer and reads only the missing suffix via impl->readBigAt (with the progress callback offset by the prefix length so it stays cumulative over the whole range), instead of dropping the prefetch entirely.

…onsumed

- readBigAt: when the prefetch covers the head of the requested range but not
  all of it, copy the covered prefix from the prefetched buffer and read only
  the missing suffix via impl->readBigAt (offsetting the progress callback so
  it stays cumulative over the whole range), instead of dropping the prefetch.
- 04000 test: also assert RemoteFSPrefetchedReads > 0 to confirm the prefetch
  is actually consumed, not just issued.
Comment on lines +513 to +514
if (!impl->supportsReadAt())
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method readBigAt() is not implemented for a given implementation");

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 move this to the beginning of readBigAt, this is more like a general correctness check, we cannot avoid it for prefetch case

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 79c20f9 — moved the supportsReadAt() check to the top of readBigAt as a general precondition.

if (progress_callback)
progress_callback(n);
return n;
suffix_progress = [&](size_t copied) { return progress_callback(from_prefetch + copied); };

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.

Why do we need to add from_prefetch to progress? Was it not added in line 509?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The value passed to progress_callback is cumulative, not incremental (see copyFromIStreamWithProgressCallback, and ParallelReadBuffer::on_progress ignores non-increasing values). impl->readBigAt for the suffix reports cumulative bytes relative to its own request (0 … suffix), so without the shift the caller would see the value drop back below the prefix already served. Adding from_prefetch keeps it cumulative/monotonic over the whole range.

I also removed the separate prefix progress_callback(from_prefetch) call (79c20f9), so now progress is reported only via the shifted suffix callback — no double counting.

- Move the supportsReadAt() correctness check to the top of readBigAt (it is a
  general precondition, needed for the prefetch path too).
- Drop the separate prefix progress_callback call; only the suffix reports
  progress, shifted by the served prefix so the reported value stays cumulative
  and monotonic over the whole range.
The filesystem cache stage is only added when the object has an etag; without it
we build a plain remote reader. Clear use_filesystem_cache in that branch so the
flag reflects whether the cache stage was actually added. Otherwise the initial
small-object prefetch guard (!use_filesystem_cache) would wrongly stay suppressed
for the enable_filesystem_cache=1 + missing-etag case, reintroducing the
synchronous tiny-file read path.

@kssenii kssenii 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.

LGTM, but will be good to fix above bot's comment

The fixture writes exactly 16 tiny files and the query reads all of them, so each
must regain the initial prefetch. Assert RemoteFSPrefetches >= 16 and
RemoteFSPrefetchedReads >= 16 instead of > 0, so a partial regression that
prefetched only some files would still be caught.
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.50% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.70% +0.00%

Changed lines: Changed C/C++ lines covered: 38/43 (88.37%) · Uncovered code

Full report · Diff report

@fm4v
fm4v added this pull request to the merge queue Jul 2, 2026
Merged via the queue into master with commit 4a2d03b Jul 2, 2026
174 of 176 checks passed
@fm4v
fm4v deleted the nik/fix-s3-small-file-prefetch branch July 2, 2026 06:22
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 2, 2026
fm4v added a commit that referenced this pull request Jul 2, 2026
Cherry pick #108872 to 26.3: Restore prefetch for small files read from object storage
fm4v added a commit that referenced this pull request Jul 2, 2026
Cherry pick #108872 to 26.4: Restore prefetch for small files read from object storage
fm4v added a commit that referenced this pull request Jul 2, 2026
Cherry pick #108872 to 26.5: Restore prefetch for small files read from object storage
robot-clickhouse added a commit that referenced this pull request Jul 2, 2026
robot-clickhouse added a commit that referenced this pull request Jul 2, 2026
robot-clickhouse added a commit that referenced this pull request Jul 2, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 2, 2026
fm4v added a commit that referenced this pull request Jul 2, 2026
Backport #108872 to 26.4: Restore prefetch for small files read from object storage
fm4v added a commit that referenced this pull request Jul 2, 2026
Backport #108872 to 26.5: Restore prefetch for small files read from object storage
grantholly-clickhouse added a commit that referenced this pull request Jul 2, 2026
Backport #108872 to 26.3: Restore prefetch for small files read from object storage
clickhouse-gh Bot pushed a commit that referenced this pull request Jul 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 2, 2026
Backport #108872 to 26.6: Restore prefetch for small files read from object storage
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Jul 6, 2026
Follow-up to ClickHouse#108872: the restored small-object prefetch was gated on
`!use_filesystem_cache`, but reads via object storage table engines go
through the filesystem cache when `filesystem_cache_name` is set (the
ClickHouse Cloud configuration). The cache does no read-ahead of its own
and fresh files (e.g. `S3Queue` ingestion) are always cache misses, so
every small file still cost a synchronous, latency-bound round trip to
object storage: `RemoteFSPrefetches` stayed 0 and insert latency stayed
~4-5x higher than on 25.12, where the prefetch was issued over the
cached buffer.

The gate existed only to keep the exact read/seek sequence asserted by
`gtest_readbuffer_s3.HavingZeroBytes` stable; restore the test-side
workaround (disable `remote_filesystem_read_prefetch` in that test)
instead of disabling the prefetch in production code.

ClickHouse/support-escalation#8093
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-file-prefetch

Restore prefetch for small files read from object storage
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Follow-up to ClickHouse#108872: the restored small-object prefetch was gated on
`!use_filesystem_cache`, but reads via object storage table engines go
through the filesystem cache when `filesystem_cache_name` is set (the
ClickHouse Cloud configuration). The cache does no read-ahead of its own
and fresh files (e.g. `S3Queue` ingestion) are always cache misses, so
every small file still cost a synchronous, latency-bound round trip to
object storage: `RemoteFSPrefetches` stayed 0 and insert latency stayed
~4-5x higher than on 25.12, where the prefetch was issued over the
cached buffer.

The gate existed only to keep the exact read/seek sequence asserted by
`gtest_readbuffer_s3.HavingZeroBytes` stable; restore the test-side
workaround (disable `remote_filesystem_read_prefetch` in that test)
instead of disabling the prefetch in production code.

ClickHouse/support-escalation#8093
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants