Repository navigation
Fix Iceberg DELETE/UPDATE deleting wrong rows after ADD COLUMN under PREWHERE - #111693
PedroTadim merged 8 commits into
Conversation
…PREWHERE An Iceberg DELETE/UPDATE reads matching rows plus the _row_number virtual column and records (data_file, row_number) into a positional-delete file. _row_number is recovered from ChunkInfoRowNumbers (row_num_offset + applied_filter) attached by the Parquet reader. For a data file predating an ALTER TABLE ADD COLUMN, the read goes through the schema-changed path where PREWHERE is stripped from the reader and replayed as a fallback FilterTransform. FilterTransform dropped rows without composing its filter into ChunkInfoRowNumbers.applied_filter, so _row_number became the compacted post-filter index instead of the physical row position, and the positional delete targeted the wrong rows. DELETE removed the wrong rows; UPDATE left duplicates and missing rows. FilterTransform can now compose the applied filter into ChunkInfoRowNumbers, but only when explicitly asked to via a new update_row_numbers_info flag (default off). The data lake read fallback filters and the Iceberg equality-delete filter in StorageObjectStorageSource/IcebergMetadata enable it: they run right after the format reader (only row-count-preserving-or-tracking transforms in between), so the info still describes the chunk. Every other FilterTransform caller keeps its previous behavior, which matters because some callers (e.g. FilterSortedStreamByRange, or a LimitTransform upstream) hand FilterTransform a chunk whose retained ChunkInfoRowNumbers no longer matches the columns. The composition also guards against such stale info (set-bit count must equal the pre-filter row count). Closes: ClickHouse#111664 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-2:20260723-192800 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 review rounds as the fix was re-architected; final round: 0 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-2:20260723-192800 |
|
cc @arsenmuk @SmitaRKulkarni — could you review this? It fixes silent wrong-row |
|
Workflow [PR], commit [4959bcd] Summary: ✅
AI ReviewSummaryThis PR fixes wrong Final Verdict✅ No new findings. |
CI finish ledger — 005d71eEvery failure below has an owner. The only real failure is a chronic, PR-independent amd_tsan job timeout (server froze mid-suite; 0 per-test results); the aggregate checks just reflect it.
The Iceberg fix and its new test ( Session id: cron:our-pr-ci-monitor:20260724-030000 |
|
Following up on the CI finish ledger above: the To be precise about what it does and does not cover, since the ledger line described the failure as a non-deterministic stall: it fixes the pid-identification defect on that same abort path ( |
The fix in this PR makes three FilterTransform call sites compose their
applied filter into ChunkInfoRowNumbers. Only the two stripped-PREWHERE
fallback filters were covered by 04615; the Iceberg equality-delete
notIn filter was not, so the equality-delete half of the contract was
unproven.
Reverting only the equality-delete call site to the old behaviour makes
the new test fail, and pristine master fails it too: on a table that
carries equality delete files the _row_number column is built from a
stale mask, which either aborts with a column length mismatch
("Expected the argument ClickHouse#2 ('__table1._row_number' of type Int64) to
have 423 rows, but it has 470") or silently yields compacted post-filter
indices instead of physical row positions. Those indices are what the
mutation path writes into positional delete files, so a wrong value
deletes the wrong rows.
The test uses the existing committed fixtures: deletes_db/eq_deletes_table
(equality plus position deletes, also read under PREWHERE so the fallback
filter stacks on top of the notIn filter) and
deletes_db/eq_deletes_required_table (equality deletes only, where the
exact physical row numbers are asserted). The per-file offset assertion is
independent of the engine path: it is checked against the raw Parquet data
files read directly through s3().
Co-Authored-By: Claude Fable 5 <[email protected]>
The equality-delete call site does not run right after the format reader: a position-delete transform, and an earlier equality-delete filter, can precede it. What actually holds is that each of those maintains ChunkInfoRowNumbers, so the info still describes the chunk. Also say what happens when the composition declines a stale mask: the info is unrecoverable at that point and is left untouched, and a consumer of a stale mask fails loudly on the resulting column length mismatch rather than silently producing wrong row numbers. Co-Authored-By: Claude Fable 5 <[email protected]>
A declined stale mask does not necessarily fail downstream: the row numbers are built one per set bit, so a mask with N set bits on a chunk that the filter reduces to N rows yields N row numbers and no length mismatch. State only what holds: the info cannot be repaired at that point, and the opt-in callers are those whose upstream transforms maintain it. The header carried the same "right after the format reader" inaccuracy that the equality-delete call site had. Co-Authored-By: Claude Fable 5 <[email protected]>
Asserting only that id - _row_number is constant per data file is weaker than it looks: a mask that replaced rather than composed would keep it constant while shifting it. Assert the exact offset per file instead. The expected values are the ones the raw Parquet data files carry, so they do not depend on the read path. With this, reverting the composition branch produces scattered offsets rather than a single shifted value. The second case is also mislabelled: this fixture is same-schema Parquet, so PREWHERE is not stripped into a fallback filter; it stays in the reader and its mask is composed with the equality-delete mask. Co-Authored-By: Claude Fable 5 <[email protected]>
The tag comment named the fallback filter path, which this fixture never takes: eq_deletes_table is same-schema Parquet, so the reader keeps PREWHERE (the same fact the second case's own comment states). The real reason is that StorageObjectStorageCluster does not override IStorage::supportsPrewhere, so the explicit PREWHERE throws ILLEGAL_PREWHERE once the cluster wrapper is used. Verified against the running server: with enable_parallel_replicas = 1, a cluster_for_parallel_replicas set and parallel_replicas_for_cluster_engines = 1, the second query returns Code 182 ILLEGAL_PREWHERE "Storage IcebergS3 does not support PREWHERE"; with parallel_replicas_for_cluster_engines = 0 it returns 125 rows. Points at the same explanation 04071 and 04615 already use. Co-Authored-By: Claude Fable 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 54/56 (96.43%) · Uncovered code |
…line
`Stateless tests` jobs have been failing with a job-level `error` that burns the
full wall-clock budget and reports no per-test results at all: `check_status`
is `error` and `results` is empty, so the failure is invisible to every
test-name-based query. Over the last 30 days this happened 16 times across 14
unrelated pull requests and 0 times on master.
In CI the runner heads a shell pipeline,
`clickhouse-test | ts | tee -a <file>` (`ci/jobs/functional_tests.py`). A
per-test wrapper is spawned with `start_new_session=True` and inherited stdio,
so it holds the pipeline's write end and lives in its own session. When the
runner aborts and exits, a wrapper that outlives it keeps that descriptor open,
`ts` and `tee` never see EOF, and the pipeline never finishes. The job-level
wall-clock timeout then replaces the runner's real exit status, which is why
the underlying `Server died` report is never produced and no per-test rows are
written.
The wrapper does not need the runner's streams: the command already redirects
the test's own output to the per-test `{stdout}`/`{stderr}` files that
`process_result_impl` reads back, so the inherited descriptors carried nothing.
Its stdout is now `DEVNULL` and its stderr is appended to the per-test stderr
file, which removes the coupling without reaping anything. The parallel workers
and the bookkeeping manager keep the runner's stdout by design, since they
report results through it; fd 0 is likewise still inherited.
Also fixed here, found while validating the above:
- The per-test stderr file is truncated before each attempt, so a retried
attempt no longer inherits the previous one's diagnostics, and the wrapper
appends rather than overwrites, since the command's own `2> {stderr}` holds a
second descriptor on that path with its own offset.
- A `preexec_fn` that dies before `exec` is now reported as the test's failure
with its numeric exit status, instead of being lost.
Documented in `tests/clickhouse-test-process-management.md`.
Verified in the job's own image with a live server: the pipeline finishes with
the runner's status while the orphan is deliberately left running, and
reverting the redirect reproduces the wedge.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111693&sha=005d71edc8389539f2661acd34f2bd165de3b108&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112265&sha=afd4ae8bc5b3cbfa78cad8f1bf5e0a5a66c33b54&name_0=PR&name_1=CI%20Tests
Related: ClickHouse#111693
Related: ClickHouse#112265
Co-Authored-By: Claude Fable 5 <[email protected]>
CI finish ledger — 4959bcdEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-043000 |
|
LGTM! @scanhex12 can you give a quick look? |
|
The fixing PR for the ledger line on this PR is now open: #112265. The Deciding to stop took 0.2 to 7.7 minutes across the affected runs; the wait between that decision Correcting the reason I gave in that ledger: I described this as a non-deterministic TSAN server |
Closes: #111664
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
DELETE/UPDATEon an Iceberg table silently removing the wrong rows (or throwingNOT_FOUND_COLUMN_IN_BLOCK) when the table contains data files written both before and afterALTER TABLE ... ADD COLUMNandoptimize_move_to_prewhereis enabled.Description
Root cause: an Iceberg
DELETE/UPDATEreads the matching rows together with the_row_numbervirtual column and records(data_file, row_number)into a positional-delete file._row_numberis recovered fromChunkInfoRowNumbers(row_num_offset+applied_filter) attached by the Parquet reader. For a file that predates theADD COLUMN, the read goes through the schema-changed path wherePREWHEREis stripped from the reader and replayed as a fallbackFilterTransform.FilterTransformdropped rows without composing its filter intoapplied_filter, so_row_numberbecame the compacted post-filter index (0,1,2,...) instead of the physical position, and the positional-delete targeted the wrong rows. This is the invariantChunkInfoRowNumbersdocuments ("a step that uses this info must not run after a step that breaks it").Fix:
FilterTransformcan now compose the mask it applies intoChunkInfoRowNumbers.applied_filter(likeDeletionVectorTransform/IcebergStreamingPositionDeleteTransform), but only when explicitly asked via a new opt-in flag. The data lake read fallback filters and the Iceberg equality-delete filter enable it, since they run right after the format reader where the info still describes the chunk. Every otherFilterTransformcaller keeps its previous behavior, which matters because some callers (e.g.FilterSortedStreamByRange, or aLimitTransformupstream) handFilterTransforma chunk whose retainedChunkInfoRowNumbersno longer matches the columns; the composition also guards against such stale info.Setting
optimize_move_to_prewhere = 0was a workaround; it is no longer needed.Version info
26.8.1.430(included in26.8and later)