Skip to content

Fix Iceberg manifest-list pruning skipping NULL partitions for ifNull/coalesce filters - #130158

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-iceberg-manifest-list-pruning-nullable-key
Nov 8, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-iceberg-manifest-list-pruning-nullable-key

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130040
Related: #129929
Related: #128575

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

On master, an Iceberg table with one manifest holding both a NULL and a non-NULL partition value returns [] for
WHERE ifNull(b, 0) IN (0) instead of the NULL row; coalesce(b, 0) IN (0, 1), assumeNotNull(b) IN (0) and
NOT (ifNull(b, 0) >= 5) behave the same. #129929 introduced it (its merge returns [], its first parent the row) and it is in
no release, hence Not for changelog.

Root cause. #129929 evaluates a field whose summary contains NULL as [lower, +inf], but buildPartitionKeyFromSpec
strips Nullable from the key columns. For a non-Nullable type ifNull, coalesce and assumeNotNull report themselves
monotonic, the +inf bound stays untransformed, and [5, +inf] against the set {0} prunes the manifest.

The change. The manifest-list pruner builds its key with the source columns' own types (keep_nullable), as MergeTree's
min-max index does for a Nullable partition column, so those functions see a NULL-able range and decline. NULL-rejecting
filters still prune on the lower bound. The file-level pruner keeps its key unchanged.

Validation. New test 05573_iceberg_manifest_list_pruning_null_partition_ifnull (13 arms: the functions above, String,
day and bucket fields, and sentinels that pin the manifest-prune counts) fails on master and passes here; 50 randomized runs
green. Three asserts in #129929's test_manifest_list_partition_pruning.py (fails on master), and the
test_storage_iceberg_with_spark pruning modules pass (33/33).

Not changed here: has([NULL, 1], b) from the issue still returns [] because the file-level pruner drops it (26.9 and 26.10
do the same; a separate, pre-existing defect). A decreasing function inside, such as ifNull(-b, 0) IN (0), additionally
needs #128575, which makes ifNull/coalesce/assumeNotNull decline a NULL stand-in on the left bound too.


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

Version info

  • Merged into: 26.11.1.1702-master (included in 26.11 and later)
  • Backported to: 26.10.11.3

…/coalesce

ClickHouse#129929 evaluates a partition field whose manifest-list summary contains NULL
as the range [lower, +inf] (NULL sorts last). The key that range is checked
against comes from buildPartitionKeyFromSpec, which strips Nullable from every
source column. For a non-Nullable type ifNull, coalesce and assumeNotNull report
themselves monotonic, so the +inf bound is left untransformed and e.g.
[5, +inf] against the set {0} for `ifNull(b, 0) IN (0)` prunes the manifest that
holds the NULL row.

Build the manifest-list pruner's key with the source columns' own types
(keep_nullable), the convention MergeTree's min-max index uses for a Nullable
partition column. Those functions then see a range that can hold NULL and
decline, while NULL-rejecting predicates keep pruning on the lower bound. The
file-level pruner keeps the stripped key.

Rejected: evaluating with Nullable data_types against the non-Nullable key
(chain functions would receive a type they were not built for); the whole
universe for every NULL-bearing field (loses the lower-bound pruning ClickHouse#129929
added and tests).

Closes ClickHouse#130040

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

groeneai commented Nov 8, 2026

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

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (1 finding below).

# Sev Finding Verdict Evidence / action
1 ⚠️ ifNull(-b, 0) IN (0) still skips the NULL-bearing manifest: negate is monotonic on [5, +inf], the inversion moves the NULL stand-in to the left bound, and ifNull checks only the right one DISAGREE (separate PR) The missing guard is in ifNull/coalesce/assumeNotNull and is fixed by #128575, which also covers Nullable MergeTree keys; the Nullable key from this PR is what lets that guard apply to Iceberg. Stated in the description.

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

Session id: cron:clickhouse-review-slot-8:20261108-140100

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One IcebergLocal INSERT of (5, 1), (NULL, 2) with iceberg_insert_single_manifest_for_all_partitions = 1, then WHERE ifNull(b, 0) IN (0) returns [] on master every time.
b Root cause explained? #129929 models a NULL-bearing summary as [lower, +inf], but the manifest-list pruner's key has Nullable stripped, so ifNull/coalesce/assumeNotNull claim monotonicity, +inf stays untransformed and the manifest with the NULL row is pruned.
c Fix matches root cause? Yes. The pruner's key keeps the source columns' Nullable types, so the key type matches the values its range can hold; the functions and KeyCondition are unchanged.
d Test intent preserved / new tests added? New stateless test (13 arms incl. manifest-prune sentinels and day/bucket transforms) and 3 asserts in the existing test_manifest_list_partition_pruning.py; no existing assertion changed.
e Both directions demonstrated? Yes. The new test fails on master and on a mutant that passes keep_nullable = false, passes with the fix; the integration test fails on master, passes with the fix. #129929's merge gives [], its first parent [2].
f Fix is general across code paths? Both users of ManifestListPruner (reads and estimateRead) share the fixed key. The file-level pruner keeps its key; its separate has([NULL, x], col) defect is pre-existing on 26.9/26.10 and not changed here.
g Fix generalizes across inputs (params/datatypes/wrappers)? Int64 and String identity fields, day transform over DateTime64(6, 'UTC'), bucket transform; IN sets, = 0 with the coalesce rewrite off, NOT (... >= 5); a NULL-free manifest next to a NULL-bearing one. Sentinels keep their prune counts.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or persisted state changes; only manifest-list pruning decisions for Nullable source columns become correct.
i Invariants and contracts preserved? The key is built and evaluated with the same types, so every chain function still gets the argument type it was built for. Bound decoding strips Nullable itself and is unchanged.

Session id: cron:clickhouse-impl-slot-40:20261108-124400

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @hanfei1991, could you review this and add the can be tested label so CI runs? The manifest-list pruner now builds its partition key with the source columns' Nullable types, so ifNull/coalesce/assumeNotNull no longer claim monotonicity over the [lower, +inf] range that #129929 uses for a NULL-bearing field, and the manifest holding the NULL partition is no longer skipped.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [847fdcc]

Summary: ✅


AI Review

Summary

Preserves Nullable types in Iceberg manifest-list partition keys so filters such as ifNull(b, 0) IN (0) retain matching NULL partitions. Reviewed PR head 847fdcc0919ae3b185591c4d89652fcf252e5602, the full diff and all prior discussion; no actionable findings. Consumers traced include IcebergIterator, IcebergMetadata::estimateRead, bound decoding, KeyCondition monotonic-function chains and MergeTreeSetIndex: these accept the retained nullability, while file-level pruning keeps its existing key types. The added stateless and Spark assertions cover the reported regression and preservation of lower-bound pruning.

Missing context / blind spots
  • ⚠️ No runnable ClickHouse build is available in this checkout, so tests were not independently rerun. The author reports failing-before/passing-after validation; the fetched targeted CI report has no results for the new regression yet. A completed targeted CI run would provide independent runtime confirmation.
Final Verdict

Status: ✅ Approve. No new inline findings to post.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 847fdcc09 with master cfd94299b (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.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 8, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 8, 2026
…s set holds NULL

The data-file partition key is built from removeNullable(source type), and
ManifestFilesPruner evaluates a NULL partition value as the single point +inf.
For a non-Nullable key KeyCondition drops every NULL set element, so
has([NULL, 1], b) became {1}, nothing matched +inf, and the data file of the
NULL partition was skipped. Dropping the NULL element is exact only for a
partition tuple without NULL.

The pruner now also builds the same key over Nullable inputs, with its own
condition, and uses that pair only for a partition tuple holding NULL in a
Nullable key position (a void field has type Tuple() and never selects it).
Every other tuple keeps the existing key and condition.

A Nullable key for every file is not used: for an untyped set holding NULL,
such as [NULL, 5] (Array(Nullable(UInt8))), the has() atom is declined for a
Nullable(Int64) key (not safely castable, and canBeInsideNullable() is false
for a Nullable key), so files of tables without a NULL partition would no
longer be pruned. Accepting a Nullable key at that KeyCondition guard would
give the untyped set the typed shape that the Parquet row-group filter still
gets wrong (ClickHouse#128570, ClickHouse#128575), and is MergeTree-wide.

The manifest-list pruner (master only) is fixed separately by ClickHouse#130158.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged via the queue into ClickHouse:master with commit 191bbbd Nov 8, 2026
374 of 375 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@groeneai @alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 19, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 19, 2026
Cherry pick #130158 to 26.10: Fix Iceberg manifest-list pruning skipping NULL partitions for `ifNull`/`coalesce` filters
robot-clickhouse added a commit that referenced this pull request Nov 19, 2026
… NULL partitions for `ifNull`/`coalesce` filters
robot-clickhouse added a commit that referenced this pull request Nov 19, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #130158 to 26.10: Fix Iceberg manifest-list pruning skipping NULL partitions for `ifNull`/`coalesce` filters
@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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg: coalesce(col, 0) IN (0) loses NULL-partition rows to manifest pruning

7 participants