Skip to content

fix(window): evaluate cumulative sum frames linearly - #27006

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:fix/23107-linear-window-frame
Aug 12, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:fix/23107-linear-window-frame

Conversation

@aunjgr

@aunjgr aunjgr commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23107

What this PR does / why we need it:

Recognizes ROWS frames ending at CURRENT ROW whose PRECEDING bound covers the runtime partition and evaluates SUM/AVG with one source-preserving running aggregate state. This avoids replaying every prefix for every output row while retaining state across bounded output chunks and resetting it at partition boundaries.

Aggregate executors must explicitly opt into the source-preserving Merge contract; aggregates whose Merge may consume the source retain the existing evaluator.

Adds prepared-bound, partition, NULL, cancellation, early Reset, multi-chunk, SQL regression, and benchmark coverage. The first-batch benchmark for the issue shape improves from about 3.0 s to about 1.25 ms locally.

Tests:

  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/window -count=1
  • .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/window -run '^$' -bench '^BenchmarkWindowFirstBatch$' -benchtime=5x -count=1

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 2b250e3. The linear path is gated to runtime ROWS frames equivalent to partition-start through CURRENT ROW and to aggregate executors whose Merge preserves the running source. I checked source-merge behavior, finite/prepared bounds, NULL/decimal behavior, chunk and partition continuation, cancellation/error cleanup, LIMIT-triggered Reset, and fallback for other aggregates. I found no reachable correctness, lifecycle, or normal-business regression blocker; required CI is green.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 2b250e3. The linear evaluator is correctly gated to ROWS frames equivalent to partition-start through CURRENT ROW and to aggregate executors with source-preserving Merge. I checked finite/prepared bounds, chunk and partition continuation, NULL/decimal semantics, cancellation/error/early-Reset cleanup, and fallback for consuming aggregate states. CGo tests for aggexec/window pass; the issue-shape benchmark is ~1.53 ms/op locally. No blocker found.

@mergify mergify Bot added the queued label Aug 12, 2026
@mergify

mergify Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-12 07:58 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-12 08:36 UTC · at 80a0c8983eeb7351e9e752feb4a2023b2aab944f

This pull request spent 38 minutes 7 seconds in the queue, with no time running CI.

Reason

Pull request #27006 has been merged manually at 052b2fd

Hint

You were too fast!

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 052b2fd into matrixorigin:main Aug 12, 2026
24 of 25 checks passed
@mergify mergify Bot removed the queued label Aug 12, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#23107

## What this PR does / why we need it:

Recognizes ROWS frames ending at CURRENT ROW whose PRECEDING bound
covers the runtime partition and evaluates SUM/AVG with one
source-preserving running aggregate state. This avoids replaying every
prefix for every output row while retaining state across bounded output
chunks and resetting it at partition boundaries.

Aggregate executors must explicitly opt into the source-preserving Merge
contract; aggregates whose Merge may consume the source retain the
existing evaluator.

Adds prepared-bound, partition, NULL, cancellation, early Reset,
multi-chunk, SQL regression, and benchmark coverage. The first-batch
benchmark for the issue shape improves from about 3.0 s to about 1.25 ms
locally.

Tests:
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/aggexec
./pkg/sql/colexec/window -count=1
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/window
-run '^$' -bench '^BenchmarkWindowFirstBatch$' -benchtime=5x -count=1

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#23107

## What this PR does / why we need it:

Recognizes ROWS frames ending at CURRENT ROW whose PRECEDING bound
covers the runtime partition and evaluates SUM/AVG with one
source-preserving running aggregate state. This avoids replaying every
prefix for every output row while retaining state across bounded output
chunks and resetting it at partition boundaries.

Aggregate executors must explicitly opt into the source-preserving Merge
contract; aggregates whose Merge may consume the source retain the
existing evaluator.

Adds prepared-bound, partition, NULL, cancellation, early Reset,
multi-chunk, SQL regression, and benchmark coverage. The first-batch
benchmark for the issue shape improves from about 3.0 s to about 1.25 ms
locally.

Tests:
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/aggexec
./pkg/sql/colexec/window -count=1
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/window
-run '^$' -bench '^BenchmarkWindowFirstBatch$' -benchtime=5x -count=1

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#23107

## What this PR does / why we need it:

Recognizes ROWS frames ending at CURRENT ROW whose PRECEDING bound
covers the runtime partition and evaluates SUM/AVG with one
source-preserving running aggregate state. This avoids replaying every
prefix for every output row while retaining state across bounded output
chunks and resetting it at partition boundaries.

Aggregate executors must explicitly opt into the source-preserving Merge
contract; aggregates whose Merge may consume the source retain the
existing evaluator.

Adds prepared-bound, partition, NULL, cancellation, early Reset,
multi-chunk, SQL regression, and benchmark coverage. The first-batch
benchmark for the issue shape improves from about 3.0 s to about 1.25 ms
locally.

Tests:
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/aggexec
./pkg/sql/colexec/window -count=1
- .agents/skills/mo-dev/scripts/mo-cgo-test ./pkg/sql/colexec/window
-run '^$' -bench '^BenchmarkWindowFirstBatch$' -benchtime=5x -count=1

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants