Skip to content

Skip Iceberg data files by JOIN runtime filters - #128145

Merged
murphy-4o merged 8 commits into
ClickHouse:masterfrom
groeneai:iceberg-join-runtime-filter-file-pruning
Nov 11, 2026
Merged

murphy-4o merged 8 commits into
ClickHouse:masterfrom
groeneai:iceberg-join-runtime-filter-file-pruning

Conversation

@groeneai

@groeneai groeneai commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #128108
Depends on: #128128

Changelog category (leave one):

  • Performance Improvement

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

Iceberg reads skip data files that cannot match a JOIN runtime filter. Controlled by the new setting use_join_runtime_filters_for_iceberg_pruning, enabled by default.

Description

JOIN runtime filters skip MergeTree granules, but an Iceberg read only filtered rows with them after opening every data file.

  • collectAppliedJoinRuntimeFilters now also registers the runtime filters on ReadFromObjectStorageStep, which hands them to the file iterator (IObjectIterator::setJoinRuntimeFilters).
  • Once the filters are built, IcebergIterator skips data files whose manifest min/max bounds exclude every key (key IN (...) or the key range). Files requested earlier are read as before.
  • New profile event IcebergRuntimeFilterPrunedFiles.

Needs #128128 first: without it, a key under two casts would prune with the wrong predicate.

TPC-DS SF1 on Iceberg, sales tables partitioned by icebergTruncate(30, sold_date_sk): all 99 queries 23.3 s → 16.2 s (q42 57 → 24 ms, 240 of 254 files skipped; q72 869 → 252 ms). Queries that skip nothing: 0.97–1.06x.

Not covered: other data lakes, plain Parquet files, cluster table functions.


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

Version info

  • Merged into: 26.11.1.1920-master (included in 26.11 and later)

groeneai and others added 2 commits October 29, 2026 12:17
A hash JOIN records the build-side keys (or their range) in a runtime filter,
and MergeTree prunes granules by them. An Iceberg read only filtered rows with
it after opening every data file: the read step's filter is fixed by
applyFilters before tryAddJoinRuntimeFilter adds the __applyFilter step, and
collectAppliedJoinRuntimeFilters registered the applied filters on
ReadFromMergeTree only.

collectAppliedJoinRuntimeFilters now also registers them on
ReadFromObjectStorageStep, which passes them to the file iterator through
IObjectIterator::setJoinRuntimeFilters (forwarded by
ObjectIteratorWithPathAndFileFilter, a no-op for other iterators). Once every
filter is finished, IcebergIterator builds `key IN (...)` or a key range
with buildRuntimeRangePredicate and skips the data files whose manifest
bounds ManifestFilesPruner shows cannot match. Files requested before every
filter is finished are read as before. The lookup is taken from the thread's
query context, like the build side does.

findAppliedRuntimeFilters now reports whether the key sits under two or more
casts (key_under_nested_casts). The pruning predicate re-applies only one cast,
so such a key would be pruned by values of the wrong type (ClickHouse#124679); it is not
registered for object storage. MergeTree consumers do not use the field yet.

New setting use_join_runtime_filters_for_iceberg_pruning (on by default;
needs enable_join_runtime_filters_index_analysis and
use_iceberg_partition_pruning) and profile event
IcebergRuntimeFilterPrunedFiles. A perf query on tpch_ice10.lineitem joins on
l_shipdate with a few days on the build side (83 of 84 files skipped).

Analysis and first version of the patch in ClickHouse#128108.

Closes ClickHouse#128108

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the RuntimeFilterFilePruning class comment and the addJoinRuntimeFilterIndexAnalysisOnDataRead doc; drop the getPruner and runtime_filter_pruning member comments that restate the code.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 rounds, 7 findings) plus my own review (1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ (own) A floating-point key could skip a data file holding a NaN row the join matches withdrawn A Spark-written table shows no skip: KeyCondition::setElementsContainNaN declines an IN set holding NaN, and floats get no range predicate; a NaN-free set matches no NaN row
2 ⚠️ The predicate was built from the first finished filters, so a filter finished later was never used AGREE, fixed getPruner waits for every filter
3 ⚠️ The test did not cover a key under one cast or concurrent reads, and asserted only > 0 AGREE, fixed one-cast case E, 4-thread case A4, exact counts (constant over 50 randomized runs)
4 💡 enable_join_runtime_filters_index_analysis text described only MergeTree AGREE, fixed one paragraph added
5 ❌ A key CAST(f.x AS Int64) can skip a file holding NaN whose scan would throw DISAGREE No result row is lost: CAST(nan AS Int64) throws CANNOT_CONVERT_TYPE, and the static Iceberg pruner skips the same file for WHERE CAST(x AS Int64) = 7. NaN missing from Iceberg bounds is #118112, fixed in ManifestFilesPruner by #126078
6 ⚠️ The test cannot detect the first-ready-filter caching DISAGREE A two-filter join with a slow build side skips 15 files in 20 of 20 runs before and after the change, at 1 and 4 threads: the probe side requests files only after every build side finishes, so no deterministic query separates the two
7 💡 join_algorithm is not pinned in the test AGREE, fixed join_algorithm = 'hash' pinned
8 ❌ With CAST(k AS UInt8) = b.k and a UInt64 common type, MergeTree granule pruning still drops rows DISAGREE (separate PR) This is #124679 on master; the MergeTree registration is unchanged by this PR. #128128 fixes it for every consumer of findAppliedRuntimeFilters; this PR leaves such keys out of Iceberg pruning (test case C)

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05457_iceberg_join_runtime_filter_file_pruning: with the setting off every one of the 16 data files is opened (IcebergRuntimeFilterPrunedFiles = 0); TPC-DS q42 on date-partitioned Iceberg reads 254 files off, 14 on.
b Root cause explained? ReadFromObjectStorageStep's filter is fixed by applyFilters before tryAddJoinRuntimeFilter adds the __applyFilter step, and collectAppliedJoinRuntimeFilters registered runtime filters on ReadFromMergeTree only, so IcebergIterator pruned by the static filter alone.
c Fix matches root cause? Yes: the applied runtime filters are registered on the object-storage read step and handed to the file iterator, which checks each data file's manifest bounds with the existing buildRuntimeRangePredicate + ManifestFilesPruner.
d Test intent preserved / new tests added? New stateless test with exact skipped-file counts (exact set, range, through the path-filter wrapper, 4 threads, one cast, nested casts, Nullable key, LEFT ANTI; on/off results equal; join_algorithm pinned to hash). Mutations: pruning disabled -> 4 lines red; wrapper forward removed -> only the wrapper case red; nested-cast guard removed -> the cast case loses 6 of 7 rows; guard tightened to one cast -> only the one-cast count red.
e Both directions demonstrated? Yes, same binary with the setting on/off, and the three mutants above; 50/50 randomized runs green.
f Fix is general across code paths? The only wrapper between the step and a data-lake iterator (ObjectIteratorWithPathAndFileFilter) forwards the filters; other iterators keep a no-op. Delta Lake, Hudi, Paimon and plain Parquet are not covered (no pruning, unchanged results).
g Fix generalizes across inputs (params/datatypes/wrappers)? 42-case matrix with pruning on, off and without runtime filters, all equal: INNER/RIGHT/LEFT/FULL/SEMI/ANTI, multi-key, 3-way, computed key, Int32/Int64, UInt8 casts, >10,000 keys, empty build side, NaN/-0.0, truncated string bounds, LowCardinality, Date, Decimal(38, 10), Array, Nullable, <=>, _file, deletes, renamed column, grace/parallel hash, max_threads 1/8.
h Backward compatible? (maintainer-approved exception only) New setting use_join_runtime_filters_for_iceberg_pruning (history entry 26.11 false -> true; 0 restores the old behaviour) and a new profile event. No format change.
i Invariants and contracts preserved? A data file is skipped only when no row in it can pass every runtime filter applied to the read: only top-level __applyFilter conjuncts on a bare key, only once every filter is finished (until then nothing is skipped), only DATA entries; delete files still attach to the files that are read.

Session id: cron:clickhouse-impl-slot-6:20261029-121200

@clickhouse-gh

clickhouse-gh Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dcced38]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

The PR lets Iceberg reads skip data files using completed JOIN runtime filters, with a setting to restore the previous behavior. No unresolved findings remain in head dcced38d05b25badceb1aa8f922e033eada120ac. The earlier nested-cast issue is addressed by the included prerequisite, #128128. The focused regression test and the before/after measurements in #128108 support the correctness and performance claims.

Missing context / blind spots
  • ⚠️ The latest head's CI rerun is still in progress, and no local build or tests were run during this review. The earlier targeted ASan/UBSan report records 44 successful runs of 05457_iceberg_join_runtime_filter_file_pruning; completing the current head's test jobs will confirm the final merge adjustments.
Final Verdict

Status: ✅ Approve. No new inline findings; final-head CI remains pending.

@groeneai

This comment was marked as resolved.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 29, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 29, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit dcced38d05b25badceb1aa8f922e033eada120ac with master failed: LogClusterNotReady: the endpoint never became ready.

See the job log for details.

@groeneai

This comment was marked as resolved.

murphy-4o and others added 2 commits November 6, 2026 11:07
- Drop the nested-cast flag from RuntimeFilterIndexAnalysisDescriptor: ClickHouse#128128
  leaves a key under two casts out of findAppliedRuntimeFilters for every
  reader, so the object storage read needs no special case.
- Annotate RuntimeFilterFilePruning state with TSA_GUARDED_BY, split the
  pruner emplace, rename unusable to no_pruning_predicate.
- Add the RuntimeFilterIndexAnalysisDescriptors alias.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@murphy-4o

This comment was marked as resolved.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - bf0ac99

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel), (arm_binary, parallel), (amd_asan_ubsan, db disk, distributed plan, targeted), (arm_asan_ubsan, targeted) and the five flaky checks / 05457_iceberg_join_runtime_filter_file_pruning needs #128128, as the PR body says: bf0ac99 drops the nested-cast exclusion that #128128 applies to every reader. Without it, case C (CAST(f.k AS UInt8) = d.k) prunes files that hold matching rows: c_on 15 instead of 0, and 1 5 instead of 7 5411. Same diff in every job, also without random settings; cases A, A4, B, D and E match #128128 (mine, open)
Mergeable Check, PR praktika rollups of the row above #128128 (the owner of the row above)
Sync - CH Inc sync (private, not actionable by me)

The other 84 jobs were dropped after these failures, so they have not run on this head. CIDB has no other FAIL or ERROR row on it.

Session id: cron:our-pr-ci-monitor:20261106-063005

@murphy-4o
murphy-4o enabled auto-merge November 10, 2026 12:56
@murphy-4o

This comment was marked as resolved.

…e-filter-file-pruning

Resolve the conflict in `collectAppliedJoinRuntimeFilters` with ClickHouse#129677,
which added `is_global_row_index` to the MergeTree registration: MergeTree
gets the new argument, object storage reads skip global row index
descriptors (`_part_starting_offset + _part_offset` is a MergeTree key,
not a column of the data files).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
auto-merge was automatically disabled November 10, 2026 17:12

Head branch was pushed to by a user without write access

@groeneai

This comment was marked as resolved.

@snelheidai

This comment was marked as resolved.

groeneai and others added 2 commits November 10, 2026 19:58
…timeFilters

The early return already makes the `else` branch an object storage read, so
this does not change behaviour: it only makes the branch say which step it is
for. Global row index descriptors are still skipped there, because their key
`_part_starting_offset + _part_offset` is the MergeTree row index and not a
column of the data files.

Review: ClickHouse#128145 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-filter-file-pruning

ClickHouse#129933 added a `PartitionSpecification` parameter to the `ManifestFilesPruner`
constructor, so the runtime filter pruner in `IcebergIterator.cpp` no longer
compiled on the merge commit (`Build (arm_tidy, 3/4)`). It passes no partition
key, and the specification is only read together with one, so pass an empty one.

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

Copy link
Copy Markdown
Collaborator Author

I merged master again (dcced38): #129933, merged today, added a PartitionSpecification parameter to the ManifestFilesPruner constructor, so Build (arm_tidy, 3/4) failed on the merge commit. The runtime filter pruner passes no partition key, so it now passes an empty specification.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - dcced38

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR: all readiness probes of the CI logs cluster timed out (Read timed out. (read timeout=3)), so the job raised LogClusterNotReady: the endpoint never became ready before comparing anything #129675 (mine, open)
PR praktika rollup of the row above #129675 (mine, open)

CH Inc sync is green, and CIDB has no FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261111-020006

@murphy-4o
murphy-4o added this pull request to the merge queue Nov 11, 2026
Merged via the queue into ClickHouse:master with commit a62d3fd Nov 11, 2026
185 of 187 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 11, 2026
murphy-4o added a commit to groeneai/ClickHouse that referenced this pull request Nov 11, 2026
…-row-group-pruning

# Conflicts:
#	src/Processors/Formats/Impl/Parquet/Reader.cpp
#	src/Processors/QueryPlan/ReadFromObjectStorageStep.cpp
#	src/Processors/QueryPlan/RuntimeFilterLookup.h
otselnik pushed a commit to otselnik/ClickHouse that referenced this pull request Nov 12, 2026
ClickHouse#128145 skips whole Iceberg data files whose manifest bounds cannot contain a key of a hash JOIN's
runtime filter. Inside the files that are read, the Parquet reader still decoded every row group:
its only statistics-based row-group pruning input is `FormatFilterInfo::key_condition`, built once
from the plan-time `filter_actions_dag`, which never contains the runtime filter (that is moved into
PREWHERE as `__applyFilter`, which `KeyCondition` cannot interpret anyway).

The read now hands the runtime filters to the format through
`FormatFilterInfo::join_runtime_filters`. Once every filter is built, one `KeyCondition` per
`FormatFilterInfo` is built from them with `buildRuntimeRangePredicate` (the `key IN (exact values)`
/ `key BETWEEN min AND max` predicate that MergeTree and ClickHouse#128145 use), on the column layout of
`key_condition`, and `Reader::prefilterAndInitRowGroups` drops the row groups whose statistics cannot
satisfy it, next to the static `key_condition` check. The probe-side reader opens its first file only
after the build side has finished (`JoiningTransform::prepare` does not pull the probe input before),
so the check at file open sees finished filters; a reader that opened a file earlier would not prune
it.

Iceberg only, gated by `use_join_runtime_filters_for_iceberg_pruning`,
`enable_join_runtime_filters_index_analysis` and `input_format_parquet_filter_push_down`; no new
setting. A file whose row groups were skipped writes no query condition cache entry (plain and TopK
keys), because the skipped row groups may still match the cached predicate. The per-file copies of
`FormatFilterInfo` carry the filters only where the reader uses the current column names: not under a
schema transform, where a current name can denote another column of the old file, and not with the
`rows_to_read` of lazy materialization. The per-file count cache needs no guard: a count of an Iceberg
table never reads it back.

New profile event `ParquetRuntimeFilterPrunedRowGroups`. Test
`05457_iceberg_join_runtime_filter_row_group_pruning`: one data file of 16 row groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg reads do not skip data files using JOIN runtime filters: star joins on date-partitioned tables open every file

6 participants