Repository navigation
Conversation
…b from object storage A source opens its next object only after the previous one, and the Parquet reader reads an object's footer on its first `read()`, so a query over many objects waits for one footer request after another in every stream (100 objects over 4 streams = 25 serial round trips per stream, even for `count()` or a statistics-pruned filter). The asynchronous creation of the next reader does not help: it does not read the footer, and it starts only when the previous reader is taken. `createIteratorWithParquetFooterPrefetch` wraps the `GlobIterator` of a plain glob over a remote object storage. It hands out the same objects in the same order and reads the footers of the next few objects on the IO thread pool. Nothing is read ahead while the streams take their first two objects each (so `LIMIT 1` reads nothing extra); then the depth grows by 4 per object up to `clamp(4 * num_streams, 16, 32)`, which is also the number of reads in flight per query. Each read does exactly what the reader of that object would do, only earlier: with the metadata cache it calls the same `ParquetMetadataCache::getOrSetMetadata` with the same key and load, so the cross-query single flight, the SLRU admission and the hit/miss events are unchanged (counted in the query's thread group). The result is attached to the `ObjectInfo` as a `ParquetPrefetchedFooter` and handed to the reader through `IInputFormat::setPrefetchedFooter`; the reader does no cache access of its own then. Handing it over through the cache instead would make two accesses per object, and SLRU promotes an entry on its first hit, so every footer read once by a scan would land in the protected segment. If the read has not started when the reader needs the footer, the reader cancels it and reads the footer itself; if it is running, the reader waits for it. An error of the read is rethrown by the reader that takes it; the read runs under `SuppressErrorCodesScope`, so a failed read of an object nobody opens does not appear in `system.errors`. Objects whose footer is not needed are skipped: archives, compressed objects, objects not larger than the remote read buffer (read whole), objects without a usable ETag, objects already in the metadata cache, objects with a valid cached row count for a count-only read, and objects with a query condition cache entry. The probes of those caches are new non-mutating `contains`-style lookups (`SchemaCache::hasValidNumRows`, `QueryConditionCache::contains`), so they neither reorder nor invalidate entries nor count lookups. The row-count cache key is computed by one helper (`getKeyForNumRowsCache`) for the source and the prefetch. Key lists, data lakes, archives, `*Cluster` reads, local object storage, `_headers` and non-seekable reads (`input_format_allow_seeks = 0`) keep the old path. The read-ahead is turned off by the existing `remote_filesystem_read_prefetch`. Analysis and the original patch: issue ClickHouse#124671. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pass the structure, so that no query infers the schema: a schema cache entry registered in the same second as the objects were written is invalid, and the next query reads a footer more. Do not check that footers were read ahead: the failpoint is global, so a parallel run of the test can turn the read-ahead off for this one, or on for its rejected run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It enables a failpoint, so the style check requires `no-parallel`. Running alone, no other run can change the failpoint for it, so check again that footers are read ahead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds nothing ahead Drop the failpoint test arm, so the test runs in parallel; check that `LIMIT 1` schedules no footer read, with the new `ParquetFooterPrefetchRequests`. Also turn the page cache off in the measured queries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…replicas are enabled, and read the footer through the shared helper in the bucket splitter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ads, so the query does not wait forever for a read that never runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d iterator is destroyed The destructor waited for every queued footer read, so when the IO pool did not run them (after a reload of `max_io_thread_pool_size` to 0, or while a busy pool kept them queued) the query's teardown waited for them. It now waits only for reads that have started; a queued read checks that the iterator is still alive before it starts, and references the query's resources weakly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove two comments that only restate the function name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 5 rounds, 7 findings) plus my own review. The last round, on bdf29bd, found nothing.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261009-134800 |
|
Workflow [PR], commit [f5f9f9f] Summary: ❌
AI ReviewSummaryThe PR adds bounded background footer reads for Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline comments or thread changes are needed. |
…ed generation The footer read ahead and the later data read are separate requests. Without `s3_validate_etag_on_read` / `azure_validate_etag_on_read` neither is pinned to the ETag seen at listing time, so an in-place overwrite between them could pair a footer of one generation with data of another. Use the same predicate as the lazy materialization reread, now shared in `isReadPinnedToObjectGeneration`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR reads Parquet footers ahead of time for multi-file glob reads from S3/Azure object storage. All the other changes are refactors or read-only cache lookups that only that new prefetch path uses, and neither ClickBench nor TPC-H runs it, because both read local MergeTree tables. The flagged Q20 improvement (-41.8%, with CPU time roughly halved) cannot come from this diff, so it is downgraded to not_sure; the likely cause is a difference between the PR build and the master baseline. Q28 is borderline, and Q33/Q34 fall within master's normal variation, which fits a diff with no effect on these benchmarks. clickbenchFlagged queries (2 of 43)
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🟢 No significant changes Debug info
|
…ping its object When the read-ahead window was full (`Slot::tryAcquire` returned null) or the IO pool refused the job, the object was still counted as handled, so its footer was never read ahead and the reader opened it with a synchronous footer request. The window fills in the normal footer-bound case, because the requests of objects already handed out keep their slots until their reads finish. Now the loop stops at the first object whose read cannot be scheduled and tries it again on the next call. Measured with 100 Parquet objects behind a 20 ms RTT (release builds, 9 runs per arm): `count() WHERE CounterID = -5` schedules 91 of 91 eligible footers instead of 76-79 with 4 threads, 81 of 81 instead of 64-69 with 16 threads (median 170 -> 147 ms); other queries within A/A noise, S3 GETs and bytes unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…condition cache With `use_query_condition_cache_for_top_k = 0` a read with TopN dynamic filtering does not consult the query condition cache, but the read-ahead iterator skipped every object that had an entry in it, so an earlier plain read of the same table and predicate turned the read-ahead off for such reads. The iterator now probes the cache only when the source would, through the source's own predicate, which is moved to `StorageObjectStorageSource::isTopKFilterAllowed`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rage-parquet-footer-prefetch Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rage-parquet-footer-prefetch Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124671
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A query over a glob of Parquet objects in object storage (for example
s3('.../*.parquet')) now reads the footers of the next objects in the background instead of one after another. With 20 ms of latency to the storage,count()over 100 objects takes about a third of the time. The read-ahead followsremote_filesystem_read_prefetchand needss3_validate_etag_on_read/azure_validate_etag_on_read(on by default).Description
A source opens its next object only after the previous one, and the Parquet reader reads the footer on its first
read(), so each stream waits for one footer round trip per object (25 in a row for 100 objects over 4 streams), even forcount()or a statistics-pruned filter. Analysis and original patch: @ snelheidai, #124671.A wrapper over
GlobIteratorhands out the same objects in order and reads the next footers on the IO pool: none for each stream's first two objects (LIMIT 1reads nothing extra), at mostclamp(4 * streams, 16, 32)ahead, each kept parsed until its object is opened, and wasted if a largerLIMITstops the query. Each read makes the reader's ownParquetMetadataCache::getOrSetMetadatacall and reaches the reader through theObjectInfo: handing it over through the cache would access every entry twice, and SLRU promotes an entry on its first hit. A failed read is rethrown by the reader that needs it, else not counted insystem.errors.Key lists, data lakes, archives,
*Cluster, non-seekable reads, objects whose query condition cache entry is read and reads withoutETagpinning keep the old path. I reusedremote_filesystem_read_prefetchas the switch; I can add a dedicated setting instead if you prefer.Release binaries, MinIO at 20 ms round trip, 100 objects, 4 threads, 9 runs per side (A/A noise 0.97-1.00):
count() WHERE CounterID = -5(pruned)count()count() WHERE AdvEngineID <> 0sum(length(URL))SELECT * LIMIT 1GETs, bytes and cache hits/misses are equal in every row, also for two concurrent cold queries; memory +2 to +21 MiB with these 105-column footers.
Tests:
05340_object_storage_parquet_footer_prefetchandobject_storage_parquet_footer_prefetch.xml.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124950]