You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a GroupsAccumulator for array_agg with ORDER BY #26409
Is your feature request related to a problem or challenge?
array_agg(x ORDER BY y) has no GroupsAccumulator: groups_accumulator_supported requires order_bys to be empty, so every grouped ordered ARRAY_AGG goes through GroupsAccumulatorAdapter, with one OrderSensitiveArrayAggAccumulator per group. High-cardinality GROUP BY queries then pay the adapter's per-group allocation, per-group dispatch and ScalarValue output costs.
#26357 adds a native groups accumulator for array_agg(DISTINCT x), including ORDER BY x. The general ORDER BY y case is still on the adapter path.
Describe the solution you'd like
A native groups accumulator for ordered ARRAY_AGG, along the lines of #26357 and the ordered first_value/last_value groups accumulators:
Store values and ordering keys in shared buffers for all groups, plus a (group_index, row_index) entry per value, instead of one accumulator per group.
In evaluate, counting-sort the entries by group, then sort each group's slice by its ordering key.
When is_input_pre_ordered is set (the input already satisfies the ordering), skip the per-group sort for raw input. States merged from several partitions still need sorting.
Describe alternatives you've considered
Keep the adapter. #25199 reduced the per-group memory of OrderSensitiveArrayAggAccumulator, but the per-group accumulator and dispatch remain.
Additional context
Follow-up to #26347 / #26357. I'd like to work on this.
Activity