Repository navigation
Fix a filter on a Hive partition column pruning by the data file's column of the same name - #123903
Conversation
…t the data file A Hive partition column and a requested virtual column are added by the source after the format produced the chunk, but the read steps of `file`, `url` and object storage passed the whole pushed-down filter to the format. Since ClickHouse#104435 `FormatFilterInfo::initKeyConditionOnce` adds every filter input missing from the format header to the KeyCondition, so the Parquet reader resolved such a column to the data file's own column of the same name and pruned row groups, pages and dictionaries by the file's values. When the file stores other values than the path (or a physical `_file` column), `WHERE key = 9` on `key=9/` and a row policy on the partition column returned no rows, while `SELECT key` showed 9 for every row. Regression since 26.8. `ReadFromFormatInfo::getFormatFilter` now gives the format the filter without the conjuncts that reference a Hive partition column or a requested virtual column (`splitFilterDagForAllowedInputs` with a partial result, so `key = 9 AND v < 10` still prunes on `v`). The files iterator keeps the full filter, and the `Filter` step above still applies all of it. It replaces the `formatReadsHivePartitionColumns() ? nullptr : filter_actions_dag` rule of ClickHouse#123381, which covered only the structure with partition columns alone. Data lakes keep their virtual-column conjuncts, because Iceberg reads its row lineage columns from the data file; they have no Hive partition columns, so their filter is unchanged. Closes ClickHouse#123717 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getFormatFilter` used `splitFilterDagForAllowedInputs`, which also drops non-deterministic conjuncts. A PREWHERE or a pushed row policy is part of `filter_actions_dag` and is applied by the format a second time through `prewhere_info` / `row_level_filter`, so `PREWHERE v < 100 + 0 * rand() WHERE key = 9` left the format with no filter while it still filtered rows: with only `count()` requested the Parquet reader threw NOT_FOUND_COLUMN_IN_BLOCK, otherwise the source cached the post-PREWHERE row count as the file's row count and a later trivial `count()` returned it. The filter is now split into its AND atoms and only the atoms that read a Hive partition or virtual column are dropped; PREWHERE and row-policy atoms read only file columns, so they always survive. Data lakes were exempt from the virtual-column strip as a whole, but Iceberg reads only `_row_id` and `_last_updated_sequence_number` from the data file. After `RENAME COLUMN _path TO old_path` (or `DROP COLUMN _path`) an old data file still stores a `_path` column, and `WHERE _path != 'evil'` pruned every row group on it. Only the row lineage columns are kept now. The test is renumbered to 05325, gets an Iceberg arm, a count-from-files cache arm and a query condition cache arm on an `S3` table (a table function has no UUID, so the cache never engages for it). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ilter The count-from-files cache was written whenever the format got no filter DAG. A join runtime filter (moved into the read's PREWHERE after the DAG is collected) and the top-K dynamic filter also make the format skip rows, so once a WHERE on a partition or virtual column no longer reaches the format, a later trivial count() returned the reduced row count. The top-K case was already wrong on master without any WHERE. `FormatFilterInfo::hasFilter` now also covers the row-level filter, PREWHERE and the top-K filter, and the object storage gate uses it. A structure of partition columns alone gets no format filter again: its columns are in the format header, so an `indexHint` on them (whose arguments are not DAG children) still pruned by the file's values. Only Iceberg keeps the row lineage conjuncts; other data lakes add every virtual column after the format. The test gets `no-replicated-database` (the replicated DDL worker does not see the temporary table `IcebergLocal` reads), an eviction-proof query condition cache control, and waits a second after writing its files because the count cache ignores an entry registered in the second the file was written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restore master's wording of the formatReadsHivePartitionColumns() comment (it still skips filters). 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; 3 rounds, 11 findings plus my own review; final head 6fa177e).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261004-211505 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261004-204000 |
|
Workflow [PR], commit [634c083] Summary: ✅
AI ReviewSummaryThis PR fixes a real regression in file-like and object-storage reads with Final Verdict
LLVM Coverage ReportMeasured on commit 634c083.
Changed lines: Changed C/C++ lines covered: 51/53 (96.23%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units128 translation units recompiled, 1196 s compile time in total, 128 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
@al13n321 maybe I need some help. This PR is a little too large for me, but maybe ok for you |
| bool FormatFilterInfo::hasFilter() const | ||
| { | ||
| return filter_actions_dag != nullptr; | ||
| return filter_actions_dag || row_level_filter || prewhere_info || top_k_filter; |
There was a problem hiding this comment.
what about the join runtime filters? should it be included here?
There was a problem hiding this comment.
hasFilter() decides whether the source may store the number of rows it read as the file's row count in the count-from-files cache (StorageFile.cpp, StorageURL.cpp, StorageObjectStorageSource.cpp). A later trivial count() returns that number, so it is right only when the format returned every row of the file. Besides filter_actions_dag, the format also drops rows by the row policy, PREWHERE and the top-K threshold.
Before this PR, the WHERE kept the DAG non-null in such queries. Now the conjuncts on Hive partition and virtual columns are stripped, so WHERE key = 9 on a partition column plus a PREWHERE, a join runtime filter or top-K reaches the format with no DAG, while those still drop rows. On the previous commit 8012399 (without this line), after ... JOIN ... ON f.v = t.v WHERE f.key = 9 the trivial count() of the 1000-row file returned 10, and after WHERE key = 9 ORDER BY v LIMIT 3 it returned 100. The last two blocks of 05325_hive_partitioning_filter_on_partition_column.sql cover all three. Without any WHERE the top-K case is already wrong on master (#123716), and this line fixes it too; #122835 makes the same change.
Join runtime filters: yes, they are covered, through prewhere_info. The runtime filter is added (optimizeTree.cpp:349) after the read's filter_actions_dag is collected (:273), so it is never in the DAG. optimizePrewhere (:448) then moves it into the read's PREWHERE, and the format applies it from prewhere_info (master's comment at FormatFilterInfo.cpp:77-79 relies on the same order). When it is not moved, it stays a Filter step above the read and the format returns every row, so the cached count is right. The test asserts that __applyFilter is in the file read's PREWHERE before checking the count.
9f9539e
… revert The PR's sequential stateless lanes failed in 05243_query_condition_cache_top_k_parquet, a master regression from ClickHouse#123903. Master reverted it in ClickHouse#124977 (c380b02), so this merge brings the revert in. Master did not touch any file this PR changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 124977 123903 Revert "Fix a filter on a Hive partition column pruning by the data file's column of the same name" Changelog-deleted-entry: 123903 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed a `WHERE` condition or a row policy on a Hive partition column (`use_hive_partitioning = 1`) returning too few rows when the Parquet data file also has a column with that name and other values: Parquet row-group, page and dictionary pruning used the file's values instead of the path's. The same applied to a virtual column such as `_file` when the data file has a physical column with that name. Affects `file`, `url`, `s3` and other object storages. [#123903](#123903) ([Groene AI](https://github.com/groeneai)).
Closes: #123717
Related: #123381
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
WHEREcondition or a row policy on a Hive partition column (use_hive_partitioning = 1) returning too few rows when the Parquet data file also has a column with that name and other values: Parquet row-group, page and dictionary pruning used the file's values instead of the path's. The same applied to a virtual column such as_filewhen the data file has a physical column with that name. Affectsfile,url,s3and other object storages.Description
On 26.8 and 26.9, with
key=9/data.parquetstoringkey = 10:26.7 returns 1000. Partition and virtual columns are added by the source after the format reads the file, but
file,urland object storage passed the whole pushed-down filter to the format. Since #104435,FormatFilterInfoadds every filter input missing from the format header to the key condition, so the Parquet reader resolvedkeyto the file's own column and skipped every row group. #123381 covered only a structure of partition columns alone.ReadFromFormatInfo::getFormatFilternow gives the format the filter without the conjuncts on Hive partition and requested virtual columns.key = 9 AND v < 10still prunes onv; the file iterator and theFilterstep keep the full condition. Iceberg keeps the_row_id/_last_updated_sequence_numberconjuncts, which it reads from the data file.With less filter reaching the format, the
count()row cache must not be written when the format skipped rows through a PREWHERE, a join runtime filter or the top-K filter, soFormatFilterInfo::hasFilternow covers them. #122835 makes the samehasFilterchange.The test covers
file,url,s3with the query condition cache,_file, a row policy, the row count cache, and that pruning on file columns still happens. It fails on master in 15 queries and passes 50/50 randomized runs. A subcolumn of a partition column (key.null) is still read from the file; that is #123718.Workflow [PR]
Sync PR [sync-upstream/pr/123903]
Version info
26.10.1.1949-master(included in26.10and later)