Repository navigation
Do not skip Iceberg position deletes on inverted reference bounds - #118181
PedroTadim merged 3 commits into
Conversation
A position-delete manifest entry may declare the range of data file paths its delete file references. When `referenced_data_file` is absent, `AvroForIcebergDeserializer` took `lower_bounds` and `upper_bounds` for the reserved `file_path` column independently, with no ordering check, and `IcebergIterator` then kept the delete file for a data file only when `lower <= path && upper >= path`. An inverted pair makes that conjunction false for every path, so the delete file was skipped for every data file it covers and the rows it deletes were returned. The query succeeded with wrong rows; only a `LOG_TEST` line and `IcebergMinMaxPrunedDeleteFiles` recorded it, and no setting gated the check. That branch is the one ClickHouse itself takes: it never writes `referenced_data_file`, so every merge-on-read delete it produces carries these bounds. The pair is now checked where it is built. When inverted, both bounds are dropped and a warning is logged, which leaves the entry as one that declares no bounds. Swapping or clamping was rejected: a swapped pair would go on skipping delete files, over a range the manifest never asserted. Dropping the bounds cannot lose deletes, because the path is re-checked downstream. `PositionDeleteTransform` pushes `WHERE file_path = '<data file>'` into the delete-file read and then filters every delete row by exact path match against the current data file. The cost is at most reading a delete file that filters to zero rows, which is already what happens for a delete file that declares no bounds. The regression test is an integration test because it rewrites an Avro manifest out of band. Its fixture is written entirely by ClickHouse, and it needs two data files under one delete file: the bounds are the extremes of the delete file's own `file_path` column, so a single data file gives `lower == upper` and exchanging them would be a no-op.
The regression test built its inverted pair by exchanging the two real extrema, so an implementation that reordered the pair rather than dropping it restored the original well-formed range and satisfied the test. Drop and reorder were observationally identical there, and no assertion on rows or profile events could separate them, because one delete file covering both data files is never skipped on a well-formed pair. Reordering is not an equivalent implementation: it prunes on a range the manifest never asserted, so where the two declared values are not the real extrema the sorted range can exclude every data file path and the delete file goes on being skipped. A second fault arm pins that. Its pair is derived from the real maximum and sorts above every data file path, so the sorted form contains no data file at all, and only dropping the bounds keeps the delete file. Measured on the built binaries: that pair returns the surviving rows with the fix and every row without it, while its sorted form returns every row even with the fix. The rewrite loop now takes the mutation as a parameter so both arms share it, and the assertion that the two bounds differ moves into the exchanging arm, the only arm it constrains. Two smaller corrections. The control arm's comment claimed a discrimination it does not provide, an implementation ignoring these bounds outright satisfying the control as well; it now states what the control does pin, which is the fixture the fault arms need. And the warning names the manifest file that declares the malformed pair, as the data file bounds guard it mirrors does, since that is the file an operator has to find to repair it.
Internal second-model reviewTwo rounds against the change. Round 1 raised one major, which I fixed; round 2 raised none. Major, test liveness (agreed, fixed). The regression test built its inverted pair by exchanging the two real extrema, so an implementation that reordered the pair instead of dropping it restored the original well-formed range and satisfied the test. Drop and reorder were observationally identical there, and no assertion on rows or profile events could separate them. A second fault arm now installs a pair derived from the real maximum that sorts above every data file path: reordering that pair leaves a range holding no data file, so only dropping the bounds keeps the delete file. Measured on both binaries across all four bound states. Two smaller corrections in the same round: the control arm's comment claimed a discrimination it does not provide, and the new warning now names the manifest file that declares the malformed pair, as the data file bounds guard it mirrors does. Noticed nearby, not part of this change and not reproduced, so I am not raising it: |
|
Workflow [PR], commit [cc417d2] Summary: ❌
AI ReviewSummaryThis PR hardens Iceberg position-delete manifest parsing by treating inverted Final Verdict✅ No new blockers or majors found. LLVM Coverage ReportMeasured on commit cc417d2.
Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+16.66 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
TL;DR: the fix looks complete for the delete-file bounds (single build site, single consumer, and the check uses the identical The residual named in the description — |
|
The follow-up is a separate pull request, tracked on my side; I will post the number in this thread when it opens, so the link does not depend on this description. The remedy transfers without a new mechanism: at master |
|
One correction on where the follow-up guard has to live, because the The So a follow-up that only ignores an inverted pair "at :219" would not change this path. The guard has to go inside |
|
You are right, and the ambiguity was mine: "there" attached to One route a guard there does not reach, so it needs its own early return rather than the fallthrough: |
CI finish ledger - 8b8f6f3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260905-043000 |
|
@zlareb1 The follow-up is #118299, as promised in this thread. It carries the placement you prescribed: the ordering check returns The second route I described in this thread is reproduced now, so it is no longer a code reading: patching the manifest list's |
…verted-delete-bounds
8396165
A filter on `_row_id` or `_last_updated_sequence_number` over a format-version 3 table is answered from the manifest, by handing `KeyCondition` the range of row lineage values a data file can hold. Two writer-declared inputs can make that range start above where it ends, and neither was checked: - `getMaterializedRowLineageRange` built `DB::Range` straight from the `value_bounds` pair declared for the reserved field id, so a manifest that declares a lower bound above the upper bound produced an empty range. - `addRowLineageHyperrectangles` derived a file's inherited block as `first_row_id + record_count - 1`. `first_row_id` is a signed long on the wire and unsigned in the reader, so a negative value made the sum wrap and the block end below its own start. An empty range prunes the data file away, so a filtered read silently loses every row it holds, and the `chassert` in `KeyCondition::checkInRange` aborts the server in debug and sanitizer builds. Both cases now drop the untrustworthy bounds. A pair inverted as declared means the manifest's statistics do not describe the file, so no range derived from them may be pruned on; swapping or clamping the pair would instead prune on a range the manifest never asserted, which is the same reasoning the guard for ordinary columns already uses. The declared-pair case returns no range and lands on the existing conservative fallback, `[0, last inherited row id]`, which holds for both reserved ids: a materialized value always comes from an earlier write, so it is below this file's own block. The wrapped-block case cannot use that fallback, because the wrapped value IS the fallback's upper bound, so it installs no row lineage range at all. Re-reading the bounds with rounding compensation, as the ordinary-column path does, is not needed here: the type is `DataTypeUInt64`, which takes the non-decimal branch of `deserializeFieldFromBinaryRepr` where that flag is unused, so the deserialized values are the declared ones. Tested by two integration arms that patch a Spark-written v3 table's avro metadata: one declares an inverted `_row_id` pair, the other a negative `first_row_id`. Each arm reddens when its own check is removed. Reported by @ zlareb1 on pull request ClickHouse#116604, which fixed the same defect class for ordinary columns, and again on ClickHouse#118181, which fixes it for position delete file paths. Related: ClickHouse#116499 Related: ClickHouse#116604
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a query over an Iceberg table returning rows that had been deleted, when a position-delete manifest declares a lower bound above the upper bound for the reserved
file_pathcolumn. Such a pair describes an empty range, so the delete file was skipped for every data file it covers; those bounds are now ignored instead. Closes #118113.Description
Closes: #118113
Related: #116604
A position-delete manifest entry can declare the range of data file paths its delete file references, and nothing checks that pair. When
referenced_data_fileis absent, the deserializer takeslower_boundsandupper_boundsfor the reservedfile_pathcolumn independently, and the reader then keeps the delete file for a data file only whenlower <= path && upper >= path. Inverted, that conjunction is false for every path, so the delete file is skipped everywhere and the rows it deletes come back. The query succeeds with wrong rows; only aLOG_TESTline andIcebergMinMaxPrunedDeleteFilesrecord it, and no setting gates the check.That branch is the one ClickHouse itself takes: it never writes
referenced_data_file, so every merge-on-read delete it produces carries these bounds.I check the pair where it is built and, when inverted, drop both bounds and warn, which leaves the entry as one that declares no bounds. I did not swap or clamp them, because a swapped pair would go on skipping delete files, over a range the manifest never asserted.
Dropping the bounds cannot lose deletes. The path is re-checked downstream:
PositionDeleteTransformpushesWHERE file_path = '<data file>'into the delete-file read, then filters every delete row by exact path match against the current data file. So the cost is at most reading a delete file that filters to zero rows, which is already what happens for a delete file that declares no bounds.Not addressed here:
getMaterializedRowLineageRangereads its reserved-field ranges just as unchecked. That is a separate site and a separate pull request.Validation
It is an integration test because it rewrites an Avro manifest out of band. The fixture is written entirely by ClickHouse: two inserts make two data files, and one
ALTER TABLE ... DELETEover both makes one delete file whosefile_pathbounds are those two paths. Both arms rewrite field id 2147483546 alone, which selects the delete manifest by construction: a data file entry keys its bounds by the table's own column ids.Two data files are needed: the bounds are the extremes of the delete file's own
file_pathcolumn, so one would make them equal. The first arm exchanges the two real extrema, the reported shape; it asserts they differ, and that an entry was rewritten, so it cannot pass unfixed. The second installs a pair derived from the real maximum that sorts above every path, so reordering rather than ignoring it would leave a range holding no data file and the delete file skipped everywhere. That pins dropping these bounds over sorting them.[1,3,..,19]NonPrunedDeleteFiles=2[0,1,2,..,19]PrunedDeleteFiles=2[1,3,..,19]NonPrunedDeleteFiles=2[1,3,..,19]NonPrunedDeleteFiles=2Rows 1 and 3 are the control: on a well-formed pair the two binaries agree on rows and counters, so the check fires only on inversion and good-pair pruning is unchanged. The test passes with the fix and fails without it, on the first fault arm, its control still passing.
Also green:
test_position_deletes.py, all 17 functions, incl. threetest_position_deletes_bounds_loggingparametrizations, which pin the logged bounds against the manifest bounds, so the check never fires on Spark's well-formed pairs; the wholetest_storage_iceberg_no_sparkmodule, 63 functions; five repeats of the new test; 85 Iceberg stateless tests; 85 Iceberg unit tests.Workflow [PR]
Sync PR [sync-upstream/pr/118181]
Version info
26.9.1.893(included in26.9and later)