Skip to main content

Module aggregate

Module aggregate 

Source
Expand description

Aggregate executor.

Handles SELECT … <aggs> … [GROUP BY …] queries. The planning strategy is straightforward:

  1. Walk the SELECT (and ORDER BY) expressions to find every aggregate function call. Dedupe by AST equality and assign each __agg_<i>.
  2. Same for every GROUP BY expression: assign __grp_<j>.
  3. Stream the WHERE-filtered rows, group by the tuple of GROUP BY values, and update per-group aggregate state.
  4. Materialise a synthetic per-group row containing [__grp_0..__grp_K, __agg_0..__agg_N] and rewrite the user’s SELECT / ORDER BY expressions to reference those synthetic columns instead of the originals.
  5. Evaluate the rewritten expressions against the synthetic schema and emit results.

v1.8 implements count(*), count(expr), sum, min, max, avg. NULL semantics follow PG: aggregates skip NULL inputs (except count(*), which counts rows). sum(int) widens to BigInt; avg(int|bigint) returns Float.

Structs§

AggResult
Output of running the aggregate path. Schema describes one row per group; rows are not yet ORDER BY-sorted (caller does it).

Functions§

contains_aggregate
is_aggregate_name
run
Execute aggregate logic against an already-WHERE-filtered iterator of rows. table_alias is the alias accepted by column resolution.
uses_aggregate
True if this statement should go through the aggregate path.