Describe the bug
Partial aggregation with PartiallySorted ordering panics when memory pressure triggers the EmitEarly OOM path:
assertion failed: *current_sort >= n
at aggregates/order/partial.rs:174
#19287 changed Partial aggregation to always use OutOfMemoryMode::EmitEarly:
(AggregateMode::Partial, _) => OutOfMemoryMode::EmitEarly,
The EmitEarly handler calls emit(EmitTo::First(n)) with n based on batch size, ignoring the sort boundary tracked by GroupOrderingPartial. Previously, emit_early_if_necessary() had a guard:
&& matches!(self.group_ordering, GroupOrdering::None)
This guard was lost in the refactor.
Trigger conditions
Partial aggregate with PartiallySorted ordering (e.g. GROUP BY a, b where input is sorted on a)
- Memory pressure triggers
EmitEarly before a sort key boundary is reached
- Many groups accumulate with the same sort key value (so
current_sort stays at 0 while n grows)
To Reproduce
A unit test is included in the linked PR #20446
Expected behavior
OOM, but not a assertion panic
Additional context
No response