Skip to content

Read an Iceberg data file in order only when its position deletes need it - #131203

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:iceberg-preserve-order-only-for-streamed-deletes
Nov 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:iceberg-preserve-order-only-for-streamed-deletes

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130931
Related: #113095
Related: #129380
Related: #120916

Changelog category (leave one):

  • Performance Improvement

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

Iceberg tables keep the row order of a Parquet data file only for files whose position deletes need it, so other files are read with full parallelism and ORDER BY ... LIMIT can skip row groups by their statistics: ORDER BY ... LIMIT queries over an Iceberg table are up to 2.7 times faster, ClickBench queries 6% faster on average. ALTER TABLE ... DELETE and UPDATE with use_roaring_bitmap_iceberg_positional_deletes = 1 no longer write position delete files that make a later read return deleted rows.

Description

Problem. Since #87220 IcebergMetadata::modifyFormatSettings forces parquet.preserve_order for every Iceberg read, because IcebergStreamingPositionDeleteTransform needs increasing row numbers from a data file and its delete files. The Parquet reader then delivers only from the first unfinished row group and never reorders row groups by statistics for ORDER BY ... LIMIT, even for files without deletes.

Change. StorageObjectStorageSource::createReader forces the order for a data file and its delete file readers exactly when the streaming transform is used (same predicate); reading in order (#113095) and lazy materialization pin it themselves. The read of ALTER TABLE ... DELETE/UPDATE, which writes each data file's positions in read order, asks for the order through input_format_parquet_preserve_order, which modifyFormatSettings now honours, as an engine table's format settings never see the query's. This also fixes a released bug: with use_roaring_bitmap_iceberg_positional_deletes = 1 that read was unordered and a later default read returned deleted rows (26.8 to 26.10). #129380 and #120916 would sort these positions in the writer instead. A SELECT without ORDER BY no longer returns a file's rows in file order (as s3()); input_format_parquet_preserve_order = 1 restores it.

Measured (release builds, IcebergLocal, 25M rows of ClickBench hits in 4 files, 16 cores, paired runs, ratio = PR / master): 14 queries geomean 0.886, ORDER BY EventTime LIMIT 10 0.686, all 43 queries 0.942, none slower beyond noise; new iceberg_top_k_row_group_order 0.37-0.41 on top-K queries, controls 1.02. Peak memory: lower on 5 of the 14 queries, up to +21% on top-K queries. Results are identical.

Tests. 05628 checks that delete files are sorted and deletes apply; it fails on master and with any part of the change reverted.

Analysis and the original patch by @ snelheidai in #130931.


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

Version info

  • Merged into: 26.11.1.2193-master (included in 26.11 and later)

groeneai and others added 2 commits November 13, 2026 05:26
…streamed

`IcebergMetadata::modifyFormatSettings` forced `parquet.preserve_order` for every Iceberg read unless
`use_roaring_bitmap_iceberg_positional_deletes = 1`, because `IcebergStreamingPositionDeleteTransform`
needs increasing row numbers from the data file reader and from the readers of its delete files. With
`preserve_order` the Parquet reader delivers only from the first unfinished row group, and the reordering
of row groups by statistics for `ORDER BY ... LIMIT` is off, so tables and files without position deletes
paid for nothing.

The order is now forced per file in `StorageObjectStorageSource::createReader`, for the data file and its
delete files, exactly when `getPositionDeleteTransformer` picks the streaming transform (the predicate is
factored out as `IcebergDataObjectInfo::usesStreamingPositionDeletes`). The read in order and lazy
materialization already pin the order themselves.

`ALTER TABLE ... DELETE` and `UPDATE` write the positions of every data file in the order their read
returns them, and the streaming transform requires them increasing. That read relied on the forced order,
and with `use_roaring_bitmap_iceberg_positional_deletes = 1` it already ran without it, writing unsorted
delete files that a later default read applies partially (deleted rows come back; reproduced on 26.8,
26.9 and 26.10). The read of the mutation now asks for the order explicitly through
`input_format_parquet_preserve_order`, which `modifyFormatSettings` now honours: an engine table's format
settings are built at CREATE time and do not see the query's.

Measured (release builds, 25M rows of ClickBench hits in 4 data files, IcebergLocal, 16 cores, paired):
14 queries geomean 0.886 (`ORDER BY EventTime LIMIT 10` 0.686), 43 queries 0.942, 4 cores 0.915; the new
perf test `iceberg_top_k_row_group_order` 0.37-0.41 on its top-K queries, neutral on the controls.

Analysis and the original patch: ClickHouse#130931 (snelheidai).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the modifyFormatSettings and mutation-read comments to one line each and drop the createReader comment that repeated the usesStreamingPositionDeletes doc comment.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings; 1 full pass), plus a separate cold review of the same tree (3 nits, no change).

# Sev Finding Verdict Evidence / action
1 💡 05628 checks results and delete-file order, not that files without streamed deletes are read unordered AGREE, no change the perf test iceberg_top_k_row_group_order measures that property
2 💡 modifyFormatSettings now lets the query's input_format_parquet_preserve_order reach an Iceberg engine table AGREE, no change the mutation read has no other channel (MutationsInterpreter passes only a context); it can only turn the order on
3 💡 #129380 rewrites the same writeDataFiles block AGREE, no change whichever lands second rebases; after #129380 the Mutations.cpp hunk is redundant, not wrong

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-11:20261113-053901

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Speedup: paired one-shot A/B of release builds (master vs PR) on a 25M-row ClickBench Iceberg table, 9 pairs per query, 95% CI per query. Bug: 05628 fails on master 5/5 without randomization (unsorted delete file, deleted rows returned).
b Root cause explained? modifyFormatSettings forced parquet.preserve_order for every Iceberg read because the streaming position delete transform needs increasing row numbers from a data file and its delete files; the order cost parallelism and the top-K row group reordering for every file. The ALTER DELETE/UPDATE read relied on it to write sorted positions, and with use_roaring_bitmap_iceberg_positional_deletes = 1 it ran unordered.
c Fix matches root cause? Yes: the order is forced per file where it is consumed, from the same predicate and context that choose the transform, and the mutation read asks for it explicitly.
d Test intent preserved / new tests added? New 05628 (delete files sorted, deletes apply for both delete modes, 1 and 16 threads, repeated streamed reads) and new perf test iceberg_top_k_row_group_order; no existing test changed.
e Both directions demonstrated? PR: 05628 10/10 and 50/50 randomized. Master: 5/5 FAIL. With the Mutations.cpp change reverted: 3/3 FAIL; delete file readers not ordered: 10/10 FAIL; data reader not ordered: Logical error: 'Chunks offsets should increase.'. Speedup: master with the roaring setting (no forced order) gains as much as the PR (0.894 vs 0.886).
f Fix is general across code paths? Both readers of the streaming transform are ordered (its only construction path is createReader); reading in order and lazy materialization already pin the order; bitmap deletes, deletion vectors, equality deletes, _row_number and row lineage are order-free; cluster replicas decide from the serialized object info; Delta Lake untouched.
g Fix generalizes across inputs (params/datatypes/wrappers)? Matrix of delete mode (writer and reader), thread counts, files with and without deletes, multi-row-group data and delete files. Column types do not matter (file-level order).
h Backward compatible? (maintainer-approved exception only) No setting default changes. A SELECT without ORDER BY of a file without streamed deletes no longer returns rows in file order (as s3() and file()); input_format_parquet_preserve_order = 1 restores it. Delete file format unchanged.
i Invariants and contracts preserved? Every reader the streaming transform consumes is created with preserve_order; positions written by a mutation increase per data file; schema cache and count paths keep the per-read format settings.

Session id: cron:clickhouse-impl-slot-5:20261113-032800

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [840028e]

Summary: ✅


AI Review

Summary

PR #131203, head 840028e7f246, limits ordered Parquet reads to files requiring streaming position deletes and explicitly preserves order when mutations collect delete positions. The change includes focused regression coverage and a performance test, with paired measurements and regression results documented by the author. No actionable findings after reviewing the diff, current code, callers, and all prior discussion.

Missing context / blind spots
  • ⚠️ The relevant stateless and performance CI jobs are pending. No local ClickHouse binary or build was available, so runtime validation relies on the author's reported runs; completed CI results for this head would close this gap.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI validation remains pending.

@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 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 840028e7f with master 21809eaaa (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

8 object files changed (+19.00 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/StorageObjectStorageSource.cpp.o 1.13 MiB 1.15 MiB +17.31 KiB (+1.49%)

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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.59, programs/clickhouse-keeper ×0.68 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.0 s +5.1 s (+259%)
Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 06ad563 Nov 13, 2026
606 of 608 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
mosya415 pushed a commit to mosya415/ClickHouse that referenced this pull request Nov 22, 2026
The check of the tests a PR adds or changes (ClickHouse#129330) failed a PR only when
a query's time grows run over run on the tested server. A test whose runs
are noisy without a trend passed its own PR, and in master_head PR mode the
report's own unstable/changed verdict never fails a PR. That is how
system_clusters_replicated_databases (ClickHouse#122223) got in: tested-server
spread (stddevPop / median of its runs) 0.41-2.1 in its PR, now > 0.5 on
both master servers in about 99% of runs and the noisiest test on master.

The check now also fails on an unstable query of such a test:

- PR changes only files under tests/ and the reference is the performance
  reference build of the tested master commit's sources (find_prev_build's
  new third value; a reference of an older commit, as in about a quarter
  of PR jobs, does not count): both servers run the same code built the
  same way, so the report's verdict judges the test; fail on changed_fail
  or unstable_fail of report/all-queries.tsv. A query that failed on the
  reference server and ran only on the tested one is not in that file; it
  is judged by the rule below.
- Any other PR or reference (code changes, the official-build fallback, or
  an older reference): the report measures the PR's change, not the test
  (the floors flag 79% of the heads of the 214 code PRs that changed a
  perf test in 2026-11-12..21, their own speedups). Fail when stddevPop /
  median of the tested server's runs is above 0.5 (at least 5 runs). A
  spread the change causes also fails: after the merge both master servers
  run that code.

The bar 0.5 flags 0.5% of those code-PR heads and 0.2% of quiet tests'
master heads (CIDB backtest), and all 4 jobs of ClickHouse#122223. A query the trend
check already reports gets only its trend row. The reading loop of
find_run_trends moves to read_query_runs, shared by both checks;
run_trend_gate becomes changed_tests_gate.

Validated locally on downloaded job logs (no test of the test
infrastructure): ClickHouse#122223's 4 jobs fail (the old check passes them); the
new tests of ClickHouse#129328, ClickHouse#124553, ClickHouse#131203 (code PRs) and the tests-only
ClickHouse#130763, ClickHouse#129627 pass; the run-trend output is unchanged on all 1754 tests
of 14 jobs.

Related: ClickHouse#100759

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 22, 2026
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 forces in-order Parquet reading on every data file; limiting it to files with position deletes makes queries up to 8% faster

3 participants