Skip to content

Introduce WindowTransformParams - #122762

Merged
Michicosun merged 13 commits into
masterfrom
window_functions_model_params
Sep 30, 2026
Merged

Michicosun merged 13 commits into
masterfrom
window_functions_model_params

Conversation

@Michicosun

@Michicosun Michicosun commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

This patch introduces WindowTransformParams, similar to AggregatingTransformParams, to reduce code complexity in the WindowTransform.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f11edc2]

Summary: ✅


AI Review

Summary

This PR extracts window-frame setup, ORDER BY index bookkeeping, and RANGE offset comparator selection from WindowTransform into WindowTransformParams, and adds a regression test for float NaN / Inf handling. I reviewed the final diff, the touched window-function consumers, and the resolved discussion threads, and I did not find a remaining correctness or compatibility issue in the current code.

Missing context / blind spots
  • ⚠️ I did not run the modified stateless tests locally because this checkout has no build artifacts or clickhouse binary available. A targeted run of 05293_window_functions_range_offset_nan together with the existing date-key RANGE tests would close that gap.
  • ⚠️ Praktika currently exposes only the build-profile report for this PR, so there is no current full CI or perf-comparison result for the latest head to validate the acknowledged hot-path performance tradeoff.
Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit f11edc2.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 232/237 (97.89%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 28, 2026
@yariks5s yariks5s self-assigned this Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-window-functions Window function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order). label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f11edc219 with master e28af044e (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.

Object file sizes

15 object files changed (+72.55 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Transforms/Window/WindowTransformParams.cpp.o new 182.25 KiB +182.25 KiB
src/CMakeFiles/dbms.dir/Processors/Transforms/WindowTransform.cpp.o 268.31 KiB 159.79 KiB -108.53 KiB (-40.45%)

716 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

20 translation units recompiled, 44 s compile time in total, 19 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR only restructures window-function execution: it moves the WindowTransform setup into a new WindowTransformParams and replaces a std::function with a plain function pointer for the RANGE OFFSET comparator. No query in clickbench or tpch_adapted_1_official uses window functions. The two flagged improvements, clickbench Q31 (-11.5%) and Q34 (-11.0%), are plain GROUP BY aggregations that never reach the changed code. Both are downgraded to not sure: the PR medians fall inside master's current-era range, and the baseline had only 5 runs after a recent master shift, so no performance change can be attributed to this PR.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 31 not_sure 295 261 -11.5% <0.0001 aggregation: Q31 is a GROUP BY aggregation with no window functions, so it never runs the refactored WindowTransform code. The -11.5% is inside master's current range of 252-334.5 ms, measured against a thin 5-run baseline.
⚠️ 34 not_sure 1269 1129 -11.0% <0.0001 aggregation: Q34 is a GROUP BY/ORDER BY aggregation that uses no window functions, so the WindowTransform refactor is off its path. The -11.0% is inside master's current range of 1095-1373 ms.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: f51bbd5d-88df-463b-815b-833f9d7d73fd
  • MIRAI run: 4abefb3a-6197-4ac5-9133-c879c9aa3b3f
  • PR check IDs:
    • clickbench_2466475_1790725167
    • clickbench_2466481_1790725167
    • clickbench_2466487_1790725167
    • tpch_adapted_1_official_2466498_1790725167
    • tpch_adapted_1_official_2466510_1790725167
    • tpch_adapted_1_official_2466546_1790725167

@Michicosun
Michicosun added this pull request to the merge queue Sep 30, 2026
Merged via the queue into master with commit 845f22c Sep 30, 2026
150 checks passed
@Michicosun
Michicosun deleted the window_functions_model_params branch September 30, 2026 08:25
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 7, 2026
…Params peer check

Master's window refactor (ClickHouse#122762, ClickHouse#123260, ClickHouse#123737) moved the peer comparison into
WindowTransformParams::arePeers and added SlidingIndexes, which marks peer-group starts for every
RANGE and GROUPS frame with raw compareAt / getEqualRangeEndAssumeSorted. The input is sorted with
the ORDER BY collator, so collation-equal values that differ in bytes (for example 'a' and 'A'
under 'en-u-ks-level2') are interleaved, and the raw scan either cuts a peer group short or trips
the debug check "Equal values are not contiguous within the range assumed to be sorted". Since
ClickHouse#123737 this aborts deterministically for an ordinary collated rank():

    SELECT rank() OVER (ORDER BY x COLLATE 'en-u-ks-level2')
    FROM (SELECT if(number % 2, 'a', 'A') AS x FROM numbers(1000))

The previous version of this fix lived in WindowTransform methods that the refactor removed, so
it is re-done on the new structure. WindowTransformParams gets the collation flag and two helpers,
haveEqualOrderByValues and getOrderByEqualRangeEnd, and every ORDER BY peer comparison goes
through them: arePeers (cume_dist and the GROUPS cross-block check), the SlidingIndexes block
boundary and in-block scan, the RANGE frame-end check and scan, and the GROUPS peer-group scan.
PARTITION BY keys stay raw, as PARTITION BY cannot carry COLLATE.

The helpers are inline in the header with the collated comparison in out-of-line cold functions,
so an uncollated window keeps the inlined raw comparison of master: the earlier out-of-line
version of these calls cost 15-19% on window_function_with_order in the arm performance check.

The test gains the deterministic 1000-row case above (also for GROUPS), a cume_dist case and a
one-row-per-block rank() case, so each of the six comparison sites has an assertion that fails
when only that site compares raw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-window-functions Window function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order). pr-not-for-changelog This PR should not be mentioned in the changelog 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