AggregateExec: incremental memory release before streaming merge #19751
+91
−47
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.
Which issue does this PR close?
Related to #19679
Related to #19695
Rationale for this change
It was observed that downstream operators (such as
SortExec) can receive extremely largeRecordBatchoutputs fromAggregateExec, violating the implicitbatch_sizeconvention used throughout the physical plan.An initial hypothesis was that normalizing batch sizes at the
AggregateExec->SortExecboundary would be sufficient.However, while implementing and testing this, it became clear that:
GroupedHashAggregateStreamallocates group keys and accumulator state before memory reservation checks are enforcedbatch_size, internal state can exceed memory limitsThis indicates that the issue is not a simple emission bug, but a design boundary between:
batch_sizeas an output convention vs. a hard invariantThis PR aims to:
What changes are included in this PR?
Importantly, this PR does not claim to fully enforce
batch_sizeat all stages, nor does it prevent all oversized intermediate states. Instead, it reduces memory pressure and clarifies current limitations.Are these changes tested?
Yes, but edge cases revealed design limitations rather than simple bugs
The PR is submitted primarily for review and discussion rather than as a final fix.
Are there any user-facing changes?
No.