Skip to content

Use iceberg row and column stats for Cascades CBO - #124857

Merged
Blargian merged 2 commits into
masterfrom
afilipovic-iceberg-stats-cascades
Nov 9, 2026
Merged

Blargian merged 2 commits into
masterfrom
afilipovic-iceberg-stats-cascades

Conversation

@antoniofilipovic

@antoniofilipovic antoniofilipovic commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Related: #120440
Related: #123085
Related: #123553
Related: #124395

The fourth PR for #120440, stacked on #124395. The Cascades optimizer seeds a read's group with the join reordering estimate (estimateStatistics), but only for ReadFromMergeTree; an Iceberg read got default statistics with 0 rows, so every join and exchange above it saw a free, empty input. With use_iceberg_manifest_statistics, an object storage read, alone or under a filter, now gets the estimate of #123085..#124395: rows after pruning and deletes, the selectivity of the filter above it, and the number of distinct values, min/max and NULL fraction of its columns.

  • A filter the estimate cannot account for keeps the live rows of the remaining files, an upper bound, as a MergeTree read keeps its selected rows.
  • max_row_count is the live rows of the remaining files (DataLakeReadEstimate::rows): pruning drops only files that cannot match, and an estimate of the conditions is not an upper bound.
  • avg_bytes per column is the width of its type: the manifests give only compressed sizes.
  • physical_read_bytes counts the live rows of the remaining files. The scan also reads the deleted rows, which are left out.

Without the settings, or without an estimate, the statistics stay as they were.

With for_runtime_filter_transport, estimateReadRowsCount does not estimate the conditions of an Iceberg read: the rows size a sent runtime filter, so they must be an upper bound, not a guess. Such a read gets the rows of the remaining files if pruning dropped a file, and no estimate otherwise, as a MergeTree read with a filter that its index does not use.

ReadFromObjectStorageStep now keeps the estimate as a shared_ptr and hands it out with getOrCreateDataLakeReadEstimate, as ReadFromMergeTree does with its analysis result, so join reordering and Cascades share one estimate without copying it. The checks of use_iceberg_manifest_statistics and use_statistics moved into it.

Cascades runs only for distributed plans, and an object storage read is serializable only in ClickHouse Cloud (ReadFromObjectStorageStep::isSerializable), so in this repository the query falls back to local execution before Cascades runs. The test is in the Cloud repository: a 100000-row Iceberg table joined with a 1000-row table, where Cascades built the hash table on the Iceberg read before and on the small table now; with a filter that keeps 5 rows, on the filtered Iceberg read.

Changelog category (leave one):

  • Improvement

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

With use_iceberg_manifest_statistics, the Cascades optimizer estimates Iceberg reads from the manifest files, as join reordering does, instead of treating them as empty.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5daf1ad]

Summary: ✅


AI Review

Summary

This PR supplies Iceberg manifest estimates to Cascades, shares the cached estimate with join reordering, and avoids using filter-selectivity guesses to size transported runtime filters. ⚠️ Request changes: the existing filtered-output width issue remains. The previously reported delete-count bound also remains, with the author's decision recorded below.

Findings

⚠️ Majors

  • Statistics.cpp:285–292: Filtered statistics must describe the filter's output. For FilterStep -> ReadFromObjectStorageStep, the helper computes output widths from the read's header. A read of k UInt64, payload String whose filter consumes and drops payload is priced at 72 bytes per output row instead of 8. Prepopulating the group bypasses deriveFilterStatistics, and the incorrect width feeds exchange and hash-table costs. Use node.step->getOutputHeader() for output widths and keep scan width separate. Existing thread.

  • Statistics.cpp:294: A proven maximum must not subtract potentially repeated deletes. [dismissed by author -- https://github.com/Use iceberg row and column stats for Cascades CBO #124857#discussion_r4327442095] The author intentionally retains the bound because normal ClickHouse and Spark writes produce disjoint deletes and the impact is limited to estimates. The concern remains: countDeletedRows sums delete-file counts, while IcebergBitmapPositionDeleteTransform unions positions. Two files deleting the same 60 positions from 100 rows therefore produce max_row_count = 0 for a read returning 40 rows, making subsequent aggregation estimates appear empty. Keep the surviving files' raw row count for the bound, or subtract only proven distinct deletes.

Missing context / blind spots
  • ⚠️ The PR describes a Cloud regression test, but the linked sync PR returned HTTP 404. Its test code and results could not be verified; provide an accessible commit or report. No local build or tests were run; this checkout has no build directory.
Tests
  • ⚠️ Add focused coverage for a filter that drops a predicate-only String column and assert the resulting Cascades output width.
  • ⚠️ Cover overlapping position deletes when asserting a proven row bound. Also verify that runtime-filter sizing retains configured limits when a selective filter prunes no files, and uses the remaining-file bound when pruning succeeds.
Final Verdict

⚠️ Request changes. Correct the filtered-output widths and add focused regression coverage. The dismissed bound concern remains recorded above; no duplicate inline comments or thread replies were posted.

@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Oct 9, 2026
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from 2b24c69 to 0723993 Compare October 13, 2026 08:30
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch 2 times, most recently from c38ba84 to 9602942 Compare October 19, 2026 10:24
@antoniofilipovic
antoniofilipovic removed this pull request from stack #124571 October 20, 2026 15:57
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from 9602942 to e36c483 Compare October 20, 2026 15:57
@antoniofilipovic
antoniofilipovic changed the base branch from afilipovic-iceberg-filter-selectivity to afilipovic-iceberg-deleted-rows October 20, 2026 15:57
@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 20, 2026
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from e36c483 to aa1f44c Compare October 22, 2026 12:13
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5daf1adae with master 84451f17e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 81120655d; 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.

Compile time of recompiled translation units

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

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse-keeper DB::DataLakeStorageSettingsTraits::Accessor::instance()::$_0::operator()() const new 99.37 KiB +99.37 KiB

Job report

@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from aa1f44c to 8611e57 Compare October 22, 2026 15:00
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from 358b673 to bf58262 Compare October 23, 2026 09:18
@scanhex12 scanhex12 self-assigned this Oct 23, 2026
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from bf58262 to bdfe9e6 Compare October 26, 2026 13:11
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from bdfe9e6 to e6dd88a Compare October 29, 2026 11:01
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from e6dd88a to 7718744 Compare October 29, 2026 12:30
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch 2 times, most recently from 31be022 to 71262c4 Compare November 2, 2026 11:04
@antoniofilipovic
antoniofilipovic marked this pull request as ready for review November 3, 2026 10:32
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch 2 times, most recently from 1921bd0 to bda765f Compare November 3, 2026 12:18
Base automatically changed from afilipovic-iceberg-deleted-rows to master November 3, 2026 20:04
@antoniofilipovic
antoniofilipovic force-pushed the afilipovic-iceberg-stats-cascades branch from bda765f to 3c56e31 Compare November 3, 2026 20:04
`ReadFromObjectStorageStep` is shared by every data lake, so it no longer reads `use_iceberg_manifest_statistics` and
`use_statistics`; `IcebergMetadata::estimateRead` returns no estimate when either is off, as before.

#124857 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@antoniofilipovic
antoniofilipovic added this pull request to the merge queue Nov 9, 2026
@hanfei1991 hanfei1991 self-assigned this Nov 9, 2026
@Blargian
Blargian removed this pull request from the merge queue due to a manual request Nov 9, 2026
@Blargian
Blargian added this pull request to the merge queue Nov 9, 2026
Merged via the queue into master with commit dfc56f5 Nov 9, 2026
368 of 369 checks passed
@Blargian
Blargian deleted the afilipovic-iceberg-stats-cascades branch November 9, 2026 21:36
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-improvement Pull request with some product 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.

5 participants