Skip to content

Fix Iceberg _row_id and _last_updated_sequence_number filters losing rows of files that store lineage values - #130100

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-row-lineage-stored-values-pruning
Nov 8, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-row-lineage-stored-values-pruning

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130022
Related: #130017
Related: #130010

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 filters on the Iceberg v3 virtual columns _row_id and _last_updated_sequence_number missing rows of data files that store some of these values instead of inheriting them from first_row_id and the data sequence number, for example a file rewritten by a copy-on-write UPDATE. Closes #130022.

Description

On v26.10.2.103-stable, SELECT id FROM icebergLocal('iceberg-row-lineage/materialized') WHERE _row_id > 1000 returns nothing for the parquetry table of #130022, whose second file stores _row_id 1001 and 1003; with use_iceberg_partition_pruning = 0 it returns 6, 8.

Two layers pruned by a range covering only one source of the values:

  • addRowLineageHyperrectangles used the declared bounds only when the column has no nulls, otherwise [0, first_row_id + record_count - 1].
  • getFormatFilter kept the lineage conjuncts in the filter pushed into the format, so Parquet skipped row groups by the statistics of the stored column, which do not cover inherited (NULL) values: after a Spark copy-on-write UPDATE, WHERE _last_updated_sequence_number = 2 lost the updated row with the default input_format_parquet_filter_push_down = 1.

Now a file is pruned by a lineage column only when its manifest declares bounds for it, widened by the inherited range when some rows may store NULL, and the format does not prune by lineage columns.

Cost: files without lineage statistics (every file appended by Spark or ClickHouse) are no longer skipped by these filters, e.g. by an incremental _last_updated_sequence_number > N read; files declaring lineage bounds still are. The old range covers what a spec-conforming writer stores, but the tables of #130022 and #130010 store values above it; keeping it for files without statistics still loses rows of the DuckDB table row_lineage_stored_columns, which declares none.

Validation: the new test 05612_iceberg_row_lineage_stored_values_pruning (tables byte-identical to #130017 / #130010) fails on master and passes 50/50; test_row_lineage_pruning.py follows the new rule and gains a Parquet push-down assertion.

🤖 Generated with Claude Code


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

Version info

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

groeneai and others added 3 commits November 8, 2026 07:54
A row's `_row_id` is the value stored in the data file, or `first_row_id`
plus its position where the file stores NULL; `_last_updated_sequence_number`
falls back to the data sequence number the same way. The manifest-level
pruning used the declared bounds of a lineage column only when the column
has no nulls, and otherwise the range `[0, first_row_id + record_count - 1]`
(`[0, sequence number]`), which assumes a stored value is below the
inherited block. Files that store values above it (compaction or
copy-on-write keeping row ids, or other writers) were skipped and their rows
lost: `WHERE _row_id > 1000` on the parquetry `iceberg-row-lineage/materialized`
table returned nothing instead of ids 6 and 8, and the DuckDB
`row_lineage_stored_columns` table (no statistics at all) lost the rows with
stored `_row_id` 100/103 and sequence numbers 7/9.

A file is now pruned by a lineage column only when its manifest declares
bounds for it; when some rows may store NULL the range is the hull of the
declared bounds and the inherited range. Without declared bounds (absent,
undecodable or inverted) the file is not pruned by that column. The early
returns for a missing `first_row_id`, an empty file, a negative sequence
number and a block that does not fit in UInt64 stay as they were.

The new test vendors both tables unmodified, at the paths used by ClickHouse#130017
and ClickHouse#130010.

Closes ClickHouse#130022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getFormatFilter` kept the conjuncts on `_row_id` and
`_last_updated_sequence_number` for Iceberg, so the Parquet reader pruned row
groups, pages and dictionaries by the statistics of the column stored in the
data file. Those statistics do not cover rows that store NULL and inherit
the value, so a filter above the stored maximum skipped row groups with
matching inherited values. After a Spark copy-on-write `UPDATE` the rewritten
file stores `_last_updated_sequence_number` [1, NULL, 1, 1], and
`WHERE _last_updated_sequence_number = 2` lost the updated row with the
default `input_format_parquet_filter_push_down = 1`.

The lineage columns are now treated like every other virtual column added
after the format; the filter is still applied after the source, and the
manifest-level pruning keeps skipping whole files where declared bounds
allow it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Files without lineage statistics (Spark and ClickHouse appends, Avro and ORC
data files, a rewritten file whose lineage statistics were dropped) are no
longer pruned by `_row_id` or `_last_updated_sequence_number`, so their
expected pruned-file counts become 0 and the `read_rows` assertion that
pinned the old skip is removed.

New assertions on the Spark copy-on-write table: the declared bounds [1, 1]
widened by the inherited sequence number 2 still skip the file for
`_last_updated_sequence_number > 2`, and `= 2` / `> 1` return the updated
row with Parquet filter push-down enabled.

The wrapped-block test now also declares `_row_id` bounds [0, 0] with a null
for the file whose block does not fit, so that widening by the wrapped block
([0, 8]) would skip it; this keeps the overflow guard observable now that a
file without declared bounds is not pruned anyway.

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 cold review (3 nits, no code change needed).

# Sev Finding Verdict Evidence / action
1 💡 Changelog entry overclaimed compaction for the manifest layer AGREE entry reworded in the PR body
2 💡 The cost note did not say the old range covers spec-conforming writers AGREE one clause added to the PR body
3 💡 05612 also pins that a file without lineage bounds is read AGREE, noted deterministic; intended by the new rule

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261108-075700

@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. icebergLocal('iceberg-row-lineage/materialized') WHERE _row_id > 1000 returns nothing on master (6, 8 with pruning off); the DuckDB table loses 2, 4 / 3, 4; a Spark copy-on-write table loses the updated row for _last_updated_sequence_number = 2 with Parquet push-down on. Also on v26.10.2.103-stable and v26.9.25.15.
b Root cause explained? Manifest pruning used declared lineage bounds only without nulls, else [0, top of the inherited block], which misses stored values above the block; the format filter kept lineage conjuncts, so Parquet pruned by stored-column statistics that do not cover inherited (NULL) values.
c Fix matches root cause? Yes. The range is built from both sources where it is built (declared bounds, widened by the inherited range when NULLs are possible; no bounds, no pruning), and the format no longer prunes by lineage columns. No setting, no widened bound, no guard.
d Test intent preserved / new tests added? New stateless test 05612 (fixtures byte-identical to #130017 / #130010). test_row_lineage_pruning.py counts follow the new rule; added a hull assertion and two Parquet push-down assertions; the wrapped-block test still observes its overflow guard.
e Both directions demonstrated? Yes. 05612 fails on master, passes 50/50 with the fix; the updated pruning module fails 11/11 on master and passes with the fix (plus test_row_lineage.py, 25/25). Mutations (no hull / no lineage pruning / no overflow guard) each fail a test.
f Fix is general across code paths? Manifest pruning and the read estimate share the changed function; format pruning is fixed for every format; files without first_row_id, wrapped blocks and the ORC _row_id skip keep their early returns; lineage is never a partition or PREWHERE column.
g Fix generalizes across inputs (params/datatypes/wrappers)? Bounds absent / with nulls / without nulls / inverted / undecodable, unknown null count, both lineage columns, Parquet, Avro and ORC files, Spark- and ClickHouse-written tables, a block wrapping at 2^64.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or metadata change; only fewer files and row groups are skipped, and results equal those with pruning off.
i Invariants and contracts preserved? canBePruned treats a lineage range as null-free, so it must contain every value a row can have: the widened range does; a missing range means not pruned. The format filter again holds no conjunct on a column added after the format.

Session id: cron:clickhouse-impl-slot-5:20261108-064300

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9f71dc4]

Summary: ✅


AI Review

Summary

Reviewed PR #130100 at 9f71dc49fa710d90dfa8dd7ff186fe613e92426e, including all prior discussion, the diff, surrounding code, and regression coverage. The change prevents filters on Iceberg lineage columns from discarding matching rows: manifest bounds include inherited values when needed, and format pruning excludes lineage predicates. Files without lineage bounds now require reading, as explicitly acknowledged in the PR. No actionable findings.

Missing context / blind spots
  • ⚠️ Runtime results were not independently reproduced: this checkout has no ClickHouse binary or build directory. The author reports before/after regression runs; the CI report currently has no completed results for the affected stateless and integration tests. Completed runs of 05612_iceberg_row_lineage_stored_values_pruning and test_row_lineage_pruning.py would close this verification gap.
Final Verdict

✅ Approve — no actionable code findings. Normal CI validation remains required.

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

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @alesapin, could you review this and add the can be tested label so CI runs? A filter on the Iceberg v3 _row_id / _last_updated_sequence_number columns pruned data files by the inherited first_row_id range when the manifest declared no null-free bounds, and Parquet pruned row groups by the stored lineage column's statistics, so rows of files that store these values were lost; now a file is pruned only by declared bounds (widened by the inherited range when some rows may store NULL) and the format filter no longer includes lineage conjuncts.

@clickhouse-gh clickhouse-gh Bot added 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 9f71dc49f with master 7b5f2bf32 (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

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

Job report

@alexey-milovidov alexey-milovidov 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

@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
Merged via the queue into ClickHouse:master with commit 39da336 Nov 8, 2026
373 of 375 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 8, 2026
@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-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 v3: a filter on _row_id prunes data files by the inherited first_row_id range and loses rows with stored _row_id

3 participants