Repository navigation
Query condition cache for table functions over files and object storage - #122127
Conversation
The query condition cache skipped every table without a UUID, which is the table behind a table function (`file`, `s3`, `icebergS3`, ...). For file-backed data the table is not needed: the entries are keyed by the location of the file together with its version (the local version token or the ETag), or by the location alone for immutable data lake files. Such tables now keep their entries under a fixed table id (`QueryConditionCache::getTableIdForFileEntries`), and object storage qualifies the path with the storage it is in (endpoint, bucket), which the table UUID used to provide. Related: #122064 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [5248f53] Summary: ✅
AI ReviewSummaryExtends the query condition cache to file and object-storage table functions, with cache identities derived from reader semantics, storage location, and file version. At Missing context / blind spots
Final VerdictStatus: ✅ Approve for code review; CI validation remains pending. |
A reader of one bucket of a file split between readers (`s3Cluster` with `cluster_table_function_split_granularity = 'bucket'`) reports the row groups of the other buckets as not matching, although it never read them. The missing table UUID used to keep these writes disabled for cluster table functions; now only a whole file, or one narrowed by an earlier cache hit, is recorded. Also restore the path-only overload of `makeQueryConditionCacheKey` that the unit test uses. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes18 object files changed (+57.16 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 units160 translation units recompiled, 1574 s compile time in total, 160 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…reads `test_s3_cluster::test_hive_partitioning` and `test_cluster_partition_pruning_reads` count the files read by repeated queries over table functions, which now use the query condition cache and skip the files an earlier query found to have no match. The first already disables every other cache for this. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122127&sha=72cddc566bda&name_0=PR Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tries Reading the same object through another endpoint is another storage for the query condition cache, so the entries written through the first endpoint must not be found through it, although the path within the bucket and the ETag are the same. Also skip the test with parallel replicas, where the replicas read the objects and the checked query counts no cache lookups. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122127&sha=79b615d766e58bce0a9410c56816a84538a6c72d&name_0=PR Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…scenario Every MergeTree table's BackgroundJobsAssignee keeps running StorageMergeTree::scheduleDataProcessingJob on the schedule pool, and a pass with nothing to merge still builds a merge predicate, a parts collector and ranges (~1.3 KB in the release profiler binary) that it frees on return. The storage profiler dumps the heap as soon as a scenario file returns, so a pass running at that dump on one arm is charged to that scenario and credited back at the next one: a conserved adjacent pair. `06_dictionary.sql` has an 80 KB baseline, so one pass clears both the 1,024-byte and the 1 % bar. Production reports on trees that already contain ClickHouse#120487 and ClickHouse#121364: ClickHouse#122127 `06` +1,296 and ClickHouse#120444 `06` +1,184, each exactly the rows of one selection pass, with `07` the same rows negated. Stop merges on each scenario table once nothing merges or mutates it any more, as ClickHouse#119706 did for `test_many_parts`: on `test_mt` after its last mutation at the end of `04`, and on `test_mt_2` / `test_mt_3` right after their CREATE in `05`. With the blocker set, scheduleDataProcessingJob returns before selectPartsToMerge. After `mutations_sync = 2` returns, the mutation task is in NEED_FINISH, which has no cancellation check, so the STOP in `04` aborts nothing. Both arms of a run read this checkout's scenario files, so the change is symmetric from the first run. `test_mt` stays exposed in `01`..`03`, where it must merge and mutate. Validated locally with one Debug build (no C++ in the diff): a clickhouse local probe of `01`..`05` counts 26-30 selection ranges in a 6 s idle window without the change, 0 with it, and 9-10 with any one STOP removed; with a 1,000-partition probe table, profiler dumps catch a selection pass in flight in 10 of 20 dumps without its STOP and 0 of 20 with it; a real +64 KiB allocation in `06` still FAILs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etch` The test reads `big.parquet` twice with the same predicate. Now that the `s3` table function uses the query condition cache, the second read hits the cache, skips every row group and issues no prefetch, so the `RemoteFSPrefetches >= 1` check of the `input_format_allow_seeks = 0` run fails. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122127&sha=cc1d035b239c1259706fbcf9b6b01ee86ddb852b&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 #122127 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… key For a table without a UUID the key used the endpoint-qualified path, which for `url` / web and HDFS storages is the raw URL or URI and can carry a signed URL or userinfo. The `part_name` is visible in `system.query_condition_cache` and in the logs. Use the path within the storage plus a hash of the qualified path instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ile readers A `part_name` of a file-backed entry identifies only the bytes of the file, not how they are read. With one fixed `table_id` for all tables without a UUID, a `file(..., CSV, ...)` read of a Parquet file found the "no match" verdicts of an earlier `file(..., Parquet)` read with the same predicate and skipped the file, returning 0 instead of throwing. The same applies to another compression or another structure (e.g. another default of a column missing in the file). `QueryConditionCache::getTableIdForFileEntries` now derives the id of a table without a UUID from its format, compression method and columns, which a table with a UUID fixes. `StorageFileSource` and `StorageObjectStorageSource` compute it once per source. The case is added to `05256`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ndition cache Mirror the gates of `StorageFileSource` in `StorageObjectStorageSource`: never write query condition cache entries from a read with a TopK filter, because its unmatched row groups depend on the running threshold, and consult the cache for such reads only while `use_query_condition_cache_for_top_k` is on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since the query condition cache works for tables without a UUID, `file` reads of Parquet files populate it. A query with `indexHint` stores the row groups pruned by min/max statistics, and a later query with the same condition and `input_format_parquet_filter_push_down = 0` skips them, returning 200 rows instead of 10000. Entries are only written once the file has settled for 3 seconds, so this showed up only in slow builds (MSan in the `CH Inc sync` private CI). The test isolates statistics pushdown, so disable the cache in it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The new failure in |
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]>
… the query condition cache key of files `type_json_use_partial_match_to_skip_paths_by_regexp` decides which paths of a `JSON` column decoded from a Parquet variant are skipped, so two `File` tables without a UUID that pin different values at `CREATE` shared entries. Add it to `fileFormatPruningSettingsSalt`, together with the other settings that the identity of the columns cache lists as changing decoded values without changing their types: `input_format_parquet_allow_geoparquet_parser`, `input_format_parquet_enable_json_parsing`, `input_format_parquet_detect_variant_by_structure` and `precise_float_parsing`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122127&sha=52220870f83abd573c1a2f3b4e9c2ceb84135768&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failure is |
|
This is fixed by my #122688, merged on 2026-10-22 03:57 UTC, after this run. The job built The server-side AST fuzzer replaced the policy of On master |
| table_name_hash.update(table_name.size()); | ||
| table_name_hash.update(table_name); | ||
|
|
||
| boost::hash_combine(condition_hash, top_k_filter->plan_hash); |
There was a problem hiding this comment.
Why do we use a weak hash combination here? Why not SipHash?
There was a problem hiding this comment.
@groeneai, check this question. When the PR is merged, do a follow-up if needed.
There was a problem hiding this comment.
No good reason. Its inputs are already 64-bit SipHash values, and Boost 1.90 hash_combine is hash_mix(seed + 0x9e3779b9 + v) with an invertible mixer, so a collision through it needs equal sums of those values, which I don't see a way to reach. Still, ReadFromObjectStorageStep builds the same key with one SipHash, and this one should too. I'll do that in a follow-up after the merge.
While checking it, I found a real collision one level down: topKPlanHash (optimizeTopK.cpp) feeds the sort column name and the type name to SipHash without their lengths, so ORDER BY cU (Int8) and ORDER BY c (UInt8) get the same plan_hash. On master 44cf9c04, with t (c UInt8, cU Int8) ENGINE = File(Parquet), row groups of 1000 rows, cU = 100 only in the first one and c = 200 only in the last one:
SELECT cU FROM t ORDER BY cU DESC LIMIT 3 SETTINGS use_query_condition_cache = 1, use_top_k_dynamic_filtering = 1, query_plan_max_limit_for_top_k_optimization = 1000; -- [100,100,100]
SELECT c FROM t ORDER BY c DESC LIMIT 3 SETTINGS <same>; -- [1,1,1], expected [200,200,200]The second query reuses the TopK by cU entry. With the column named cV, it returns [200,200,200]. The same shape on MergeTree is not affected. I'll fix this in the follow-up as well, check the object storage key (it consumes the same plan_hash), and link the PR here.
There was a problem hiding this comment.
Follow-up: #127688. It builds this key with one SipHash, turns the two queryConditionCacheSettingsSalt(s) ^ fileFormatPruningSettingsSalt(s) into one SipHash, and length-prefixes the strings in topKPlanHash.
A correction to my reply above: MergeTree is affected too, when a WHERE stays a separate filter outside PREWHERE; the new test has that case. The object storage key is already one SipHash and takes the fixed plan_hash; no type name that Iceberg, Delta Lake or Paimon reads ends with another one, so data lake tables could not hit the collision. Its no-filter branch salts with queryConditionCacheSettingsSalt only, unlike its filter branch; I left that as is.
alexey-milovidov
left a comment
There was a problem hiding this comment.
Everything else LGTM.
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
🕵 Thanks, @clickgapai: the finding is correct. |
|
@alexey-milovidov Confirmed on current master (with #122127, without #127745): the repro from
|
…-parallel-read Conflicts with the query condition cache for tables without a UUID (#122127) and with skipping Parquet files by the cached statistics (#125528): the split file now uses `query_condition_cache_table_id` (computed before splitting), the sources of a split file don't keep the statistics (each reads only some row groups) and count a skipped file once, and the reader of a bucket skips other buckets' row groups only after recording their ranges. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ary tests Since ClickHouse#122127 the query condition cache also serves `file()` once the file is 3 s old. On a slow run the warm-up of `05229` (randomized `input_format_parquet_dictionary_filter_push_down = 0`) wrote a cache entry, the `without_filter` measurement (also 0) hit it and read 0 bytes, and the `with_filter` measurement (100000000, another cache key) read the bloom filters: `FAIL: 576 > 0`. In `05325` every query has the same key, so on a slow run both byte measurements read 0 bytes and pass vacuously. Same fix as `38be33cbbbb26` for `05024_parquet_s3_no_footer_prefetch`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=5ca96fa461ab69f4471e81d4de6f97dcc6ced361&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20parallel%2C%201%2F3%29 ClickHouse#122127 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…de redundant by master Since #122127 a bucket task neither looks up nor writes the query condition cache unless its bucket came from a cache hit, so marking the row groups outside the bucket as matched no longer changes anything; 05256 already covers `s3Cluster` split into buckets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The query condition cache ignored every table without a UUID. That includes the table behind a table function (
file,s3,azureBlobStorage,icebergS3,icebergLocal, ...) and tables in databases without UUIDs. So repeated queries over Parquet files through table functions never used the cache. TheNilcheck was added forMergeTree, where part names likeall_1_1_0repeat across tables, so the table is part of an entry's identity (#92863, #92864).File-backed entries don't need the table. Their part name is the location of the file together with its version: the version token of a local file (modification time, inode and size, already required to have settled), or the ETag of a remote object. For immutable data lake files the location alone is used. So:
QueryConditionCache::getTableIdForFileEntriesmaps a missing UUID to a table id derived from the reader definition: format, compression method and columns. A table with a UUID fixes these, but the same file can be read with another definition (e.g.file(..., CSV, ...)over a Parquet file), and a verdict from one reader is wrong for another.StorageFileandStorageObjectStorageSourcecompute the id once per source and use it for their entries. TheNilcheck inread/writestays, soMergeTreeis unchanged.getUniqueStoragePathIdentifierwith the connection info, as the schema cache does). Otherwise the same key in two buckets could share entries.The bucket-splitting iterator (
ObjectIteratorSplitByBuckets) is left as it is. Its lookup key has neither the ETag nor the connection info, so it keeps passing the plainNilUUID, which the cache still ignores.The test covers
file,s3andicebergLocal: the second run of a query hits the cache, and after the file is rewritten the next query misses and returns the correct result. Onmasterthese table functions neither read nor write the cache:readreturns nothing and counts neither a hit nor a miss for aNilUUID.This composes with #122064 (the TopK query condition cache for Parquet files, which currently also skips UUID-less tables). Whichever merges second switches its call sites to
getTableIdForFileEntries.Related: #122064
Related: #121876
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 Parquet files read through table functions such as
file,s3oricebergS3, not only through tables.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122127]
Version info
26.11.1.708-master(included in26.11and later)