Skip to content

Use Iceberg uuid manifest bounds for pruning only when they are equal - #118380

Merged
PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-uuid-manifest-bounds
Oct 12, 2026
Merged

PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-uuid-manifest-bounds

Conversation

@groeneai

@groeneai groeneai commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #118366
Related: #118371, #118364

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 Iceberg min/max pruning skipping a data file that holds matching rows, when the file's uuid bound was written by an external engine (Spark, Trino, pyiceberg). Such a bound now prunes only when its lower and upper bounds are equal. This fixes the Iceberg manifest bounds only: the uuid statistics of the Parquet data file itself are a separate defect, so a query at default settings can still miss rows. Closes #118366.

Description

A uuid manifest bound cannot be a Range over a ClickHouse UUID column, for two reasons:

  1. The spec serializes the value as 16 big-endian bytes. deserializeFieldFromBinaryRepr raw-copies them into ColumnVector<UUID>, whose insertData does not swap, while both data paths do (decodeParquetUUID, readColumnWithUUIDFromFixedBinaryData), so the bound differs from the value a query constant produces.
  2. A conforming writer orders the bound pair by unsigned byte comparison, but ClickHouse orders UUID by its second half (docs/reference/data-types/uuid.mdx), so the declared pair is not an interval in the column's own order.

Because of 2, applying the byte swap is necessary but not sufficient. Measured with pyiceberg 0.11.1 on one data file holding

A = 00000000-0000-0000-0000-000000000001
C = 00000000-0000-0000-ffff-ffffffffffff
B = 00000001-0000-0000-0000-000000000002

the writer declares lower = A, upper = B (byte-wise A < C < B). ClickHouse orders these A < B < C: C is above the upper bound, yet A < B holds, so the inverted-pair guard does not fire. On master WHERE u = toUUID(C) returns nothing, as does a correctly byte-swapped implementation, though the file holds the row.

So the pair is dropped, as for decimal and Variant, unless its bounds are equal: that point, decoded with the swap, is exactly the value the file holds. ClickHouse-written tables lose nothing: canDumpIcebergStats returns false for UUID.

Two related surfaces are deliberately untouched. The same root cause in the Parquet reader's uuid statistics is #118371, which prunes these files' row groups too, so a default-settings query still misses C. A uuid partition column is #123961: its values are never decoded, so filtering on it throws. The manifest-list pruner shares this helper, so on such a table master's silent row loss (every manifest pruned) becomes that error; an equal-bounds summary cannot help, as the files it keeps throw too.


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

Version info

  • Merged into: 26.10.1.2221-master (included in 26.10 and later)

A SELECT over an Iceberg table with a uuid column could silently return
fewer rows than the table holds, whenever the manifests were written by a
conforming external engine (Spark, Trino, pyiceberg). No error, nothing
above DEBUG.

deserializeFieldFromBinaryRepr sent uuid down its raw-copy branch, where
ColumnVector<UUID>::insertData is data.emplace_back(unalignedLoad<T>(pos)):
no byte swap, and the length argument ignored. Two mismatches then stack.

First, the value space. The Iceberg spec serializes a uuid value as 16
big-endian bytes, while both data paths convert (decodeParquetUUID and
readColumnWithUUIDFromFixedBinaryData each reverse the two 8-byte halves
on little-endian). So the bound decoded to a different value from the one
the data path and the query constant produce.

Second, the sort order, which is why the byte swap alone is not the fix.
A conforming writer orders the lower/upper pair by unsigned big-endian
byte comparison, but ClickHouse orders UUID by its second half, on
purpose and documented. For A=...0001, C=...ffff-ffffffffffff and
B=00000001-...0002 in one data file, pyiceberg declares lower=A, upper=B
because byte-wise A < C < B. ClickHouse orders those A < B < C, so C sits
above the upper bound while A < B still holds, meaning the inverted-pair
guard does not fire either, and WHERE u = toUUID(C) prunes the very file
that holds C. A correctly byte-swapped pair loses the same row.

Since the declared pair is not an interval in the column's own order, the
bound is dropped instead: the detect-and-drop shape this function already
uses for decimal and Variant. The column contributes no pruning range and
the file is read. Nothing is lost on ClickHouse-written tables, because
canDumpIcebergStats returns false for UUID and dumpFieldToBytes has no
UUID case, so ClickHouse never wrote a uuid bound. If pruning is wanted
later, lower == upper is the only exactly sound case.

The new integration test needs three values in one data file, since a
one-row-per-file rig has lower == upper where a swap is exact and only the
byte order is exercised. It also disables the Parquet statistics
push-downs, which prune on the same UUID statistics of the data file
itself: that is a separate defect, tracked as ClickHouse#118371.

Closes: ClickHouse#118366

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Sep 6, 2026
@groeneai

groeneai commented Sep 6, 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 cold pass
over the resulting tree (1 finding, in the pull request body rather than the code).

# Sev Finding Verdict Evidence / action
1 ⚠️ The Closes: line sat inside the template's leading HTML comment, so it was not a line of the rendered description AGREE, fixed before publishing Live Closes: and Related: lines now; nothing in the diff changed

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

The issue reporter agreed with this shape
before I opened this: std::nullopt for the manifest bounds, with lower == upper as the only
sound pruning case. I left the point bound out, since it never decoded correctly either.

Session id: cron:clickhouse-review-slot-11:20260906-044000

@clickhouse-gh clickhouse-gh Bot closed this Sep 6, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [38fa997]

Summary: ✅


AI Review

Summary

This PR correctly stops treating external Iceberg data-file uuid min/max pairs as ordinary UUID ranges and restores the only sound case—an exact lower_bound == upper_bound point—on the data-file pruning path, with a focused regression test. One important sibling path is still inconsistent: manifest-list partition summaries still route UUID through deserializeFieldFromBinaryRepr, so exact UUID summaries are widened to “no bounds” instead of using the same point-interval rule.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestListPruning.cpp:74] boundsOfPartitionFieldSummary still decodes UUID partition summaries with deserializeFieldFromBinaryRepr, but deserializeFieldFromBinaryRepr now returns std::nullopt unconditionally for UUID. That means even an exact manifest-list summary (lower_bound == upper_bound) degrades to (-∞, +∞) on the ManifestListPruner path, so the sibling pruning surface does not implement the same “equal bounds are safe” rule this PR now uses for data-file min/max stats. Even setting the broader UUID partition-key issue aside, this leaves the shared manifest-metadata contract inconsistent across the two pruning consumers.
    Suggested fix: reuse deserializeUUIDPointFromBinaryRepr (or factor the pair-aware UUID decoding out once) inside boundsOfPartitionFieldSummary, and add a focused regression on a partitioned Iceberg table that exercises use_iceberg_manifest_list_partition_pruning.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Teach ManifestListPruning::boundsOfPartitionFieldSummary to keep the exact-point UUID case instead of widening it to no bounds.
    2. Add a focused regression for the manifest-list pruning path so the two UUID pruning surfaces stay aligned.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @arsenmuk, could you review this? An Iceberg uuid bound is 16 big-endian bytes and a conforming writer orders the lower/upper pair by unsigned byte comparison, while deserializeFieldFromBinaryRepr raw-copies it into ColumnVector<UUID> and ClickHouse orders UUID by its second half, so the declared pair is not an interval in the column's own order and min/max pruning skips data files that hold matching rows; a byte swap alone leaves the ordering half, so I drop the bound instead. Note that it edits the same function #115817 moves.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 38fa99797 with master 371b23a4b (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

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

Job report

@scanhex12 scanhex12 self-assigned this Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 7b35b86

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 (arm_asan_ubsan, azure, sequential) / 04340_distributed_plan_status_reenqueue_fault flaky, unrelated to this diff (Iceberg manifest bounds): 46 PRs and 9 true-master rows in 30 days #118417 (external, open), #118390 (mine, open)
Stateless tests (arm_asan_ubsan, azure, sequential) / 04648_distributed_plan_task_error_propagation flaky, same job and same family: 54 PRs and 14 true-master rows in 30 days #118417 (external, open), #118390 (mine, open)
PR praktika aggregator of the job above #118417 (external, open), #118390 (mine, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

CI ran on the master merge pushed to this branch at 2026-09-08T03:45:40Z, so the failing head is
current with master.

Session id: cron:our-pr-ci-monitor:20260908-103036

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@PedroTadim PedroTadim self-assigned this Oct 9, 2026
…nifest-bounds

Master moved the bound deserialization out of `ManifestFileIterator.cpp` into
`IcebergFieldParseHelpers.cpp`, so the `UUID` guard now lives in the moved
`deserializeFieldFromBinaryRepr`. It also covers the manifest list partition
summaries that master decodes with the same function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim enabled auto-merge October 9, 2026 13:24
@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6846ab5

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 (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines test regression from merged #123364, not from this PR (which changes only the Iceberg uuid bound parsing and its integration test): under DatabaseReplicated the CREATE DICTIONARY row is counted twice in system.query_log. The rerun diagnosis passed 22/22 #124928 (external, merged 17:58Z, after this run was built). The row clears once this branch next picks master up
Mergeable Check, PR praktika rollups of the row above #124928 (external, merged)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20261009-213010

A `uuid` bound pair is ordered by unsigned byte comparison, which is not
the order of ClickHouse `UUID`, so the pair as a whole is still unusable.
When both bounds are equal, the pair describes the single value the
column holds in that file, and decoding the 16 big-endian bytes gives that
value exactly. Such a file is pruned again on that point, for example a
single-row data file or a column that is constant within the file.

The decoding loads both halves big-endian into the high and low words of
the `UUID`, which is what the data path does for `FIXED_LEN_BYTE_ARRAY`
uuid values. The test now asserts that the single-value file is pruned for
a predicate on another value and kept for its own value.

Requested in review: ClickHouse#118380 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
auto-merge was automatically disabled October 10, 2026 11:46

Head branch was pushed to by a user without write access

@groeneai groeneai changed the title Do not prune Iceberg data files on uuid manifest bounds Use Iceberg uuid manifest bounds for pruning only when they are equal Oct 10, 2026
/// The spec serializes a `uuid` bound as 16 big-endian bytes and orders the pair by unsigned
/// byte comparison, while ClickHouse orders `UUID` by its second half. The two orders
/// disagree, so even a byte-swapped pair can exclude a value the file holds.
if (non_nullable_type->getTypeId() == TypeIndex::UUID)

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 restores the exact-point case only for data-file min/max stats. ManifestListPruning::boundsOfPartitionFieldSummary still decodes UUID partition summaries via deserializeFieldFromBinaryRepr (ManifestListPruning.cpp:74-75), so the unconditional std::nullopt here turns even lower_bound == upper_bound into "no bounds" on the manifest-list path.

That regresses use_iceberg_partition_pruning for UUID partition keys: a manifest entry whose summary is an exact UUID point can no longer be skipped as a whole, even though the same point case is now considered sound for data-file pruning. Please reuse deserializeUUIDPointFromBinaryRepr (or factor the pair-aware logic out) in boundsOfPartitionFieldSummary as well, and add a focused test for a partitioned Iceberg table so this surface stays covered.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - bb7be10

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 (arm_binary, ParallelReplicas, s3 storage, parallel) / 02963_remote_read_small_buffer_size_bug flaky, not from this PR (27 of 27 reruns pass): the write_block_size < 200e3 check reads only the initiator's query_log row, which shows one 4338-byte write when the replicas did the reading. Same failure on 1 other PR today, 0 on master a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR praktika rollups of the row above a fix task is created (the one above)

Session id: cron:our-pr-ci-monitor:20261010-163006

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 02963_remote_read_small_buffer_size_bug (Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)) created: #125092

@PedroTadim
PedroTadim enabled auto-merge October 12, 2026 08:23
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 12, 2026
Merged via the queue into ClickHouse:master with commit 4586049 Oct 12, 2026
177 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 Oct 12, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 2, 2026
ClickHouse#118380 added `deserializeUUIDPointFromBinaryRepr` for data file bounds while
this branch carried its own 16-byte decoder. Keep a single decoder: the point
helper now checks that both bounds are equal and delegates to
`deserializeUUIDFromBinaryRepr`, and the manifest list pruner calls the point
helper instead of repeating the equality check.

With ClickHouse#118380 in the base, the example from ClickHouse#123961 (`WHERE u = ...` on a table
that keeps the default `uuid` column metrics) returns its rows, so the test
asserts it too.

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... groeneai-origin-issue PR origin: picked up an external GitHub issue pr-bugfix Pull request with bugfix, not backported by default 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 min/max pruning reads UUID manifest bounds without the RFC byte swap: WHERE over a UUID column silently misses rows

5 participants