Skip to content

Introduce Partition Abstraction for WindowTransform - #123260

Merged
Michicosun merged 16 commits into
masterfrom
window_functions_model_partition
Oct 3, 2026
Merged

Michicosun merged 16 commits into
masterfrom
window_functions_model_partition

Conversation

@Michicosun

@Michicosun Michicosun commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Based on #123026

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 adds a row-range partition abstraction to simplify the WindowTransform logic.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9b5ee1c]

Summary: ✅


AI Review

Summary

This PR refactors WindowTransform to track partition boundaries through the new Partition / SlidingIndexes helpers instead of the inlined partition-end scanner, and adds a stateless regression test for window functions over chunks with no input columns. I reviewed the current diff, the follow-up commits, the existing review threads, and the CI signal, and I did not find a correctness, safety, or contract issue in the final code.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 9b5ee1c.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 162/163 (99.39%) · 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 Oct 1, 2026
@yariks5s yariks5s self-assigned this Oct 1, 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 Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9b5ee1c97 with master b1f44e396 (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

13 object files changed (+41.49 KiB total), 2 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Transforms/Window/SlidingIndexes.cpp.o new 21.17 KiB +21.17 KiB

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

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

Job report

@Michicosun
Michicosun enabled auto-merge October 3, 2026 07:01
@Michicosun
Michicosun added this pull request to the merge queue Oct 3, 2026
Merged via the queue into master with commit 41857bb Oct 3, 2026
294 of 295 checks passed
@Michicosun
Michicosun deleted the window_functions_model_partition branch October 3, 2026 08:06
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 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