Skip to content

Check Cancellation in Window Aggregation State - #130328

Merged
Michicosun merged 1 commit into
masterfrom
window_functions_recalculate_cancellation
Nov 10, 2026
Merged

Michicosun merged 1 commit into
masterfrom
window_functions_recalculate_cancellation

Conversation

@Michicosun

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

Do cancellation checks periodically in recalculated window aggregate functions.

Fixes #129940


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

Version info

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

@yariks5s yariks5s self-assigned this Nov 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ededa4]

Summary: ✅


AI Review

Summary

PR #130328 adds a persistent CancellationBudget to AggregateState, checking the query's killed flag and elapsed-time limit between aggregate input segments. Review of head 5ededa4ef0679060211247b74531104fe0e1a660 found no new inline findings. Regression coverage remains insufficient; the two previously discussed cancellation limitations remain accepted follow-up work.

Findings

⚠️ Majors

  • src/WindowFunctions/Aggregate/AggregateState.cpp:79 — No regression test proves cancellation during recalculation. [dismissed by author -- https://github.com/Check Cancellation in Window Aggregation State #130328#discussion_r4513408984] The current diff still contains no tests. 01572_kill_window_function.sh kills as soon as the query enters system.processes, potentially before sorting or aggregation, so it can pass with this checkpoint removed. Add focused stateless coverage that reaches expensive frame recalculation and demonstrates bounded cancellation and timeout enforcement.
  • src/WindowFunctions/Aggregate/AggregateState.cpp:39 — Processor-only cancellation remains invisible to the callback. [dismissed by author -- https://github.com/Check Cancellation in Window Aggregation State #130328#discussion_r4514995447] The current gRPC path calls PullingAsyncPipelineExecutor::cancel, which cancels the processor graph without marking QueryStatus killed. With no execution limit, the callback therefore keeps succeeding during recalculation. This remains real, but the author's decision to fix it separately is accepted; observe processor cancellation in that follow-up.
  • src/WindowFunctions/Aggregate/AggregateState.cpp:79 — Outer-row charging does not bound expensive aggregate work. [dismissed by author -- https://github.com/Check Cancellation in Window Aggregation State #130328#discussion_r4515030497] A suffix-window sumArray(range(1000000)) over 128 rows charges only 8,256 units, below the 65,536-unit checkpoint threshold, while adding 8.256 billion array elements. The current code still makes no budget callback in that example; the thread reports 11.8 seconds with max_execution_time = 1. This existing limitation is accepted for separate work; checkpoints must eventually account for nested work or elapsed time.
Tests
  • ⚠️ Add a stateless regression using an expensive moving or suffix frame. Demonstrate that it fails with budget.chargeUnits removed and passes at this head; cancellation must land during aggregation rather than merely during input or sorting. Cover KILL QUERY and max_execution_time. No local runtime tests were executed during this review.
Final Verdict

Status: ⚠️ Request changes — minimum action: add regression evidence that exercises the new checkpoint. The two existing implementation limitations above remain non-blocking follow-ups. All existing threads were resolved by the author and were left untouched; no duplicate comments or new review batch were posted.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5ededa4ef with master 5c1a21488 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of ad36c6520; 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

7 object files changed (+32.35 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/WindowFunctions/Aggregate/AggregateState.cpp.o 11.84 KiB 43.73 KiB +31.88 KiB (+269.20%)

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

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

Job report

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). ignore-unresolved-threads Do not limit CI and block merge on unresolved review threads 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.

Window aggregate batches skip cancellation: KILL QUERY waits minutes

4 participants