Skip to content

feat: native GroupsAccumulator for unordered first_value - #91

Merged
rkrishn7 merged 2 commits into
branch-55from
unordered-first-value-groups-accumulator
Nov 9, 2026
Merged

rkrishn7 merged 2 commits into
branch-55from
unordered-first-value-groups-accumulator

Conversation

@rkrishn7

@rkrishn7 rkrishn7 commented Nov 6, 2026

Copy link
Copy Markdown

See apache#27150 for details.

Also implements evaluate_preserving/state_preserving, which upstream's first_value doesn't support yet.

first_value only had a GroupsAccumulator when it had an ORDER BY. Without
one, grouped aggregation fell back to GroupsAccumulatorAdapter, which keeps
a boxed TrivialFirstValueAccumulator per group. DISTINCT ON without ORDER BY
plans as one unordered first_value per selected column, so queries with
many distinct keys paid that per-group cost in both time and memory.

Add UnorderedFirstValueGroupsAccumulator. It stores values in the existing
ValueState implementations plus one is_set bit per group. A group takes the
first row that passes the FILTER clause (and, with IGNORE NULLS, is not
null) and is never written again, which is the same row
TrivialFirstValueAccumulator keeps. The state layout stays
[first_value, is_set], so partial and final aggregation are unchanged.

Also implements evaluate_preserving and state_preserving.

LAST_VALUE and ordered FIRST_VALUE are unchanged.
@rkrishn7
rkrishn7 merged commit 6621548 into branch-55 Nov 9, 2026
64 of 66 checks passed
@rkrishn7
rkrishn7 deleted the unordered-first-value-groups-accumulator branch November 9, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant