Skip to content

Introduce SlidingArguments for WindowTransform - #128726

Merged
Michicosun merged 6 commits into
masterfrom
window_functions_sliding_arguments
Nov 4, 2026
Merged

Michicosun merged 6 commits into
masterfrom
window_functions_sliding_arguments

Conversation

@Michicosun

@Michicosun Michicosun commented Nov 2, 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):

This patch improves the performance of the argument preparation phase during window transform calculation.

Closes: #127659


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

Version info

  • Merged into: 26.11.1.1334-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0980440]

Summary: ✅


AI Review

Summary

The PR replaces repeated retained-block scans with incremental argument caching for window functions. Focused local measurements confirm the intended scaling improvement, but the cache also retains unused entries for aggregate-only windows. Request changes to avoid that resource regression.

PR Metadata

💡 The change is a Performance Improvement. The required changelog entry is present, but should explain the affected workload. Suggested replacement:

### Changelog category (leave one):
- Performance Improvement

### Changelog entry:
Improve window-function performance, including `lagInFrame`, for partitions spanning many small input blocks by avoiding repeated scans of retained blocks when preparing arguments.
Missing context / blind spots
  • ⚠️ CI for head 0980440e was pending during review. Local checks used d2c83633, whose changed C++ files match the reviewed head. The comparison binary, 0fc3c803, also predates the output-queue and bounds changes, so total before/after memory differences cannot be attributed solely to this cache.
Findings

⚠️ Majors

  • src/Processors/Transforms/Window/SlidingArguments.cpp:23–25: Aggregate-only windows retain argument caches they never consume. The constructor includes every function, and add retains a block record per function per input block, plus pointer vectors for functions with arguments. Only general functions consume these caches; aggregates read through their workspaces. An unbounded preceding frame therefore accumulates unused cache data across the partition. Cache only general functions with arguments, retaining the original function-index mapping. In local runs of the five-aggregate reproduction in the linked comment, median peak memory was approximately 124 MiB versus 66 MiB on the older baseline; the comparison limitation is stated above.

💡 Nits

  • Use the performance category and workload-specific changelog entry shown above.
Final Verdict

⚠️ Request changes — exclude aggregates and argument-free functions from retained argument caches.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 2, 2026
@yariks5s yariks5s self-assigned this Nov 2, 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 Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0980440e3 with master ef3ab708d (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 0a399a7ff; 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

11 object files changed (+34.31 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Transforms/Window/SlidingArguments.cpp.o new 49.93 KiB +49.93 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

15 translation units recompiled, 27 s compile time in total, 14 of them have a recent master baseline.

Job report

@Michicosun
Michicosun added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit 5fdd3ce Nov 4, 2026
186 checks passed
@Michicosun
Michicosun deleted the window_functions_sliding_arguments branch November 4, 2026 14:23
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2026
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-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.

Window functions batch execution (#127389): every batch walks all retained blocks

3 participants