Skip to content

Enable optimize_move_to_prewhere_if_final by default - #121350

Merged
yakov-olkhovskiy merged 15 commits into
masterfrom
yarik/enable-move-to-prewhere-if-final
Sep 25, 2026
Merged

yakov-olkhovskiy merged 15 commits into
masterfrom
yarik/enable-move-to-prewhere-if-final

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Related: #109538
Related: #109703

Changelog category (leave one):

  • Performance Improvement

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

Setting optimize_move_to_prewhere_if_final is now enabled by default, so queries with FINAL benefit from the automatic PREWHERE optimization. Only deterministic conditions over the sorting key are moved, and query results are not affected.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f434783]

Summary: ✅


AI Review

Summary

This PR flips optimize_move_to_prewhere_if_final to the 26.10 default, records the compatibility change, adds focused FINAL/float-key regression coverage plus a targeted performance test, and updates lazy FINAL expectations for the new default. I did not find a remaining correctness, compatibility, or evidence gap in the current merge result; the earlier float row-policy blocker is already covered by the required follow-up PR 121782, which merged into master on 2026-09-24.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit f434783.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 21, 2026
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 8a89c13b-ae33-4b4c-a897-72fd56dadef9
  • MIRAI run: b4e8471e-03ac-44e0-bd4a-4a1663bda8ea
  • PR check IDs:
    • clickbench_1781166_1790341968
    • clickbench_1781171_1790341968
    • clickbench_1781178_1790341967
    • tpch_adapted_1_official_1781189_1790341968
    • tpch_adapted_1_official_1781199_1790341967
    • tpch_adapted_1_official_1781237_1790341967

@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f43478330 with master 4cafc2605 (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.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 22, 2026
Comment thread src/Core/Settings.cpp Resolved
@yariks5s

Copy link
Copy Markdown
Member Author

Required: #121782

@yakov-olkhovskiy

Copy link
Copy Markdown
Member

@yariks5s there is an interesting finding (by an agent) in clickhouse-test itself:
https://github.com/ClickHouse/ClickHouse/blob/yarik/enable-move-to-prewhere-if-final/tests/clickhouse-test#L1879-L1881

# NOTE: optimize_move_to_prewhere_if_final is excluded because it triggers
# "Logical error: Input-output header mismatch after removing unused columns
# after pushing down filters to prewhere" (a real code bug).

and this PR flips this flag - and apparently no bugs are observed - seems like a stale workaround - probably it's worth to revert it in this PR...

Comment on lines +44 to +50
CREATE TABLE t_prewhere_final_float (a UInt64, f Float64, v UInt64) ENGINE = ReplacingMergeTree(v) ORDER BY (a, f);

INSERT INTO t_prewhere_final_float VALUES (1, 0.0, 1);
INSERT INTO t_prewhere_final_float VALUES (1, -0.0, 2);

SELECT count() FROM (EXPLAIN actions=1 SELECT * FROM t_prewhere_final_float FINAL WHERE toString(f) = '0') WHERE explain LIKE '%Prewhere filter%';
SELECT a, f, v FROM t_prewhere_final_float FINAL WHERE toString(f) = '-0';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an agent detected that toString(f) = '-0' returns 1 -0 2 in any case (checked on 26.10.1.551), recommendation is to flip it to the direction that fails WHERE toString(f) = '0' - must return nothing and returns 1 0 1 when the guard is missing (though SELECT count() should catch a regression)

also it would be good to bring here tests for NaN payloads, Nullable(Float64), Tuple(Float64, UInt8) and Array(Tuple(Float64, UInt8)), and the mixed-key control from #122142 - it is closed in favor of this PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@yakov-olkhovskiy
yakov-olkhovskiy added this pull request to the merge queue Sep 25, 2026
Merged via the queue into master with commit f614faa Sep 25, 2026
348 of 349 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. 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.

3 participants