Repository navigation
Query condition cache for TopK reads of Parquet files in object storage - #124813
Conversation
A TopN (`ORDER BY ... LIMIT n`) read of Parquet files in `S3` or `AzureBlobStorage` now records in the query condition cache the row groups which hold no row of the result, and a rerun skips them. The threshold of the TopN filter comes from the rows of all objects of the query, so the key covers the paths and ETags of all of them: `ObjectIteratorListingAllForTopKQueryConditionCache` lists the objects before returning the first one (up to 100000 objects). An object can be overwritten after it was listed, so the key is made only when every read is pinned to the listed ETag (`s3_validate_etag_on_read`, `azure_validate_etag_on_read`). Related: #124785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [d6d53d0] Summary: ✅
AI ReviewSummaryThis PR extends the query condition cache to TopK reads of Parquet files in Missing context / blind spots
Final VerdictStatus: ✅ Approve — no code changes requested; final CI results remain pending. |
…state; fix the object limit and the build on Apple/WASM - Extract the repair of a missing `datalake_table_state` from `createFileIterator` into `StorageObjectStorageSource::ensureDataLakeTableState`, and call it in `ReadFromObjectStorageStep::createIterator`, so the TopK key is made from the same snapshot the files are read from, also when the state was missing in the storage metadata. - `ObjectIteratorListingAllForTopKQueryConditionCache` lists one object more than `MAX_OBJECTS`, so exactly `MAX_OBJECTS` objects still make a key. - Use `size_t` hash seeds for `boost::hash_combine`, which did not compile on Apple and WASM where `UInt64` is a different type than `size_t`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes521 object files changed (+85.14 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units3348 translation units recompiled, 18692 s compile time in total, 3347 of them have a recent master baseline. Translation units without a recent master baseline:
|
…at use the TopK query condition cache key For plain object storage, the key may turn out not to be made (too many objects, an archive member, a bucketed read, an object without a usable `ETag`), and then the per-row-group `top_k_best_value` bookkeeping was paid for nothing. Read only the files that actually use the key with a `FormatFilterInfo` with `track_row_group_best_values`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Processors/QueryPlan/ReadFromObjectStorageStep.cpp
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124813&sha=da25e86336b792e034ea0b003dd17bccbbe4566f&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 ( Also: |
|
The I checked it against this exact query. On a master debug build ( The job timeout: #123849 (mine) splits |
|
📊 Cloud Performance Report 🟢 AI verdict: One query was flagged: clickbench Q20 is -42.7% faster (220 ms to 126 ms), and CPU time dropped from about 2898 ms to 1538 ms, so the gain reflects less work done, not a timing quirk. The PR does not explain it. Every source change is in the object-storage read path: a TopK query condition cache for S3, Azure and data-lake Parquet reads, plus a refactor of the existing ETag-pinning check into a helper. ClickBench reads a local MergeTree table, so Q20 never runs that code. The result clears the thresholds that lock a verdict in place, so it stays an improvement, but it should not be credited to this PR; it most likely comes from other changes between the base build and the PR build, and a re-run against the PR's exact merge base would confirm that. clickbench🟢 1 improved Flagged queries (1 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
|
…rage Take the key of the base PR (the whole filter of the step, `SipHash` of the condition, the TopK plan and the table state) and keep the plain object storage part: `condition_hash_without_files` is the hash of the condition and the TopK plan, to which the hash of the set of files is added later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y condition cache key `getDataLakeSettings` throws `NOT_IMPLEMENTED` for plain object storage, so after the merge of the base branch every TopN read over `S3` failed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks @groeneai, noted: the Update: merged the base PR branch ( |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124813&sha=4cdf05d99b254b5a94f96ee7fbe4b705e7647609&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 ( The |
…n cache key A URL with `versionId` makes every read fetch that version, bypassing the listed-`ETag` validation, while the object metadata (and so the `ETag` in the per-file key) describes the latest version. After `ALTER NAMED COLLECTION` and `DETACH` / `ATTACH`, the table keeps its UUID, paths and `ETag`s, so the entries of another version could be reused and rows of the result skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124813&sha=3d741af8db977bc1427159d9a86b4239b9f35274&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29 (abort in |
|
Same bug as #127364, which is the fix (open, CI green at d72ee5c, waiting for review). The stack on 3d741af (STID 2905-3cdd) is the one #127364 targets: an INSERT in the embedded client (web terminal / SSH) throws after Master still has the unguarded dereference. Since #125517 routed stress load through the web terminal and SSH, this abort has failed 11 stress jobs today under three STIDs (2905-3cdd, 2360-3d86, 3554-3f66), 4 of them on master. |
|
🕵 Thanks @groeneai - agreed, the Update: the |
|
🕵 Update: merged current master ( The previous red checks were not caused by this PR:
|
|
🕵 The only red check was |
…ull` A URL with `versionId` makes `ReadBufferFromS3` request that version instead of checking the listed `ETag`. For a real version this pins the read, but the null version is mutable: in a bucket with versioning suspended, an upload under the same key overwrites it in place. So a rerun could read a replaced object while reusing entries recorded for the old one, and skip row groups of other objects that now hold rows of the result. `isReadPinnedToListedGeneration` now returns false for `versionId=null`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only red check, Update: merged current master ( |
|
🕵 The only red check was Merged current master ( |
Resolve the conflicts in ReadFromObjectStorageStep.cpp/.h and StorageObjectStorageSource.cpp/.h: keep the 26.10 side and take only the lines of #113095. The conflicting master context is the TopK query condition cache for object storage (#124808, #124813) and the declarations next to it, none of which is in 26.10. So the in-order sources are built without a TopK query condition cache key, and createIterator keeps its 26.10 form, which has no iterator_metadata to preserve. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the query condition cache for TopN (
ORDER BY <column> LIMIT n) reads of Parquet files in plain object storage (S3,AzureBlobStorage), continuing #124808 (data lakes).A TopN read now records the row groups which hold no row of its result, and a rerun of the same query over the same objects skips them - also without any
WHERE.ObjectIteratorListingAllForTopKQueryConditionCachelists all objects on the first call ofnext(when the pipeline already runs, as some iterators apply a_path/_filefilter only then) before returning the first one. A TopN read reads all objects anyway, so this adds no requests. With more than 100000 objects, or an object without a usable ETag, inside an archive or split into buckets, no key is made and the objects are read as before.s3_validate_etag_on_read(not for GCS) or Azure withazure_validate_etag_on_read, both enabled by default. Then an overwrite between the listing and the read fails the read. The check is shared with lazy materialization, which has the same requirement (isReadPinnedToListedGeneration).The test covers repeated queries with and without a predicate, a different
LIMIT/ direction / plain read not reusing the entries, a rewrite of one object of a glob (without the ETags in the key, the rerun returns999, 998, 997instead of100999, 100998, 100997- checked by building with them removed), unpinned reads, anduse_query_condition_cache_for_top_k = 0.Benchmark (local build, local MinIO; 32 Parquet objects in one glob, 32M rows, 3200 row groups of 10000 rows;
SELECT * FROM t ORDER BY k DESC LIMIT 10withk = cityHash64(number); medians of 3 runs):S3GetObjectReadBufferFromS3Bytesuse_query_condition_cache_for_top_k = 0A cold run costs the same as the read without the cache, since listing the glob ahead adds no requests. With a
WHEREthe numbers are similar (111 / 110 / 40 ms; 1.95 GiB / 1.95 GiB / 6.64 MiB). Details: #124813 (comment)Related: #124785
Related: #124808
Related: #122064
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The query condition cache now also works for
ORDER BY ... LIMIT nqueries over Parquet files inS3andAzureBlobStorage: a rerun of such a query over the same objects skips the row groups which held no row of the result.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124813]
Version info
26.11.1.1613-master(included in26.11and later)