Expand description
Aggregate executor.
Handles SELECT … <aggs> … [GROUP BY …] queries. The planning strategy
is straightforward:
- Walk the SELECT (and ORDER BY) expressions to find every aggregate
function call. Dedupe by AST equality and assign each
__agg_<i>. - Same for every
GROUP BYexpression: assign__grp_<j>. - Stream the WHERE-filtered rows, group by the tuple of GROUP BY values, and update per-group aggregate state.
- 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. - 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).
Statics§
- AGGREGATE_
ARRAY_ AGG_ ORDER_ BY_ FIRE - AGG_
PER_ ROW_ COMPILED_ HIT - AGG_
PER_ ROW_ COMPILED_ MISS - AGG_
PER_ ROW_ COUNT_ STAR_ SENTINEL - AGG_
PER_ ROW_ EVAL_ FALLBACK - AGG_
PER_ ROW_ FAST_ POS - v7.37.9 Phase 1A-ext — per-row spec dispatch branches in
accumulate_groups’s hot loop. Verifies the Phase 1A decomposition agent’s S06 assumption (“14 specs × eval_expr per row”). Sum should equaln_specs × n_input_rows. Branch distribution tells which attack target ROI is highest: FAST_POS many = baseline OK; COMPILED_MISS many = Step-VM is hot path; EVAL_FALLBACK > 0 = uncompilable specs walking the eval_expr tree per row × Cow row materialise. - DISTA_
LITERAL_ ARG2_ CACHE_ FIRE - v7.37.9 Phase 0 diagnostic counters — see
.claude/notes/v7.37.9-class-a-c-cascade-closure-plan.md. These are read-only telemetry, do not gate any code path. Used byxtests/dogfood_replay/src/bin/counter_dump.rsto verify whether the DISTA A-3 + array_agg-ordered fast paths actually fire on the mailrs Class A SQL shape.
Functions§
- contains_
aggregate - is_
aggregate_ name - is_
hypothetical_ set_ name - v7.32 (round-29) — hypothetical-set aggregates:
rank(args) WITHIN GROUP (ORDER BY …)and friends compute the rank the hypothetical row would have. Like ordered-set, the value stream comes from the sort spec and the in-parens args are direct (the hypothetical row). - is_
ordered_ set_ name - v7.32 (round-29) — ordered-set aggregates: the value to aggregate
comes from the
WITHIN GROUP (ORDER BY …)sort spec, and any in-parens arguments are direct arguments (the percentile fraction).mode()takes no direct argument. - is_
within_ group_ name - v7.32 (round-29) — every aggregate that takes its value stream from
a
WITHIN GROUP (ORDER BY …)clause (ordered-set + hypothetical-set). - uses_
aggregate - True if this statement should go through the aggregate path.
Type Aliases§
- Correlated
Eval - Execute aggregate logic against an already-WHERE-filtered iterator of
rows.
table_aliasis the alias accepted by column resolution. v7.25.2 (round-19 A) — caller-injected evaluator for synth-row expressions that still carry subquery nodes after the rewrite (correlated subqueries in the select list / HAVING / aggregate ORDER BY of a GROUP BY query). The engine passes its correlated-aware evaluator; pure-library callers pass None and surviving subqueries keep erroring loudly.