Skip to main content

execute_group_by

Function execute_group_by 

Source
pub fn execute_group_by(
    bindings: Vec<Binding>,
    group_vars: &[Var],
    aggregations: &[AggregationDef],
) -> Vec<Binding>
Expand description

1-pass streaming GROUP BY.

Previous implementation accumulated ALL input bindings per group (HashMap<String, Vec<Binding>>), then ran aggregations in a second pass. Memory cost: O(input_rows) in the groups map.

This version keeps only the incremental aggregation state per group — one Box<dyn Aggregator> per AggregationDef. Memory cost drops to O(distinct_groups × agg_defs), which is dramatically lower for high-cardinality inputs with few distinct groups.