Skip to content

Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix) - #124991

Merged
alexey-milovidov merged 6 commits into
masterfrom
revert-revert-123903-with-top-k-cache-fix
Oct 11, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
revert-revert-123903-with-top-k-cache-fix

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Closes: #124975
Related: #123903
Related: #124977
Related: #123717

This reverts the revert #124977, which brings back #123903, and fixes the problem that broke 05243_query_condition_cache_top_k_parquet on master.

#123903 keeps the conjuncts on Hive partition and virtual columns out of the filter pushed into the format. ReadFromFile::makeTopKQueryConditionCacheKey built the TopK query condition cache key from the format's filter, so:

  • with a filter only on such columns (WHERE _file = 'b.parquet') the format got no filter, while the step had one, and no key was made: the file_b_* lookups of 05243_query_condition_cache_top_k_parquet stopped happening;
  • with a conjunct that mixes such a column with a data column (key = 1 OR v > 450), the key was made from the reduced filter, so queries that differ only in that conjunct shared TopK entries and lost rows of the result (TopK File reads skip result rows: cache key omits Hive/virtual conjuncts #124975).

The rows these conjuncts drop after the format decide the TopK threshold too, so the key now covers the whole filter of the step (with the same determinism and PREWHERE checks, moved into FormatFilterInfo::computeConditionHash). When the format gets the whole filter, the key does not change.

The new test 05353_query_condition_cache_top_k_virtual_column_conjunct is the reproducer of #124975.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

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.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/124991]

Version info

  • Merged into: 26.10.1.2107-master (included in 26.10 and later)
  • Backported to: 26.9.17.9, 26.8.25.15

alexey-milovidov and others added 3 commits October 9, 2026 19:29
…-partition-filter-not-on-file-column"

This reverts commit c380b02, reversing
changes made to 38bc12d.
Since `getFormatFilter` keeps the conjuncts on virtual and Hive partition columns out of the filter
pushed into the format, the TopK key of `ReadFromFile::makeTopKQueryConditionCacheKey` was either not
made at all (a filter only on `_file`, which broke `05243_query_condition_cache_top_k_parquet`) or made
from the reduced filter, so queries that differ only in such a conjunct shared entries and lost rows of
the result. The rows these conjuncts drop after the format decide the TopK threshold too, so the key
must cover the whole filter of the step.

Closes: #124975

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [975ae45]

Summary: ✅


AI Review

Summary

This PR restores the Hive/virtual-column split for file-like format pushdown and fixes the TopK query-condition-cache keying so virtual/hive conjuncts do not alias cache entries. That addresses the original Parquet wrong-results bug and the follow-up indexHint hole, but there is still one correctness gap in the Iceberg path: row-lineage virtuals are treated as format-readable for every Iceberg* table even though the reader-side materialization is only wired up for Parquet.

Findings

⚠️ Majors

  • [src/Processors/QueryPlan/ReadFromObjectStorageStep.cpp:161] getFormatFilter(..., keep_row_lineage_columns = configuration->isIcebergConfiguration()) keeps _row_id / _last_updated_sequence_number in the pushed-down filter for all Iceberg tables, but StorageObjectStorageSource::getMaterializedRowLineageColumns only materializes them from the file when the actual data-file format is Parquet. On Iceberg tables backed by ORC / Avro (or mixed-format tables), the filter can still prune by a physical same-named column, reintroducing silent wrong results for row-lineage predicates.
    Suggested fix: gate the special-case on the actual file-format capability (or reuse a shared helper) instead of the coarse isIcebergConfiguration() check.
Final Verdict

Not ready to merge: the Iceberg row-lineage exception needs to be narrowed to the formats that really materialize those columns inside the reader.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 9, 2026
alexey-milovidov and others added 3 commits October 10, 2026 16:21
…ts on columns added after the format

`indexHint` keeps its arguments in its own DAG, so `getFormatFilter` did not see that
`indexHint(key = 9)` or `indexHint(_file = ...)` read a Hive partition or virtual column,
and kept it in the filter pushed into the format, which could prune row groups by the
data file's column of the same name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…column` for the `indexHint` cases

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only CI failure, Stateless tests (arm_asan_ubsan, azure, sequential), is the job hitting its 9000 s timeout at test 1175/1180 with no failed tests (https://s3.amazonaws.com/clickhouse-test-reports/PRs/124991/cabc19cc33c10e044a6e0021e85f93f25281f2ef/pr/stateless_tests_arm_asan_ubsan_azure_sequential/job.log). It is unrelated to this change and is being addressed by #123849. Pushed a fix for the indexHint review comment and merged master.

/// Iceberg reads the row lineage columns from the data file.
auto format_filter_info = std::make_shared<FormatFilterInfo>(
info.formatReadsHivePartitionColumns() ? nullptr : filter_actions_dag,
info.getFormatFilter(filter_actions_dag, /*keep_row_lineage_columns=*/ configuration->isIcebergConfiguration()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keep_row_lineage_columns gate is too broad here. This now keeps _row_id / _last_updated_sequence_number in the pushed-down format filter for every Iceberg* table, but StorageObjectStorageSource::getMaterializedRowLineageColumns only treats those columns as format-read when the actual data file format is Parquet (object_info->getFileFormat().value_or(configuration->format) == "parquet").

For Iceberg tables backed by ORC / Avro (or mixed-format tables), those columns are still added after the format, so keeping their conjuncts in getFormatFilter can prune by a physical same-named column or by values the reader never materializes. That reintroduces the same wrong-results bug for row-lineage filters on non-Parquet files. Please gate this on the real file-format capability (or share a helper with getMaterializedRowLineageColumns) instead of isIcebergConfiguration().

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 975ae455a with master ed30948f0 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

7 object files changed (+17.52 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/prepareReadingFromFormat.cpp.o 293.39 KiB 310.05 KiB +16.66 KiB (+5.68%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

146 translation units recompiled, 1485 s compile time in total, 146 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +74.2 s (+5%) in total before that adjustment.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 11, 2026
Merged via the queue into master with commit 5edd158 Oct 11, 2026
164 checks passed
@alexey-milovidov
alexey-milovidov deleted the revert-revert-123903-with-top-k-cache-fix branch October 11, 2026 02:49
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 11, 2026
qoega added a commit to qoega/ClickHouse that referenced this pull request Oct 11, 2026
Bring in the Parquet query-condition-cache fix and the replicated query-log test correction.

Related: ClickHouse#124991
Related: ClickHouse#124928
Related: ClickHouse#124490
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 11, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Oct 12, 2026
Cherry pick #124991 to 26.8: Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix)
robot-clickhouse added a commit that referenced this pull request Oct 12, 2026
…ning by the data file's column of the same name (revert of revert with a fix)
alexey-milovidov added a commit that referenced this pull request Oct 12, 2026
…e conflicts

The release branch lacks the prerequisites the original change was built on:
the TopK query condition cache of `ReadFromFile`
(`makeTopKQueryConditionCacheKey`) and `formatReadsHivePartitionColumns`
from #123381. So only the fix
itself is backported:

- `ReadFromFormatInfo::getFormatFilter` drops the conjuncts on Hive partition
  and virtual columns from the filter passed to the format, and is used by
  `ReadFromFile`, `ReadFromURL` and `ReadFromObjectStorageStep`.
  `formatReadsHivePartitionColumns` is not needed: on 26.9 the format header
  never contains a Hive partition column.
- `FormatFilterInfo::hasFilter` also covers the row-level filter and PREWHERE
  and is used for the row count cache of object storage reads.

`FormatFilterInfo::computeConditionHash` and the test
`05353_query_condition_cache_top_k_virtual_column_conjunct` only concern the
TopK query condition cache, which does not exist on 26.9, so they are dropped.

Original pull request: #124991

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll2 added a commit that referenced this pull request Oct 12, 2026
Cherry pick #124991 to 26.9: Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix)
robot-clickhouse added a commit that referenced this pull request Oct 12, 2026
…ning by the data file's column of the same name (revert of revert with a fix)
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 12, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 12, 2026
Backport #124991 to 26.8: Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix)
clickhouse-gh Bot added a commit that referenced this pull request Oct 12, 2026
Backport #124991 to 26.9: Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.8-must-backport

Projects

None yet

5 participants