Skip to content

Use partition statistics from manifest list for pruning - #115817

Merged
scanhex12 merged 11 commits into
masterfrom
iceberg-manifest-list-partition-pruning
Sep 10, 2026
Merged

scanhex12 merged 11 commits into
masterfrom
iceberg-manifest-list-partition-pruning

Conversation

@scanhex12

@scanhex12 scanhex12 commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Iceberg manifest list contains statistics like lower_bound, upper_bound, and etc that can be used for pruning. This PR use them to prune data. Closes #104567


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

Version info

  • Merged into: 26.9.1.1103 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd9a0ea]

Summary: ✅


AI Review

Summary

Adds manifest-list partition pruning for Iceberg by caching each manifest entry's partition summaries and skipping manifests whose summaries cannot satisfy the query filter, behind use_iceberg_manifest_list_partition_pruning. The direction is good, but the current implementation still has three meaningful gaps: nullable summaries lose valid pruning, historical mixed-spec manifests stop benefiting once a dropped partition source column disappears from the current snapshot schema, and merge-on-read tables still decode every delete manifest before returning the first row. Status is request changes.

PR Metadata
  • Changelog category: Performance Improvement matches the change.
  • Changelog entry: required, but it is too vague and folds the issue link into the text that goes to CHANGELOG.md. Suggested replacement: Iceberg reads can now prune whole manifest files from the manifest list's partition summaries before opening them, controlled by use_iceberg_manifest_list_partition_pruning.
  • Put Closes: https://github.com/ClickHouse/ClickHouse/issues/104567 on its own relation line above the template instead of inside the changelog entry.
Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp:83] contains_null widens the lower edge to NEGATIVE_INFINITY even when the manifest declares concrete non-null bounds. Under ClickHouse's NULL_LAST ordering the safe interval is [lower_bound, +inf], so manifests like {NULL, 100} stop being skipped for filters such as WHERE p = 0 or WHERE p < 50. Keep the lower bound and only widen the upper edge when nulls are present.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp:42] Conditions are built once per partition_spec_id against a single schema_id_on_snapshot_commit, so historical manifests from an older snapshot schema lose manifest-list pruning as soon as a dropped partition source column disappears from the current snapshot schema. A table evolved from (region, day(ts)) to day(ts) after DROP COLUMN region will never prune the old manifests here even for ts filters that their summaries can still disprove. This needs schema-aware conditions plus field-to-summary index mapping, or an explicit fail-closed limitation with regression coverage.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp:360] The new setting only skips data manifests. next still calls ensureDeletesReady() first, and decodeDeleteManifests then opens every delete manifest on merge-on-read tables, so partition-filtered queries still block on exactly the metadata-heavy path this PR is trying to avoid. Apply the same manifest-list predicate to delete manifests, or narrow the setting/docs to data manifests and add a merge-on-read regression test.
Tests
  • ⚠️ Add a focused nullable-partition regression where a manifest mixes NULL and concrete values, then assert a filter below the non-null lower bound still skips the manifest.
  • ⚠️ Add a mixed-spec regression covering DROP PARTITION FIELD ... followed by DROP COLUMN ..., so the intended contract for historical manifests is explicit.
  • ⚠️ Add a merge-on-read Iceberg test with multiple delete manifests and a partition filter; it should prove that use_iceberg_manifest_list_partition_pruning either skips irrelevant delete manifests or is documented as data-only.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: fix the nullable-summary range construction, and either complete the new pruning path for historical/delete manifests or explicitly narrow the supported contract and tests around those cases.

LLVM Coverage Report

⚠️ No coverage measurement for commit cd9a0ea: incomplete coverage measurement: 1 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_it_7.profdata.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 21, 2026
@scanhex12
scanhex12 force-pushed the iceberg-manifest-list-partition-pruning branch from 9e977fa to f0cd374 Compare August 21, 2026 15:55
@scanhex12
scanhex12 force-pushed the iceberg-manifest-list-partition-pruning branch from d440fb9 to c107b49 Compare August 21, 2026 16:08
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 40 queries analysed

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
  • StressHouse run: 6697530d-4e22-4a67-a5fe-7a6fc9c3ccee
  • MIRAI run: 8d7921de-edb7-4902-a246-7e65441b81fe
  • PR check IDs:
    • clickbench_153994_1788997591
    • clickbench_154007_1788997591
    • clickbench_154013_1788997591
    • tpch_adapted_1_official_154024_1788997591
    • tpch_adapted_1_official_154050_1788997591
    • tpch_adapted_1_official_154064_1788997591

@SmitaRKulkarni SmitaRKulkarni self-assigned this Aug 24, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
Resolve the conflicts with the Iceberg changes that landed on `master`
meanwhile, and fix the two CI failures of the pull request:

- `master` replaced the prefetching `SingleThreadIcebergKeysIterator`
  with the concurrent `DataFileEntriesStream`, so the manifest list
  pruning is re-applied there: the stream takes a `SkipManifest`
  predicate, and `ManifestListPruner` is built in the stream's `prepare`
  callback, after `buildOrderedSetsForDAG`, because the key conditions
  of the pruner are built over the filter DAG.
- `master` added row lineage columns to the filter DAG transformation
  and the manifest partition tuple arity check, so
  `renameFilterDagColumnsToFieldIds` and `buildPartitionKeyFromSpec`
  carry them over from the member function this branch extracted them
  from.
- The binary bound decoding, which this branch moved into
  `IcebergFieldParseHelpers`, keeps the `compensate_rounding` flag and
  the overflow rejection that `master` gained in the meantime, and
  `ManifestFileIterator` uses that single shared implementation.
- `ManifestFileCacheKey` carries both the partition summaries of this
  branch and `first_row_id` of `master`.

Build (arm_tidy) failed with `performance-move-const-arg`:
`KeyDescription` has a user-declared copy constructor and hence no move
constructor, so the `std::move` of it in `ManifestListPruner` is
dropped.

Style check failed because `use_iceberg_manifest_list_partition_pruning`
was recorded in the `26.8` block of `SettingsChangesHistory.cpp` while
the current version is `26.9`; the entry is moved to the `26.9` block.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115817&sha=a23f9bd482b562de33ac5ecdbd7b555e812944e4
Related: #115817

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cd9a0ea0a with master b75d29e7d (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

31 object files changed (+223.62 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp.o new 109.35 KiB +109.35 KiB
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp.o 351.56 KiB 284.68 KiB -66.88 KiB (-19.02%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp.o 191.55 KiB 250.88 KiB +59.32 KiB (+30.97%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/StatelessMetadataFileGetter.cpp.o 191.35 KiB 223.20 KiB +31.86 KiB (+16.65%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp.o 342.85 KiB 372.57 KiB +29.72 KiB (+8.67%)
src/CMakeFiles/dbms.dir/Planner/Utils.cpp.o 278.30 KiB 306.51 KiB +28.21 KiB (+10.14%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergFieldParseHelpers.cpp.o 51.16 KiB 71.95 KiB +20.79 KiB (+40.65%)

716 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

78 translation units recompiled, 764 s compile time in total, 77 of them have a recent master baseline.

Job report

scanhex12 and others added 3 commits September 8, 2026 13:14
Skipping a manifest through its manifest-list partition summaries also skips
every data file it lists, but only `IcebergPartitionPrunedManifestFiles` was
incremented, so `IcebergPartitionPrunedFiles` dropped to zero exactly when
pruning got better. That is what broke `test_partition_pruning` and
`test_optimize_manifest_files_decimal_partition`: both measure pruning through
that counter, and both hit tables whose manifests hold a single partition each
(one written by a later `INSERT`, the others produced by `OPTIMIZE ... MANIFEST`,
which clusters entries by partition). The skipped manifest's `live_files_count`
is now added to the file counter, which is also what keeps the counter working
once ClickHouse starts writing partition summaries of its own.

Manifest-list pruning is also gated on `use_iceberg_partition_pruning`, as the
description of `use_iceberg_manifest_list_partition_pruning` already states. It
was only checking its own setting, so a query that switched partition pruning
off still had manifests skipped under it, and the reference run of the pruning
tests would have counted skipped files.

The test of the feature now pins both counters and the interaction with
`use_iceberg_partition_pruning`.
`deserializeFieldFromBinaryRepr` hands the bound bytes to `IColumn::insertData`,
which for a fixed-size column ignores the length and reads the width of the type.
Iceberg stores a bound as it was written, so after an `int` -> `long` promotion of
a partition column the manifest list keeps a 4-byte bound for a column that is
`Int64` now, and reading it produced a garbage bound out of 4 bytes past the
buffer. Under MSan that killed the server, which is how the `amd_msan` shard
reported it: every `test_partition_pruning` query after
`ALTER TABLE ... ALTER COLUMN tag TYPE BIGINT` failed with a network error.

A bound narrower than the type is reported as absent now, so such a manifest is
not pruned instead of being pruned by a bound made of uninitialized memory.

Reproduced locally with the MSan build of the previous commit: the added test
kills the server without this fix and passes with the bound treated as absent.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115817&sha=5036ffab8829347b65f9eaf727b236301b416ad8&name_0=PR
PR: #115817

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
if (!fields || fields->size() == 0)
continue;

auto partition_key = buildPartitionKeyFromSpec(fields, partition_schema_id_, schema_processor_, context);

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.

This builds one manifest-list condition per partition_spec_id against a single partition_schema_id_, but a current snapshot can still reference manifests that were added under an older snapshot schema. In that case buildPartitionKeyFromSpec drops any source field that no longer exists in partition_schema_id_, and the arity check here disables manifest-list pruning for the whole historical spec.

A concrete case is a mixed-spec table like (region, day(ts)) after DROP PARTITION FIELD region and then DROP COLUMN region: queries on ts can still be pruned from the old manifests' summaries, but this code never builds a usable condition for that spec. Since ManifestFileCacheKey already carries added_snapshot_id and IcebergSchemaProcessor tracks snapshot_id -> schema_id, I think this needs schema-aware conditions (or at least a regression test that documents the limitation).

Manifest-list partition pruning skips a manifest by the partition summaries
the manifest list carries, and reports the files it skips through
`IcebergPartitionPrunedFiles`. `05045_iceberg_manifest_partition_arity`
patches the `partition-spec` header of the manifests but never the manifest
list, so with the new pruning on the A7 and A8 probes were answered before the
patched manifest was ever read: their counters went from 0 to 1 and the arms
stopped saying anything about the pruner they were written for - in particular
that a partition key narrower than the tuple is not realigned onto the wrong
value.

Turn `use_iceberg_manifest_list_partition_pruning` off for those probes, and
add A9 to pin the new behaviour instead of losing it: the manifest list prunes
both tables before their patched manifests are read, and the rows that survive
are still the right ones.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115817&sha=083fda43bd9d54e6dd600ab963dced915957c53f&name_0=PR
Related: #115817

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
[this](const ManifestFileCacheKey & manifest_list_entry)
{
if (!manifest_list_pruner
|| !manifest_list_pruner->canBePruned(manifest_list_entry.partition_spec_id, manifest_list_entry.partition_summaries))

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.

use_iceberg_manifest_list_partition_pruning is only wired into data_files_stream, but next still calls ensureDeletesReady() first and decodeDeleteManifests() then walks every delete manifest unconditionally. On merge-on-read tables a partition-filtered query therefore still blocks on opening all delete manifests, even though the manifest list already carries partition_spec_id / partition_summaries for those entries and ManifestFilesPruner already applies partition pruning to delete-file entries after decode.

I think the new setting needs the same manifest-list skip on the delete-manifest path, or its contract/docs need to be narrowed to say it only affects data manifests. As written, the improvement disappears on the row-level-delete tables that also tend to accumulate the most delete manifests.

Conflict in `ManifestFileIterator.cpp`: this branch moved `deserializeDecimalBound` and
`deserializeFieldFromBinaryRepr` into `IcebergFieldParseHelpers` so that `ManifestListPruning`
can use them too, while master kept its own copies inline and gave
`getMaterializedRowLineageRange` an extra `path_to_manifest_file` argument. Resolved by keeping
master's signature, which is what the caller in this file now passes, and dropping master's
inline copies of the two helpers, which would otherwise clash with the ones this file already
includes from `IcebergFieldParseHelpers.h`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
upper = deserializeFieldFromBinaryRepr(*summary.upper_bound, type, false);
}

left_keys[i] = (lower.has_value() && !summary.contains_null) ? FieldRef(*lower) : FieldRef(NEGATIVE_INFINITY);

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.

contains_null means the manifest may also contain NULL, but the non-null values are still bounded by lower_bound / upper_bound. Under the same NULL_LAST convention used in ManifestFilesPruner, the safe interval for a summary like {NULL, 100} is [100, +inf], not (-inf, +inf).

Widening the left edge to NEGATIVE_INFINITY here drops valid pruning for predicates below the first non-null value (WHERE p = 0, WHERE p < 50, and so on), so nullable partition columns stop benefiting from manifest-list pruning whenever a manifest mixes NULL and concrete values. Please keep the decoded lower bound when contains_null is true and only widen the upper edge to POSITIVE_INFINITY.

@scanhex12
scanhex12 added this pull request to the merge queue Sep 10, 2026
Merged via the queue into master with commit 6233914 Sep 10, 2026
175 checks passed
@scanhex12
scanhex12 deleted the iceberg-manifest-list-partition-pruning branch September 10, 2026 06:43
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 10, 2026

@SmitaRKulkarni SmitaRKulkarni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 4, 2026
Antalya 26.8 - Backport of ClickHouse#114817 - Use partition statistics from manifest list for pruning- ClickHouse#115817
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Nov 7, 2026
… NULL partition value

`ManifestListPruner::canBePruned` passed the per-field partition summaries of a
manifest-list entry to `KeyCondition::mayBeTrueInRange`, which treats the two key
vectors as the ends of a range of tuples, and replaced the bounds of a field that
contains NULL with -inf/+inf. The tuple decomposition evaluates a later field over the
non-Nullable key type's universe, which excludes NULL, everywhere except next to the
boundary values of the earlier fields. So on a table partitioned by `a, b`,
`WHERE a = 2 AND b IS NULL` was judged impossible for a manifest with `a` in [1, 3] and a
NULL `b`, and the manifest was skipped: no rows instead of the matching ones. With NULL
also in `a`, no real value of `a` could pair with a NULL `b` at all (the fuzzer's shape).
PyIceberg and Spark write one manifest per commit covering all its partitions, so this
hits ordinary tables at default settings since 26.9 (ClickHouse#115817).

Iceberg `field_summary` bounds each field independently, so the manifest's partition
tuples lie in the box of the per-field ranges. Evaluate exactly that box with
`KeyCondition::checkInHyperrectangle`: `[lower, upper]`, or `[lower, +inf]` when the field
contains NULL (NULL sorts last, the encoding `ManifestFilesPruner` uses for a NULL
partition value), or the whole universe when the bounds are missing, NaN, undecodable or
inverted. For NULL-free summaries the box is inside the old tuple range, so no correct
prune is lost, and the bounds of fields after the first are now used too.

Found by the Data lake fuzzer (arm_release), NightlySQLancer, master 2332693,
pyiceberg_rest seed 228157089.

Closes ClickHouse#129913

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

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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: prune manifest files at the manifest-list level using the partitions summary

6 participants