Skip to content

Return original trivial count optimization - #123267

Merged
scanhex12 merged 2 commits into
masterfrom
iceberg-total-rows-parallel-manifests
Oct 2, 2026
Merged

scanhex12 merged 2 commits into
masterfrom
iceberg-total-rows-parallel-manifests

Conversation

@scanhex12

@scanhex12 scanhex12 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Return original trivial count optimization


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

Version info

  • Merged into: 26.10.1.1240-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [74114ce]

Summary: ✅


AI Review

Summary

This PR restores the Iceberg trivial count() fast path by trusting snapshot-summary row counts again and updates the tests/fixtures to match that behavior. I do not think it is safe to merge as-is: the new early return reintroduces the same exactness bug that the previous manifest-based implementation fixed, so SELECT count() and planner row estimates can become wrong again on snapshots whose summary counters diverge from the live manifests.

Missing context / blind spots
  • ⚠️ The Praktika report currently shows only Build profile diff; I could not validate the functional Iceberg jobs that exercise the changed count() path. A completed Stateless tests run would close that gap.
Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp:1311] totalRows() now returns snapshot.summary.total-records - total-position-deletes before it inspects any live manifests. That breaks the exact-count contract in the same two ways the removed tests covered: a corrupted historical commit can silently poison total-records for every later snapshot, and raw position-delete record counts are not exact because delete files can duplicate positions or point at data files that are no longer live. As a result, both SELECT count() and planner statistics can become arbitrarily wrong again. Keep the manifest-file scan as the source of truth, or at minimum validate the summary against the live manifest record_count totals and prove there are no live delete files before using it.
Final Verdict

❌ Changes requested.

LLVM Coverage Report

Measured on commit 74114ce.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 19/23 (82.61%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 1, 2026
Comment on lines +1306 to +1309
if (auto total_rows = actual_data_snapshot->getTotalRows(); total_rows.has_value())
{
ProfileEvents::increment(ProfileEvents::IcebergTrivialCountOptimizationApplied);
return total_rows;

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.

Returning snapshot.summary.total-records - total-position-deletes here makes count() trust writer-maintained summary hints again before we inspect the manifests. That regresses the exactness contract in two ways we already model in-tree: a corrupted historical commit can silently poison total-records, and live delete files still make the summary non-exact (tests/queries/0_stateless/04612_iceberg_count_position_deletes_corrupted_summary.sh documents the 100 - 2 = 98 failure). Because this early return runs before the delete-file guard below, both SELECT count() and the planner statistics built on totalRows() can become arbitrarily wrong for Iceberg tables. Please keep the manifest-file scan as the source of truth, or at minimum prove there are no live delete files and validate the summary against manifest record_count before using it.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 74114ce57 with master 28dc98b1f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 0982e5a39; 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

35 object files changed (+46.20 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Transforms/Window/SlidingBlocks.cpp.o new 34.98 KiB +34.98 KiB
src/CMakeFiles/dbms.dir/Processors/Transforms/WindowTransform.cpp.o 160.67 KiB 136.67 KiB -24.00 KiB (-14.94%)

719 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.

Compile time of recompiled translation units

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

Job report

Do not answer the trivial count from the snapshot summary when the snapshot
has equality deletes (`total-equality-deletes` is missing or non-zero): their
record count is the number of predicates, not of deleted rows.

Adjust the tests to the summary-based count: drop the corrupted-summary part
of `04612_iceberg_count_position_deletes_corrupted_summary`, remove
`total-records` from the `04615_iceberg_count_negative_record_count` fixture,
and disable `optimize_trivial_count_query` in tests that expect `count` to
read corrupted manifests.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123267&sha=latest&name_0=PR
PR: #123267

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@scanhex12 scanhex12 self-assigned this Oct 1, 2026
@scanhex12
scanhex12 enabled auto-merge October 1, 2026 20:46
@scanhex12
scanhex12 disabled auto-merge October 1, 2026 20:47
@scanhex12
scanhex12 enabled auto-merge October 1, 2026 20:47
@scanhex12
scanhex12 added this pull request to the merge queue Oct 1, 2026
Merged via the queue into master with commit 77f18e5 Oct 2, 2026
148 of 149 checks passed
@scanhex12
scanhex12 deleted the iceberg-total-rows-parallel-manifests branch October 2, 2026 01:21
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
alexey-milovidov added a commit that referenced this pull request Oct 2, 2026
…ata-cross-check

Conflict resolution: master (#123267) returned
the summary-based trivial count for Iceberg: `IcebergMetadata::totalRows` answers from
`IcebergDataSnapshot::getTotalRows` when the snapshot summary provides a usable count. Keep that
design, and keep this PR's cross-check of the snapshot summary's `total-records` only on the
fallback path that sums the manifest files. Accept the deletion of
`04611_iceberg_count_ignores_corrupted_snapshot_summary` and
`04614_iceberg_count_malformed_manifest_row_counts` from master.
alexey-milovidov added a commit that referenced this pull request Oct 2, 2026
…sed count

Master (#123267) answers the trivial count from the
snapshot summary when it provides a usable row count, so a table whose manifest files over-report
the per-file `record_count` is now counted from the summary, with the optimization applied. Drop
the corrupted-summary case, which master deliberately no longer guards against.

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

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... 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.

2 participants