Skip to content

Iceberg bucket split improvements - #124890

Draft
scanhex12 wants to merge 12 commits into
masterfrom
iceberg-bucket-splitting-improvements
Draft

scanhex12 wants to merge 12 commits into
masterfrom
iceberg-bucket-splitting-improvements

Conversation

@scanhex12

@scanhex12 scanhex12 commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

  1. Introduce auto mod. It will split the task if the number of data files is not high
  2. Fill split_offsets stats to skip parquet file reading step

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

scanhex12 and others added 3 commits October 8, 2026 10:43
Splitting Parquet files into row group buckets (`cluster_table_function_split_granularity = 'bucket'`)
rarely paid off and silently lost Iceberg deletes:

- The initiator read the footer of every file synchronously, under the mutex of the task
  distributor, with a HEAD request per file. Files whose size is known from the table metadata
  (Iceberg) are now cut into byte ranges without reading them, using the `split_offsets` of the
  manifest when present; the worker selects the row groups whose midpoint falls into its range.
  Files that still need a footer read are processed ahead of time in a thread pool.
- The copies of an `IcebergDataObjectInfo` made for the buckets were sliced to `ObjectInfo`, so the
  workers did not receive the position and equality delete files. `ObjectInfo::clone` keeps the type.
- The default `cluster_table_function_buckets_batch_size` of 0 made a task per row group; it is now
  128 MiB, and files smaller than that are not split.
- `cluster_table_function_split_granularity = 'auto'` splits only when there are fewer files than
  reading threads in the cluster. `IcebergIterator::estimatedKeysCount` uses the live file counts
  of the manifest list for that.
- Position delete transforms open the delete files lazily, when the reader knows which rows of the
  data file it outputs, and read only the positions of that range.
- Workers keep a request for the next task in flight while processing the current one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…f buckets

The requests for tasks that a worker keeps in flight are not answered in the order they were
scheduled, so an empty answer to one of them did not mean that the others were empty too: a
later request could have received the last task, which was then dropped. Collect the answers
of all requests in flight before declaring the task stream exhausted.

`SELECT count()` over Parquet files split into buckets returned the row count of the whole file
for every bucket; count the rows of the selected row groups instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…split_offsets`

The number of pieces of a file is now the larger of `size / cluster_table_function_buckets_batch_size`
and `8 * reading threads of the cluster / number of files`, capped by the number of row groups.
Row groups are assigned to pieces by their midpoint, the same rule the reader uses for byte
ranges, so pieces are even and never empty. With few large files, six pieces for three reading
threads left most of the cluster idle at the tail; now there are about eight tasks per thread.
`auto` splits when there are fewer files than that target.

Fixed byte ranges guessed from the file size are gone: without `split_offsets` the initiator reads
the footer (in the thread pool) instead of producing tasks that select no row group.

The Iceberg writer now records the row group offsets of every data file in `split_offsets`, so
tables written by ClickHouse are cut without reading their footers, like those written by Spark.

Also remove the explanatory comments added to the code in the previous commits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 marked this pull request as draft October 9, 2026 12:01
Removes `RowRangeToReadGetter.h`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 9, 2026
scanhex12 and others added 2 commits October 9, 2026 13:10
…condition cache

A reader of a bucket reported the row groups of the other buckets of the file as not matching the
condition, and the cache key covers the whole file. Every bucket overwrote the others, so a later
read of the whole file with the same condition skipped almost all row groups and returned wrong
results (`file` granularity after `bucket` on Iceberg TPC-H: 985857 rows instead of 29577564).
Row groups the reader did not process are now reported as possibly matching.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A task for a whole file already keeps all threads of a node busy, because the Parquet reader
reads row groups in parallel, so files only need to be split to balance the work between nodes.
Counting reading threads made the target 864 tasks on a 3-node cluster with 36 threads per node,
and every file was cut down to single row groups, the most expensive way to split it.

`auto` now splits when there are fewer files than four times the number of nodes.

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

Copy link
Copy Markdown
Member Author

TPC-H on Iceberg: ClickHouse cluster without splitting, with splitting from this branch, and Trino

Setup

  • One machine: 36 vCPU (Intel Xeon Platinum 8223CL), 69 GB RAM. The engines were run one after another, never at the same time.
  • Data: TPC-H SF5 generated by Trino (tpch connector) into Iceberg tables, Parquet, stored in MinIO, registered in an Iceberg REST catalog (apache/iceberg-rest-fixture). Both engines read the same tables through the same catalog.
  • Three layouts of the same data:
    • few large files: one writer per Trino worker, 3 files per table, lineitem files of up to 258 MB with 11 row groups each;
    • Trino default: lineitem is 27 files of up to 79 MB with one row group each, so there is nothing to split;
    • one file: lineitem alone written as a single file of 767 MB with 30 row groups, used for the scan queries.
  • ClickHouse: 3 servers forming one cluster. Tables are read through DataLakeCatalog with enable_parallel_replicas = 1, cluster_for_parallel_replicas = '<the 3-node cluster>', max_parallel_replicas = 3, join_use_nulls = 1, everything else default.
    • master at 41ffcf2a3af with cluster_table_function_split_granularity = 'file';
    • this branch at ddf3938ce9c with 'bucket' and with 'auto', default cluster_table_function_buckets_batch_size. The branch aims at four tasks per node: 'bucket' always splits, 'auto' splits only when there are fewer files than that.
  • Trino 483: a coordinator (not scheduling work) and 3 workers, 10 GB heap each.
  • Queries: tests/benchmarks/tpc-h/queries. Q11 uses the SF5 constant. Q2, Q4, Q17, Q20, Q21 and Q22 are decorrelated for ClickHouse (joins with grouped subqueries), because correlated subqueries are not supported with remote tables; their results were checked against Trino. Q6 and Q15 are excluded: on DOUBLE columns the two engines return different results for them.
  • Time is the server-side elapsed time (X-ClickHouse-Summary for ClickHouse, the statement stats for Trino), the best of 3 runs for TPC-H and of 5 for the scans, in milliseconds.

Scans of one large file

query ClickHouse master, no splitting ClickHouse branch, 'bucket' ClickHouse branch, 'auto' Trino
TPC-H Q1 307 271 270 268
filter + aggregate 143 116 116 129
wide scan 471 341 344 579

TPC-H, few large files

query ClickHouse master, no splitting ClickHouse branch, 'bucket' ClickHouse branch, 'auto' Trino
Q01 283 270 269 274
Q02 581 569 613 427
Q03 1206 1147 1177 1182
Q04 1562 1533 1527 1180
Q05 1359 1333 1378 1299
Q07 1463 1599 1475 977
Q08 1789 1813 1921 2194
Q09 2346 2330 2233 1003
Q10 1907 1438 1358 1557
Q11 271 317 323 265
Q12 1077 1419 1211 655
Q13 323 320 310 1309
Q14 1008 933 640 1174
Q16 248 268 242 765
Q17 1578 1231 1265 407
Q18 1172 943 992 2219
Q19 1348 1873 1899 636
Q20 474 484 457 399
Q21 2207 1409 1500 1605
Q22 338 295 291 293
total 22540 21524 21081 19820

TPC-H, Trino default layout

query ClickHouse master, no splitting ClickHouse branch, 'bucket' ClickHouse branch, 'auto' Trino
Q01 282 305 284 438
Q02 627 601 574 487
Q03 1092 1200 1230 1440
Q04 1737 1513 1448 1268
Q05 1360 1457 1339 1651
Q07 1608 1579 1462 1193
Q08 1917 2082 1772 2277
Q09 2197 2573 2136 1372
Q10 1197 1589 1566 2083
Q11 252 304 289 359
Q12 1319 1306 1211 775
Q13 512 507 500 1318
Q14 1000 1043 1171 1280
Q16 231 248 247 910
Q17 1371 1399 1469 622
Q18 1090 928 967 2335
Q19 1889 1853 1879 763
Q20 567 560 592 549
Q21 1720 1837 1534 2134
Q22 388 371 404 492
total 22356 23255 22074 23746

Notes

  • Splitting pays off when there are fewer files than nodes: on one file, three nodes instead of one cut scan times by 20-28%.
  • On TPC-H the totals stay within run-to-run noise, single queries vary by up to 15% between runs. In cluster mode only the reading runs on the replicas while the joins run on the initiator, and the joins take most of the time. A replica reading a whole file already uses all its cores through the Parquet reader, so files only need to be split to balance the work between nodes.
  • 'auto' has the best total on both layouts. On the Trino default layout it does not split (27 files for 3 nodes), while 'bucket' splits and is about 4% slower.
  • Two issues in master were found while running this:
    • A read of one bucket stored the row groups of the other buckets as unmatched in the query condition cache, under a key for the whole file. A later read of the whole file with the same condition skipped almost all row groups: 985857 rows instead of 29577564. Fixed in this branch.
    • With parallel replicas, SELECT count() FROM orders WHERE o_orderkey IN (SELECT l_orderkey FROM lineitem) over DataLakeCatalog tables returns 0 instead of 7500000; it is correct without parallel replicas. Not fixed here; Q4 was rewritten as a join with DISTINCT to work around it.

@scanhex12

Copy link
Copy Markdown
Member Author
image

@scanhex12

Copy link
Copy Markdown
Member Author
image

…replica

The initiator's own replica asks for `max_threads` tasks at once, before the other replicas have
received the query. When the iterator was exhausted, the distributor gave it the files queued for
the other replicas as well, so a table of three files on three nodes was read by one node (3/0/0
tasks; with `max_threads = 4` it was 1/1/1). The distributor now waits up to one second for the
owner of a file to connect before giving the file to someone else, and among replicas that are
already working it takes the file from the one with the most remaining files.

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

Copy link
Copy Markdown
Member Author
image image image image

scanhex12 and others added 2 commits October 12, 2026 15:12
In a query with several tables, every replica received `SELECT columns FROM table` without the
filter on that table: `ReadFromCluster::applyFilters` used the pushed-down filter only to prune
files on the initiator, so the replicas read and shipped every row and the initiator filtered them
(TPC-H Q12 on Iceberg: 575 MiB over the network). The conjuncts of the pushed-down filter that are
made of the read columns, constants, constant `IN` lists and registered deterministic functions are
now added to the `WHERE` of the query sent to the replicas (Q12: 77 MiB, 1195 ms -> 367 ms). The
filter above the read stays, so the replicas only drop rows that it would drop anyway.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a replica takes a task of another one, it takes it from the replica with the most remaining
bytes, counting the byte range of a bucket or the file size, instead of the most remaining tasks:
a few large files and many small ones are no longer balanced by count.

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

Copy link
Copy Markdown
Member Author
image image image image

…tting-improvements

Most of this branch landed through separate PRs:
#125611
#125615
#125636
Their versions are kept. Bucket splitting by `min_buckets` is applied on
top of the greedy splitter of master, the weight of a byte range bucket is
capped by the file size, byte ranges are gated by
`cluster_table_function_split_by_split_offsets`, and the duplicate test of
the filter pushdown is removed.

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

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a46cef6]

Summary: ❌

job_name test_name status info comment
Style check FAIL
various FAIL cidb
Build (arm_tidy, 1/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 2/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 3/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 4, 2026
@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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

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-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants