Repository navigation
Query condition cache for TopK reads of data lakes - #124808
Conversation
A TopN (`ORDER BY ... LIMIT n`) read of a data lake table (`Iceberg`, `DeltaLake`, `Paimon`) with Parquet data files now records in the query condition cache the row groups which hold no row of the result, and a rerun of the same query skips them, also without a `WHERE`. The entries are keyed by the TopK plan, the predicate, and the snapshot of the table: the snapshot identifies the set of data files (and deletes), which are never modified in place, and the threshold of the TopN filter comes from the rows of all of them. The same was done for the `File` engine in #122064. Related: #124785 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [77e72b4] Summary: ✅
AI ReviewSummaryExtends the query condition cache to TopK reads of data lake tables with Parquet files, partitioning threshold-dependent entries by the predicate, TopK plan, and pinned table snapshot. No unresolved actionable findings remain at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; merge remains subject to the required CI checks. |
…imon` reads An incremental `Paimon` read iterates only the delta since the watermark committed in Keeper (or of `paimon_target_snapshot_id`, bounded by `max_consume_snapshots`), so the same pinned `datalake_table_state` yields different sets of data files from query to query. A TopK entry recorded for one batch could then wrongly skip row groups in another one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion cache as a whole `boost::hash_combine` takes `std::size_t &`, which is not `UInt64` on Darwin and WASM, so combine the key with `SipHash` instead. Address review: with `use_query_condition_cache_for_top_k = 0` a TopN read neither consults nor populates the plain predicate entries, also for the files that do not apply the TopN filter (`ORC`, schema evolution, identity-partitioned sort column), as `File` and `MergeTree` do. https://s3.amazonaws.com/clickhouse-test-reports/PRs/124808/08f892a6e0762c92e0e5bc00b67ea6d300bf53ba/pr/build_amd_darwin/build_clickhouse/build_clickhouse.log Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124808&sha=08f892a6e0762c92e0e5bc00b67ea6d300bf53ba&name_0=PR&name_1=Performance%20Comparison%20(amd_release%2C%20master_head%2C%202%2F6) ( |
|
Withdrawn: the PIE attribution below was wrong. The measured cause is in #124808 (comment) Original commentInvestigated. Not caused by this PR:
No fix PR is in progress yet. The remedy is the open choice in #122447 (comment): (A) build |
…es` for the TopK cache gate This PR intentionally makes `use_query_condition_cache_for_top_k = 0` keep a TopN read of a data lake table out of the query condition cache as a whole, also for the files that do not apply the TopN filter (as `File` and `MergeTree` do, requested in review). The test added on master pinned the previous per-file behaviour, so the `05320_top_k_off` query now has no cache hits. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124808&sha=89e62924aac1ac2e6655a41bd72ddb4d976a687a&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20sequential%29 #124808 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 sizes12 object files changed (+80.09 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 units43 translation units recompiled, 463 s compile time in total, 43 of them have a recent master baseline. |
|
Fixing PR for the amd_release 2/6 perf red (general_purpose_hashes #1): |
… the step The TopK entries of `ReadFromObjectStorageStep` were keyed by the `condition_hash` of the format filter, which lacks the conjuncts on virtual columns such as `_path`. Those narrow down the set of files read, so a query with such a conjunct could reuse the row group skips of a broader query and lose rows of its result. Key by the whole filter of the step, as `StorageFile` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or the `_path` case Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The |
# Conflicts: # src/Processors/QueryPlan/Optimizations/updateQueryConditionCache.cpp
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124808&sha=c4e1c93cea5cf3fc1a02858ff717e8ff8f5e80c0&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 ( |
|
The fix is in progress: #125706 (approved, merge state clean). This run has the same cause as the ones on #100377, #104965 and #114043. At 01:15:57 a fuzzed secondary query of The master run ( |
…`_table` condition `RENAME TABLE` and `EXCHANGE TABLES` keep the UUID and the data lake snapshot but change `_table`, so the TopK query condition cache key of a read of object storage stays the same while a condition on `_table` lets other files make the threshold. Treat `_table` like `_time`, `_etag` and `_tags` and disable the TopK entries when the filter or PREWHERE reads it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124808&sha=9004f7b8dfd988ec312571e7ebb70289d88f5ca2&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 ( The other failure, |
|
The fix is #125446 (open; the changes requested in its review are in b58c6f8, waiting for re-review). Cause: with Details and a smaller 26.3 case: #125446 (comment). Both are correct with b58c6f8. |
| } | ||
| catch (...) | ||
| { | ||
| tryLogCurrentException(log, "Failed to write to query condition cache"); |
There was a problem hiding this comment.
Why do we need try/catch? Better to just let the error propagate.
There was a problem hiding this comment.
This runs in the destructor: the verdict needs the final TopK threshold, which is known only after the sorting transforms are done with the rows, so the write cannot happen earlier (e.g. in onFinish). Letting the exception escape the destructor would call std::terminate. StorageFileSource::~StorageFileSource uses the same pattern.
alexey-milovidov
left a comment
There was a problem hiding this comment.
Everything else LGTM.
Resolve conflicts with the TopK query condition cache of object storage (#124808) and the query condition cache of `URL`: the plain predicate is consulted under the `table_id` and key for files, so table functions keep using it; the TopK key stays with tables having a UUID. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… condition cache after the master merge Master (ClickHouse#124808) added a TopK query condition cache key for data lake reads and made a TopN read of object storage neither consult nor write the plain predicate key while `use_query_condition_cache_for_top_k` is off. A statistics-only read (a `String` sort key without `use_top_k_dynamic_filtering_for_variable_length_types`) compares no row with the threshold, so, as for `File` tables and as the setting's documentation says, it stays a plain read for the cache: - the plain key is consulted (merge resolution) and written whatever the value of the setting; - `ReadFromObjectStorageStep::makeTopKQueryConditionCacheKey` makes no TopK key for it, as `ReadFromFile` already does: the key would make the reader track the best value of every row group, a per-row comparison on the `String` column that the statistics-only mode exists to avoid. Test: a statistics-only read with the setting off populates the cache (File, S3); an Iceberg read without a filter consults the cache with the opt-in and not without it. Mutants, each red on exactly its line: write gate without `filter_rows`, consult gate without `filter_rows`, no early return in the data lake key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 data lake tables (Iceberg,DeltaLakewith Delta Kernel,Paimon) with Parquet data files - the same as #122064 did for theFileengine. So far such reads only consulted the entries written by plain reads with the same predicate, and never wrote any themselves.A TopN read now records the row groups which hold no row of its result, and a rerun of the same query skips them - also without any
WHERE, e.g.SELECT * FROM iceberg_table ORDER BY k DESC LIMIT 10.optimizeTopKcomputes), the predicate if any, and the serialized snapshot of the table (datalake_table_statepinned in the storage metadata, which the file iterator reads). A snapshot identifies the set of data files and deletes, and data lake files are never modified in place, so no per-file versions are needed: each new snapshot gets fresh entries. No key is made for tables without a UUID (table functions), with distributed processing, with a row policy, for incrementalPaimonreads (paimon_incremental_read, which return a different batch of files for the same snapshot), or for configurations without a snapshot state (Hudi, the legacy Delta Lake reader).File: a row group that returned no row, or whose best returned value of the sort column is strictly beyond the final threshold, holds no row of the result. Deletes only remove rows after the reader, so this stays sound. The entries are written when the source is destroyed, against the final threshold; a cancelled read writes nothing. A file which the iterator split into buckets neither consults nor writes the key.The test covers repeated queries with and without a predicate, a different
LIMIT/ direction / plain read not reusing the entries, theuse_query_condition_cache_for_top_ksetting, and a new snapshot afterALTER TABLE ... DELETE: without the snapshot in the key, the rerun returns6, 5, 4instead of100999, 100998, 100997(checked by building with it removed).Related: #124785
Related: #122064
Related: #122109
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 data lake tables (Iceberg,DeltaLake,Paimon): a rerun of such a query skips the Parquet row groups which held no row of the result in the same snapshot.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124808]
Version info
26.11.1.492-master(included in26.11and later)