Repository navigation
Iceberg OPTIMIZE: write correct snapshot totals and read each position delete file once - #128759
Conversation
… once The manifest list of every snapshot also lists the manifests of the earlier snapshots, so getPlan collected each data file and position delete file once per snapshot that lists it. - Every copy of a delete file was applied to every copy of a data file, so IcebergPositionDeleteTransform opened the same delete file many times. The bitmap is idempotent, so only the cost grew: on IcebergS3 with 40 single-row inserts and 8 deletes, OPTIMIZE made 3,332 S3 GETs instead of 60. - snapshot_id_to_data_files[S] is the whole live set of S, and its row count was passed as added_records, which setSnapshotTotals adds to the rewritten parent's total-records. INSERT (1),(2); INSERT (3); DELETE x = 1; OPTIMIZE left a trivial count() of 3 against a full scan of 2. A data file now enters its partition bucket, and a delete file the delete list, only the first time it is seen. added_records is the live rows of the snapshot minus those of its parent when the parent was rewritten in the same pass (the parent is then found by getParentSnapshot), else the live rows. Attributing each data file only to the first snapshot that lists it would not be enough for the totals: a delete-only snapshot is not rewritten, so an append whose parent is one gets total-records = added_records alone, and INSERT (1),(2); DELETE x = 1; INSERT (3) would report 1 instead of 2. The accumulator is widened from Int32 to Int64: it sums a whole snapshot. Closes ClickHouse#128265 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The trivial count falls back to the manifest row counts when it cannot use total-records, so it alone cannot see total-records, and it never sees a snapshot other than the current one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…shots from their live files They were chained from the original deltas, so they restarted after a delete-only parent and kept the pre-rewrite sizes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds, 2 findings; last round clean) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261102-204600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261102-200700 |
|
cc @PedroTadim @SmitaRKulkarni, could you review this and add the |
|
Workflow [PR], commit [6d52681] Summary: ✅
AI ReviewSummaryThis PR fixes Iceberg Missing context / blind spots
Final Verdict✅ Approve — no new inline findings to post. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 18 s compile time in total, 7 of them have a recent master baseline. |
3b3f22d
Closes: #128265
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
OPTIMIZEof Iceberg tables (allow_experimental_iceberg_compaction) now writes thetotal-records,total-data-filesandtotal-files-sizeof every rewritten snapshot from its live rewritten files, so a trivialcount()after compaction matches a full scan, and reads each position delete file once per data file it applies to instead of once for every snapshot that lists the two files, which makes compaction of long histories much cheaper. Closes #128265.Description
getPlanreads the manifest list of every snapshot, and a manifest list also lists the manifests of earlier snapshots, so each data file and position delete file was collected once per snapshot listing it:added_recordswas the row count of the snapshot's whole live set, andsetSnapshotTotalsadds it to the parent'stotal-records(in the issue: trivialcount()3, full scan 2).Now each file is collected once, and a rewritten snapshot's
added_records,added_filesandadded_files_sizeare its live rows, data files and bytes minus its parent's when the parent is rewritten too, so each total equals the live value. Counting a data file only under its first snapshot is not enough: a delete-only snapshot is not rewritten, so its child would get only its own rows (INSERT (1),(2); DELETE x = 1; INSERT (3) gives 1, the test'sdelete_parentcase).total-data-filesandtotal-files-sizerestarted there too (1 of 2 files, 551 of 1102 bytes, e.g.system.tables.total_bytesof aMergetable over it).Other multi-snapshot walks already read each manifest once.
Validated by the new test (before:
3 2, delete-file reads24 10; after:2 2,2 2), 50/50 randomized runs, and the IcebergOPTIMIZEstateless and integration tests.OPTIMIZEofIcebergS3on MinIO, N single-row inserts then M deletes (master already prunes by delete-file bounds):count()before -> after (full scan)Caused by #85250.
Workflow [PR]
Sync PR [sync-upstream/pr/128759]
Version info
26.11.1.1207-master(included in26.11and later)