Skip to content

[Iceberg spec part 6] Sort the rows of an Iceberg position delete file by file_path and pos - #120916

Open
scanhex12 wants to merge 1 commit into
masterfrom
iceberg_position_delete_sorted
Open

scanhex12 wants to merge 1 commit into
masterfrom
iceberg_position_delete_sorted

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

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):

Sort the rows of an Iceberg position delete file by file_path and pos


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

The spec requires the rows of a position delete file to be sorted by `file_path`
and then `pos`, so that a reader can filter rows while scanning instead of
loading the whole delete file. The delete rows of one mutation come from many
data files and the mutation pipeline emits them interleaved, so they were
written in pipeline order: a `DELETE` over a table with 50 data files produced a
delete file whose rows jump between data files.

Sort the delete stream inside the mutation pipeline. A single sort over the whole
stream is enough for the per-file requirement: the delete files are split by
partition key afterwards, and a subsequence of a sorted sequence stays sorted.
Doing it in the pipeline rather than buffering the pairs and sorting before the
write keeps the memory bounded - `MergeSortingTransform` spills to disk under the
same settings as an ordinary `ORDER BY`, while the delete path itself still
streams block by block. The pipeline is resized to one stream first, because
merging the sorted streams with a plain resize would interleave them again.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c75568b]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy) FAIL
Build ClickHouse FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED
Build (arm_asan_ubsan) DROPPED

AI Review

Summary

This PR makes Iceberg mutations write position delete rows in spec order by sorting them on file_path and pos before the delete file is emitted. The correctness direction looks right, but the current implementation gets there by collapsing the mutation pipeline to one stream first, which makes large multi-file DELETE / UPDATE operations effectively single-threaded while the delete file is being produced.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp:182] builder.resize(1) serializes the whole position-delete sort. After that call, fullSortStreams can only create one PartialSortingTransform / MergeSortingTransform, so a mutation that used to read many Iceberg files in parallel now funnels every deleted row through a single sorter. Suggested fix: keep the existing streams and use the full-sort path that does a final merge after per-stream sorting, instead of resizing to one stream before sorting.
Final Verdict

Changes requested: preserve parallel sorting here, or show why forcing the delete path through one sort stream is acceptable for large multi-file Iceberg mutations.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Sep 18, 2026
delete_sort_description.emplace_back(block_row_number);

auto builder = interpreter->execute();
builder.resize(1);

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 resize(1) makes the whole position-delete sort single-stream. After it, fullSortStreams builds exactly one PartialSortingTransform / MergeSortingTransform, so a DELETE or UPDATE over many Iceberg data files loses the read parallelism we already had and funnels every deleted row through one sorter.

SortingStep already has the full-sort path that keeps per-stream sorting parallel and only adds a final merge, which seems like a much better fit here. Can we use that instead of collapsing the pipeline up front?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant