fix(exec): batch full-frame aggregate window input#643
Open
zhli1142015 wants to merge 1 commit into
Open
Conversation
### What problem does this PR solve?
Non-spillable aggregate window functions can still evaluate full-partition frames where every output row has the same frame, such as `ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING`. For aggregate functions outside the spillable-window whitelist, the regular AggregateWindow path used to load the whole partition into argument vectors at once before computing the aggregate.
That creates avoidable memory spikes for large partitions. It also leaves the non-spillable path without regression coverage, because common aggregate functions such as `sum`, `count`, `min`, `max`, and `avg` can use the spillable window build instead.
Issue Number: N/A
### Type of Change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Performance improvement (optimization)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Refactoring (no logic changes)
- [ ] Build/CI or Infrastructure changes
- [ ] Documentation only
### Description
Detect the non-streaming full-partition same-frame case in `AggregateWindowFunction` and handle it separately. The new path computes the aggregate once, loads partition input in chunks bounded by `max_output_batch_rows`, caches the computed result for the rest of the current partition, and copies the cached value to later output batches.
The optimization is intentionally gated to non-row-streaming partitions. Row-streaming partitions use cumulative frame coordinates that are not safe to re-read from row 0, so they continue to use the existing incremental path.
The tests cover both behavior and the intended path:
- `last(d)` over an unbounded full frame verifies correctness for a non-spillable aggregate window and asserts that the spillable window build is not used.
- A test-only aggregate records the largest `addSingleGroupRawInput` batch and verifies that full-frame aggregation is chunked by `max_output_batch_rows` instead of loading the whole partition at once.
### Performance Impact
- [ ] No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).
- [x] Positive Impact: I have run targeted validation.
<details>
<summary>Click to view validation results</summary>
```text
Regression evidence from SpillableWindowTest.nonSpillableSameFrameAggregationBatchesInput:
- Before the fix, the test-only aggregate observed a max addSingleGroupRawInput batch of 512 rows.
- After the fix, the max observed batch is 50 rows, matching max_output_batch_rows.
Unit tests:
- SpillableWindowTest.nonSpillableLastAggUnboundedFrame: passed
- SpillableWindowTest.nonSpillableSameFrameAggregationBatchesInput: passed
- WindowTest.* + SpillableWindowTest.* + RowStreamingWindowTest.* + SortAndWindowTest.* + SortWindowTest.*: 35 tests passed
```
</details>
- [ ] Negative Impact: Explained below (e.g., trade-off for correctness).
### Release Note
Release Note:
```text
Release Note:
- Reduced memory spikes for non-spillable full-frame aggregate window functions by batching input loading and reusing the computed frame result.
```
### Checklist (For Author)
- [x] I have added/updated unit tests (ctest).
- [x] I have verified the code with local build (Release/Debug).
- [x] I have run clang-format / linters.
- [ ] (Optional) I have run Sanitizers (ASAN/TSAN) locally for complex C++ changes.
- [ ] No need to test or manual test.
### Breaking Changes
- [x] No
- [ ] Yes (Description: ...)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6d7d1c3 to
ab156c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Non-spillable aggregate window functions can still evaluate full-partition frames where every output row has the same frame, such as
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. For aggregate functions outside the spillable-window whitelist, the regular AggregateWindow path used to load the whole partition into argument vectors at once before computing the aggregate.That creates avoidable memory spikes for large partitions. It also leaves the non-spillable path without regression coverage, because common aggregate functions such as
sum,count,min,max, andavgcan use the spillable window build instead.Issue Number: N/A
Type of Change
Description
Detect the non-streaming full-partition same-frame case in
AggregateWindowFunctionand handle it separately. The new path computes the aggregate once, loads partition input in chunks bounded bymax_output_batch_rows, caches the computed result for the rest of the current partition, and copies the cached value to later output batches.The optimization is intentionally gated to non-row-streaming partitions. Row-streaming partitions use cumulative frame coordinates that are not safe to re-read from row 0, so they continue to use the existing incremental path.
The tests cover both behavior and the intended path:
last(d)over an unbounded full frame verifies correctness for a non-spillable aggregate window and asserts that the spillable window build is not used.addSingleGroupRawInputbatch and verifies that full-frame aggregation is chunked bymax_output_batch_rowsinstead of loading the whole partition at once.Performance Impact
No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).
Positive Impact: I have run targeted validation.
Click to view validation results
Negative Impact: Explained below (e.g., trade-off for correctness).
Release Note
Release Note:
Checklist (For Author)
Breaking Changes