Repository navigation
TopN dynamic filtering for Parquet reads from object storage and data lakes - #122109
Conversation
`ReadFromObjectStorageStep` now accepts the `ORDER BY <column> LIMIT n` dynamic filter, as `ReadFromFile` does since #115798, so the Parquet reader drops rows and skips row groups that cannot enter the top-K for `s3`, Azure, HDFS and data lake tables. The step checks the same eligibility (a column the format reads, with no default expression), and `StorageObjectStorageSource` keeps the filter off for the files whose columns a data lake rewrites after the reader: files under an older schema, files with a schema transform, and an identity partition column. Related: #115798 Related: #121876 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [0621fc3] Summary: ✅
AI ReviewSummaryThis PR extends Final Verdict
LLVM Coverage ReportMeasured on commit 0621fc3.
Changed lines: Changed C/C++ lines covered: 81/87 (93.10%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 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
|
…entries With the TopN filter a row group can end up without a returned row only because the running threshold had excluded it, and the object-storage cache key covers just the predicate: after `SELECT ... WHERE p ORDER BY k LIMIT 3`, a plain `SELECT count() ... WHERE p` skipped row groups and returned 54509 instead of 100000. As for local files, TopN reads now never write entries, and consult them only while `use_query_condition_cache_for_top_k` is on. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…torage-top-k-dynamic-filtering
`schema_changed` is also set for an Iceberg file that only carries equality deletes: it gets an initial schema, but no schema transform, and is read under the current names. Gate the filter on the schema transform instead, and keep it in the filter info built for such a file. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With `allow_delta_kernel_rs = 0` the partition columns stay in the format header and are replaced in the chunks the format returns, so the reader compared what a data file stores under that name against the threshold: a table whose files also store the partition column returned the rows of the wrong partition for `ORDER BY p LIMIT 3`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`deltaLakeLocal` needs delta-kernel-rs, which is not built under MSan, so the flaky check failed with `Unknown table function deltaLakeLocal`. The new test carries `no-msan`, like `05237_delta_lake_legacy_partition_column_type`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122109&sha=6b8e64c332c4f9423ffc43d5fbfd1ee4673767ee&name_0=PR Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The query condition cache gates in `StorageObjectStorageSource` looked at the shared `format_filter_info->top_k_filter`, but whether the filter is applied is decided per file: data lake files with a schema transform, or sorted by an identity partition column, are read without it. Such files were still kept from writing cache entries, and with `use_query_condition_cache_for_top_k = 0` also from reading them, which lost row-group pruning on exactly the files that opted out of the optimization. The per-file decision now lives in one lambda used by both the cache read and the reader construction, and `ReaderHolder` records whether its reader applies the filter, which gates the cache write in `generate`. Address review: #122109 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ge read A data lake table configured as `Parquet` can contain files of other formats, such as ORC in Iceberg. `is_top_k_filter_allowed` now also requires the actual file format to be `Parquet`, so such a file is treated as read without TopN and keeps consulting the query condition cache with `use_query_condition_cache_for_top_k = 0`. Address review: #122109 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both have fixing PRs:
|
… column Since f5ca04b a structure of only Hive partition columns makes the format read them from the data file, while the query takes their values from the path. `ReadFromObjectStorageStep::supportsTopKDynamicFilter` then armed the filter on the file's values, so `ORDER BY key LIMIT 3` over `b=1/key={10,9}/` returned `10` instead of `9`. Mirror the `formatReadsHivePartitionColumns` guard of `ReadFromFile` and add a test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… reader declines TopN for The Parquet reader does not install `__topKFilter` for a file that does not store the sort column, so such a file is read as without TopN. Decide whether a file may populate the query condition cache by asking the input format (`IInputFormat::isTopKFilterApplied`) instead of by the presence of `FormatFilterInfo::top_k_filter`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…` as `no-parallel` It checks `QueryConditionCacheHits`, and other tests drop the query condition cache concurrently, like for all other tests checking this profile event. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122109&sha=1c2aa218a7d38897ee84c785db8e9348c4e961c1&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 #122109 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lumn` Use an `S3` table instead of the `s3` table function, whose UUID changes with every query, so that the query condition cache entries are found, and write `Int64` columns matching the declared structure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is good.
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Conflicts with the TopN query condition cache key (ClickHouse#122109 and the `StorageFile` TopK key), the `Parquet` columns cache and the lazy column chunk metadata (ClickHouse#124364): - `StorageFile`: row blocks are read only from the plain predicate key, in the same consultation as its row groups (one Hits/Misses event), so `readFile` gained `increment_profile_events`. - `StorageFile`: master moved the `!top_k_filter` check out of the write-side condition to write TopN entries under the TopK key. The row-block write keeps it, otherwise a TopN read would store threshold-dependent row blocks under the plain key. - `StorageObjectStorageSource` merged cleanly: the row-block write is inside the per-file `!isTopKFilterApplied()` block of ClickHouse#122109. - `Reader::file_metadata` is an accessor now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extends TopN dynamic filtering (
ORDER BY <column> LIMIT n,use_top_k_dynamic_filtering) to Parquet reads from object storage:s3, Azure, HDFS, and data lake tables (Iceberg, Delta Lake, ...). #115798 added it for local files only. As there, the Parquet reader drops the rows that cannot enter the top-K and skips whole row groups whose statistics prove the same.ReadFromObjectStorageStepopts in throughsupportsTopKDynamicFilterwith the same eligibility asReadFromFile. The sort column must be one the format reads: Hive partition and virtual columns are appended after the reader, and a column with a default expression is recomputed above it byAddingDefaultsTransform.Object storage builds the filter info per file, and data lakes rewrite the values a file's reader returns. So
StorageObjectStorageSourcedecides per file, and keeps the filter off where the reader's value is not the value the query sorts by:Deletes (positional, equality, deletion vectors) only remove rows after the reader, which is compatible with the filter: it only drops rows that cannot be in the result. Floating-point sort keys and the other exclusions of #115798 apply unchanged.
The test covers plain Parquet on S3 and Iceberg tables. For each it checks that fewer rows are read and that results are identical with the optimization on and off. It also includes an Iceberg table whose sort column got its name by a rename after the first file was written: that old file stores tiny values under the same name. Handing the filter to that file (checked by building it that way) returns
65408, 65407, 65406instead of99999, 99998, 99997.On MinIO,
SELECT * FROM s3(...) ORDER BY k LIMIT 10over 20M rows in random key order takes 64 ms instead of 90 ms, with 6.1M instead of 20M rows reaching the sort.A follow-up can bring the TopK query condition cache of #122064 to object storage, starting with data lakes, whose snapshot identifies the exact file set.
Related: #115798
Related: #122064
Related: #121876
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ORDER BY ... LIMIT nqueries over Parquet files on object storage (s3, Azure, HDFS) and over data lake tables such as Iceberg now skip the rows and row groups that cannot be in the result, as they already did for local files.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122109]
Version info
26.10.1.1777-master(included in26.10and later)