Skip to content

Introduce Frame Abstraction for WindowTransform - #124175

Merged
Michicosun merged 40 commits into
masterfrom
window_functions_model_frame
Oct 13, 2026
Merged

Michicosun merged 40 commits into
masterfrom
window_functions_model_frame

Conversation

@Michicosun

@Michicosun Michicosun commented Oct 6, 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 the frame abstraction needed for window calculation in the window transform and isolates border-related logic into separate files.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9aa30a1]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, parallel) ERROR

AI Review

Summary

This PR refactors WindowTransform around explicit Frame, Partition, and SlidingIndexes helpers, and it broadens stateless coverage for block-boundary, NULL, NaN, and GROUPS / RANGE behavior. The refactor itself looks internally consistent and the CI surface is green, but the already-discussed explicit-ROWS peer-semantics bug is still present at the current head and the new tie-free coverage still does not exercise it.

Missing context / blind spots
  • ⚠️ The dedicated performance-comparison shards were skipped because the PR is not labeled pr-performance, so the runtime cost of replacing peer-group start bits with per-row Int64 group indexes is not fully validated here. The available Build profile diff report is clean, but it is not a substitute for end-to-end query timings on this hot path.
Findings

⚠️ Majors

  • [src/Processors/Transforms/WindowTransform.cpp:331] [dismissed by author -- https://github.com/Introduce Frame Abstraction for WindowTransform #124175#discussion_r4212953552] Peer identity is still derived from the frame type, so an explicit ROWS frame still collapses tied ORDER BY keys into one-row "peer groups" before rank, dense_rank, and percent_rank run. That is the known 1, 1, 2 -> 1, 2, 3 bug: it is not newly introduced here, but it is still present in the current code, and the new block-boundary coverage orders by k, id, so it does not protect this refactor from regressing the tied-key case.
    Suggested fix: keep peer grouping keyed only by ORDER BY equality and add an explicit tied-key ROWS case to tests/queries/0_stateless/05293_window_functions_block_boundaries.sh.
Final Verdict

✅ I did not find a new PR-introduced blocker in the refactor itself, so I am not adding a new inline review batch. The one substantive concern that remains is the previously discussed explicit-ROWS peer-semantics bug, which is still present at this head and still uncovered by the new tests.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-window-functions Window function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order). labels Oct 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

See the job log for details.

@Michicosun Michicosun added the ci-performance performance only label Oct 7, 2026
@Michicosun Michicosun removed the ci-performance performance only label Oct 7, 2026
@yariks5s yariks5s self-assigned this Oct 8, 2026

@yariks5s yariks5s left a comment •

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.

The changes are good for me, though they show memory and speed degradation in some niche corner cases. They are mostly because of the index representation in the form of this "row belongs to group…" instead of "a peer group starts here" which takes 8 bytes instead of one bit

I'm checking what we can do here, but it is not a blocker for me. Design-wise and execution-wise, it is good

Upd: this makes it faster, but I'm not sure we should proceed with it fix.patch

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 9, 2026
…sets

`compareNullableRangeOffset` ranks NULL below every value and never sees
`nulls_direction`, so with NULL rows a `RANGE` offset frame is wrong under
`NULLS LAST` (the default for `ASC`) and `DESC NULLS FIRST`, as `05269`
documents for the `Nullable(Int32)` keys master already supports. On a
`Nullable(Decimal32(1))` key over [NULL, 1, 2, 3, NULL], `count() OVER
(ORDER BY n RANGE 1 PRECEDING)` gave 4 for the NULL rows instead of 2, and
`DESC NULLS FIRST` gave every row the whole partition. Master rejects the
key with `NOT_IMPLEMENTED`, so routing it through that comparator would
turn an error into wrong results.

The four decimal widths now get a comparator only for a non-`Nullable`
key; a `Nullable` one keeps master's `NOT_IMPLEMENTED` until the NULL
ordering honours `NULLS LAST` (ClickHouse#124175). The `Nullable` arms leave
`02892`, and `05257` pins the rejection next to the other unsupported key
types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Michicosun Michicosun added the ci-performance performance only label Oct 12, 2026
@Michicosun Michicosun removed the ci-performance performance only label Oct 12, 2026
@Michicosun Michicosun added the ci-performance performance only label Oct 13, 2026
@Michicosun Michicosun removed the ci-performance performance only label Oct 13, 2026
@Michicosun
Michicosun enabled auto-merge October 13, 2026 16:03
@Michicosun
Michicosun added this pull request to the merge queue Oct 13, 2026
Merged via the queue into master with commit f87328f Oct 13, 2026
346 of 349 checks passed
@Michicosun
Michicosun deleted the window_functions_model_frame branch October 13, 2026 23:37
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 14, 2026
ClickHouse#124175 replaced the per-row peer group start flags in SlidingIndex with
peer group indexes, so the separate ORDER BY index used by rank and
dense_rank under a ROWS frame is now an index too. It is computed by
master's assignPeerGroupIndexes with the frame type and the collation
comparison passed in, instead of a second copy of that logic, and the
transform moves order_by_peer_group_start when the index changes, the
same way master moves peer_group_start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickgapai

Copy link
Copy Markdown
Contributor

@Michicosun @yariks5s — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

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.

4 participants