Skip to content

Estimate hypothetical normal projections in EXPLAIN WHATIF - #118233

Merged
yariks5s merged 66 commits into
masterfrom
yarik/whatif-projection-estimate
Sep 23, 2026
Merged

yariks5s merged 66 commits into
masterfrom
yarik/whatif-projection-estimate

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 5, 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):

Provides the possibility to estimate hypothetical projections in WHATIF.


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

Version info

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

@mintlify

mintlify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Sep 10, 2026, 5:32 PM

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [673f321]

Summary: ✅


AI Review

Summary

This PR teaches EXPLAIN WHATIF to estimate normal hypothetical projections, adds the supporting docs/tests, and tightens the privilege handling around hypothetical projections. The feature is close, but the current estimator still diverges from the real normal-projection chooser in two cases, so I would not merge it yet.

Findings

⚠️ Majors

  • [src/Storages/MergeTree/WhatIfIndexEstimator.cpp:141-146,319-323] EXPLAIN WHATIF still leaves prefer_optimize_projection live while the real chooser folds it into the same relax_projection_checks path as force_optimize_projection. With prefer_optimize_projection = 1, optimizeUseNormalProjection may pick any usable projection even when it has no filter/sort advantage or reads more marks, but evaluateProjection still reports not_applicable / not chosen because only force_optimize_projection* and preferred_optimize_projection_name are stripped. That makes the new verdict contract false under an existing setting. Suggested fix: reset/strip prefer_optimize_projection together with the other projection-selection settings and document it as ignored, or thread it into evaluateProjection so the WHATIF verdict uses the same relaxed rule as the optimizer.
  • [src/Storages/MergeTree/WhatIfIndexEstimator.cpp:417-430,551-553] Projection estimates are still computed from analysis.parts_with_ranges even when selectRangesToRead() returned an unusable partial baseline because max_rows_to_read was exceeded on a table that already has real projections. The real normal-projection optimizer repairs that case by rebuilding an all-parts baseline before comparing candidates (src/Processors/QueryPlan/Optimizations/optimizeUseNormalProjection.cpp:471-485), but WHATIF forwards the truncated analysis directly into evaluateProjection. In that state the projection row can report marks, rows, and verdict for only a prefix of the table. Suggested fix: clone the optimizer's !analysis.isUsable() fallback before calling evaluateProjection, or suppress numeric projection estimates whenever the baseline analysis is incomplete.
Final Verdict

Request changes.

LLVM Coverage Report

Measured on commit 673f321.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.40% +0.10%

Changed lines: Changed C/C++ lines covered: 573/598 (95.82%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-projections Projections: precomputed layouts for accelerating queries (projection parts, maintenance). label Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 673f321b090a7ac1f7a9a1607a2a6fe99169075f was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@yariks5s yariks5s added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Sep 6, 2026
@CLAassistant

CLAassistant commented Sep 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ yariks5s
✅ alexey-milovidov
❌ Yarik Briukhovetskyi


Yarik Briukhovetskyi seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

return change.name == "enable_parallel_replicas"
return change.name == "force_optimize_projection"
|| change.name == "force_optimize_projection_name"
|| change.name == "preferred_optimize_projection_name"

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.

prefer_optimize_projection is still live here, but the real normal-projection chooser folds it into the same relax_projection_checks path as force_optimize_projection (optimizeUseNormalProjection.cpp:448-458, 617-633). That means EXPLAIN WHATIF ... SETTINGS prefer_optimize_projection = 1 can still report a usable hypothetical projection as not chosen (or even not_applicable when there is no filter / sort help) even though the actual optimizer would pick it regardless of mark cost.

Please either strip/reset prefer_optimize_projection alongside the other projection-selection settings, or thread it through evaluateProjection and document that it affects verdict.

@yariks5s
yariks5s added this pull request to the merge queue Sep 23, 2026
Merged via the queue into master with commit 174f438 Sep 23, 2026
349 of 350 checks passed
@yariks5s
yariks5s deleted the yarik/whatif-projection-estimate branch September 23, 2026 11:20
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
@clickhouse-gh clickhouse-gh Bot added comp-what-if What-if analysis: hypothetical indexes and projections that exist only in the catalog, and the es... and removed comp-projections Projections: precomputed layouts for accelerating queries (projection parts, maintenance). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-what-if What-if analysis: hypothetical indexes and projections that exist only in the catalog, and the es... pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard 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