Skip to content

Write one Iceberg position delete file per data file in ALTER UPDATE and DELETE - #129380

Merged
fm4v merged 5 commits into
ClickHouse:masterfrom
groeneai:iceberg-delete-file-per-data-file
Nov 20, 2026
Merged

fm4v merged 5 commits into
ClickHouse:masterfrom
groeneai:iceberg-delete-file-per-data-file

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #129159
Related: #128374
Related: #120916

Changelog category (leave one):

  • Performance Improvement

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

Iceberg ALTER TABLE ... UPDATE and DELETE write one position delete file per data file, with positions in increasing order, as Spark does by default, and reads look such delete files up by data file path, so each data file reads only its own deletes. Reads after such mutations are 6-9 times faster in the Iceberg configuration of the apply_patch_parts_merge performance test.

Description

Problem. A mutation kept one position delete writer per partition and read data files in parallel, so each delete file mixed positions of many data files and its file_path bounds covered almost all of them. IcebergIterator::next prunes by those bounds, so every data file opened every delete file.

Change. Deleted positions are collected per data file and written as one delete file per data file, sorted by pos, with exact bounds; the files of a partition share one manifest. On read, delete files whose bounds name one data file are looked up by path, so a data file no longer walks the delete files of other data files. A failed mutation removes the delete files it already wrote.

Measured (release, x86, Iceberg local disk, 10 paired runs; perf tests via perf.py --table-engine iceberg_local): apply_patch_parts_merge M0-M3 -84..-89%, apply_patch_parts_steps S0/S1 -78/-82%; 20 UPDATEs 315 s -> 118 s, UPDATE peak memory 1.94 GiB -> 531 MiB. 2000 data files x 5 sparse DELETEs (10,000 delete files): count() -40% local, -15% S3, -15..-32% icebergLocalCluster. Losing shape: lightweight_delete L0 +10..15%: its one-thread DELETE writes master's single file in data-file order, so it is pruned by row group, while the 10 per-file files are read whole.

Side effects. Tables have more, smaller delete files; their pos order covers the goal of #120916. Skipping position delete file is logged only for files not bounded by one data file. 05325 T2 and a new part of 04291 read Spark-written fixtures, 05229 covers a multi-file DELETE manifest, and test_iceberg_inverted_delete_bounds.py, test_position_deletes_bounds_logging and the setup checks of iceberg_deletes_scale.xml follow the new layout.

Patch and analysis by @ snelheidai in #129159.


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

Version info

  • Merged into: 26.12.1.61-master (included in 26.12 and later)

groeneai and others added 2 commits November 4, 2026 20:55
…les up by path

ALTER UPDATE and DELETE collect the deleted positions of each data file in a roaring bitmap and write one
position delete file per data file, rows sorted by pos, with file_path lower == upper bounds; the files of a
partition share one manifest. Reads group the position delete files whose bounds name one data file by that
path once per query, so a data file looks its own up instead of walking every delete file of its partition.
The pruning counters keep their totals. A failed mutation removes the delete files it already wrote.

04291 (ClickHouse#91525) gets a part reading a Spark-written fixture whose delete file covers several data files, since
ClickHouse no longer writes one; 05229 pins the manifest-list file count of a multi-file DELETE; the setup checks
of iceberg_deletes_scale.xml accept both layouts. Analysis and the writer patch: issue ClickHouse#129159.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove comments that narrate the new code in Mutations.cpp and shorten the rest to the invariants they state.

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

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (rounds 1-4): 8 findings fixed, 1 out of scope, 5 noted
Finding Verdict
❌ 04291 (#91525) built its multi-file delete fixture with ClickHouse mutations, which now write one delete file per data file, so the test no longer exercised the row filter AGREE, fixed: 04291 also reads a Spark-written table whose delete file covers several data files (fails with the #91525 filter removed)
❌ iceberg_deletes_scale.xml setup checked the old delete-file counts (302 / 2) and would abort AGREE, fixed: the checks accept both layouts, since the setup runs on both binaries
❌ A partitioned UPDATE writes the whole mutated block into every target partition DISAGREE (out of scope): unchanged master code, #101665, fixed in #109838
⚠️ The lookup and the one-manifest-per-partition layout were not pinned by a failing test AGREE, fixed: test_position_deletes_bounds_logging asserts no per-pair skip line; 05229 covers a DELETE manifest with 3 files
⚠️ A failed mutation left the delete files it had already uploaded AGREE, fixed: removed on failure (best effort)
⚠️ The cleanup re-indented the unchanged UPDATE pass, which #109838 rewrites AGREE, fixed: a scope guard, the UPDATE pass is untouched
⚠️ No committed test failed without the cleanup AGREE, fixed: 05497 runs an UPDATE whose SET expression throws and checks that no delete file is left
⚠️ The cleanup was disarmed before the UPDATE result was built, which allocates AGREE, fixed: disarmed right before each successful return
💡 A 04291 comment still described one delete file per ALTER AGREE, fixed
💡 One more Preliminary check debug line per data file noted, not blocking
💡 Compaction.cpp keeps its own delete/data-file walk noted: OPTIMIZE on 2000 files x 5 DELETEs 21.0 s -> 11.8 s
💡 max_pending_uploads = 16 is a bare constant noted, not blocking
💡 The UPDATE data files of a failed UPDATE stay, as on master noted, separate PR
💡 A throw after writeDataFiles returns but before the cleanup of writeMetadataFiles exists still leaves the delete files, as master leaves the UPDATE data file there noted, not blocking (best effort)

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05497_iceberg_mutation_delete_file_per_data_file fails on master every run (1 delete file per partition instead of 10, per-file pair counters 0 10 instead of 90 10) and passes with the change. The performance shapes are scripted paired runs.
b Root cause explained? A mutation kept one position delete writer per partition while reading data files in parallel, so each delete file's file_path bounds covered almost every data file and IcebergIterator::next could prune nothing. With one delete file per data file, next still compared every data file with every delete file of its partition, serially for -Cluster reads.
c Fix matches root cause? Yes. The writer emits one delete file per data file with exact bounds, and the reader looks such files up by path. The applied set is the same as the bounds test gives (lower == upper == P passes iff the data file path is P). No setting and no workaround.
d Test intent preserved / new tests added? New 05497 (file counts, sorted pos, exact bounds, pair counters, rows, DELETE and UPDATE, partitioned, a failed UPDATE). Existing tests follow the new layout and keep their property: 05325 T2 and a new part of 04291 (#91525) read Spark-written fixtures whose delete file covers several data files, 05229 covers a multi-file DELETE manifest, test_iceberg_inverted_delete_bounds.py uses per-file bounds, and test_position_deletes_bounds_logging asserts that no pair is skipped one by one.
e Both directions demonstrated? Yes, on Build-ID-checked debug servers: 05497, 05325, 05229 and the Spark bounds test FAIL on master and pass with the change. The new part of 04291 fails when the #91525 row filter is removed, and 05229 fails when the manifest-list file count is reverted to 1. 50 randomized runs of 05497, 04291 and 05229: 50/50 each.
f Fix is general across code paths? Deletion vectors go through the same lookup. Equality deletes are unchanged. The row estimate shares the grouping helper. Local, S3 and Azure are covered by the Spark test, and the cluster path was measured. Compaction is unchanged (OPTIMIZE timing measured).
g Fix generalizes across inputs (params/datatypes/wrappers)? Covers partitioned and unpartitioned tables, DELETE and UPDATE, mixed layouts (corpus 05477, 04291), inverted bounds, v3 deletion vectors and mixed v2/v3 tables, 1 to 2000 data files, sparse and dense deletes.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change. Master reads tables written by this change with identical results, and the change reads old ClickHouse and Spark layouts identically.
i Invariants and contracts preserved? The new member is filled under deletes_mutex before deletes_ready, like position_deletes_files. A throw during grouping leaves deletes_ready unset. defineDeletesSpan inputs stay sorted. Deletion vector and position delete application does not depend on order, and counter totals are unchanged. A failed mutation removes the delete files it already wrote: 05497 runs an UPDATE whose SET expression throws after its 10 delete files were uploaded and checks that none is left (all 10 are left when the cleanup is disabled); injected failures in the upload loop and in the UPDATE pass also leave 0 (3 and 10 without the cleanup).

Session id: cron:clickhouse-impl-slot-6:20261104-204200

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @alesapin, could you review this and add the can be tested label so CI runs? Iceberg mutations now write one position delete file per data file (sorted pos, exact file_path bounds) and reads look such files up by data file path, so a data file no longer opens the delete files of other data files; the per-file pos order also covers the goal of #120916.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [681cb9c]

Summary: ✅


AI Review

Summary

Reviewed #129380 at 681cb9ca40c68891a62eaabfcb02501044f4b97a, including all prior discussion. The PR writes sorted Iceberg position deletes per data file and indexes files with identical path bounds, avoiding repeated scans of unrelated delete files. The supplied benchmarks substantiate the performance improvement and disclose the slower workload. No unresolved findings remain. Both earlier cleanup and cancellation findings are fixed in the current code; their bot-authored threads have been resolved.

Consumers checked for the changed file layout:

  • IcebergIterator::next retains partition and sequence-number filtering; the streaming and bitmap transforms consume the sorted positions, and cluster serialization retains its existing representation.
  • IcebergMetadata::estimateRead shares the grouping helper; system.iceberg_files enumerates individual manifest entries.
  • Compaction and partition deletion process every applicable entry in a manifest.
  • Snapshot expiration and orphan-file reachability traverse every position-delete entry.
Missing context / blind spots
  • ⚠️ No local build or runtime tests were run. Current-head CI builds are still in progress, so this review does not establish their outcome; the normal CI run must complete.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 681cb9ca4 with master f98d6d53d (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.

Object file sizes

7 object files changed (+38.02 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp.o 655.00 KiB 675.43 KiB +20.42 KiB (+3.12%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp.o 213.21 KiB 229.85 KiB +16.64 KiB (+7.80%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

In the DBReplicated stateless job the ALTER on an IcebergLocal table is
executed once per shard (DatabaseReplicated::shouldReplicateQuery returns
true for a non-replicated table when the cluster has several shards), and
every server sees the same files. The shard-2 server re-ran
`UPDATE s = 'x' WHERE n % 5 = 0` after the initiator, matched the 857 rows
the first run had just written, and added one data file and one delete file
(DATA 12 / POSITION_DELETE 21 instead of 11 / 20). The DELETE statements
already match nothing on a second run.

`AND s != 'x'` makes the second run a no-op, so the counts no longer depend
on the database engine. Checked on a local two-shard Replicated database
rig: the unchanged test fails 5/5 with the CI diff, the changed one passes
20/20 there and 20/20 on an Atomic database, both with randomized settings,
and still fails against a master server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp
…illed query while writing

A position delete file was added to the mutation's file list only after it
had been written, so an exception while writing it left a file that the
cleanup of the failed mutation did not see. Besides I/O errors, this is what
a KILL QUERY or max_execution_time during the write phase does: the Parquet
writer reports the cancellation from its finalize, and the delete file it was
writing stayed in the table directory. The file is now registered before its
object is created.

The delete files are written after the read pipeline has finished, and the
Parquet writer checks for a killed query only with parallel encoding. With
max_threads = 1 a killed or timed-out DELETE wrote all its delete files and
committed the snapshot, although the client received the error. Check the
query status for every block and after the last upload, so such a mutation
fails and its files are removed.

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 19, 2026
@fm4v
fm4v added this pull request to the merge queue Nov 20, 2026
Merged via the queue into ClickHouse:master with commit 01e3ff9 Nov 20, 2026
197 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 20, 2026
@stresshouse

stresshouse Bot commented Nov 20, 2026

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

No performance changes are attributable to this PR. It changes only Iceberg code: delete files are now looked up by data file path when reading, and ALTER DELETE/UPDATE writes one position delete file per data file. ClickBench and TPC-H here read local MergeTree tables and never run that code. Two ClickBench queries were flagged but stay inconclusive. Q28 (+5.6%) is a borderline result where the two tests disagree. Q31 (+11.6%) is inside master's normal range for that query and is noisy on master, so that suppression is consistent with the diff.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 28 not_sure 1020 1077 +5.6% 0.0002 cpu: This query does a regex-heavy GROUP BY over the MergeTree hits table and never runs Iceberg code. The +5.6% shift is borderline and the two tests disagree, so it stays not_sure.
⚠️ 31 not_sure 215 240 +11.6% <0.0001 aggregation: At 240 ms, the median for this WatchID/ClientIP hash aggregation is inside master's current band of 209-283 ms, and the query is noisy on master. The PR changes only Iceberg code, so the suppression stands.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: e47261f3-08f2-47a1-89c2-becbe3b39d8f
  • MIRAI run: faaf745f-38a5-4731-9cbf-b1f0ade061e1
  • PR check IDs:
    • clickbench_508791_1795195184
    • clickbench_508797_1795195183
    • tpch_adapted_1_official_508804_1795195183
    • tpch_adapted_1_official_508854_1795195183

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 21, 2026
…-spec

Resolve the Mutations.cpp conflict with ClickHouse#129380, which writes one position
delete file per data file: the DELETE pass now collects the deleted positions
by data file only, and each data file's delete file is grouped under the spec
id, schema id and partition tuple recorded in its manifest entry, instead of
the partition recomputed from row values with the default spec. Master's
per-partition manifest writer takes the spec, partition columns and types as
arguments, so delete manifests are written under the recorded spec while new
UPDATE data files keep the default one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-performance Pull request with some performance improvements 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 mutations write position delete files that reads apply to many data files; one file per data file cuts apply_patch_parts_merge reads by 89–91%

3 participants