Skip to content

feat(calcite): push whole-table SUM down to zone-map stats#184

Merged
dfa1 merged 2 commits into
mainfrom
feat/calcite-where-pushdown
Jun 27, 2026
Merged

feat(calcite): push whole-table SUM down to zone-map stats#184
dfa1 merged 2 commits into
mainfrom
feat/calcite-where-pushdown

Conversation

@dfa1

@dfa1 dfa1 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What

Wires SUM into VortexAggregatePushDownRule. A whole-table SELECT SUM(col) now rewrites to a single-row Values folded from the per-zone SUM rows — no data segment decoded — joining the existing MIN/MAX/COUNT push-down (ADR 0013 §6, ADR 0018 Phase 2).

The fold goes through the new VortexTable.zoneSum(column), which delegates to reader.compute.ZoneReducer.sum (extracted in #183). Until now that fold was reachable only through the test-only VortexAggregates helper; this makes the planner a real consumer of ZoneReducer — the seam justification from #183.

Behaviour

  • SUM(col) over the whole table → metadata-only Values, exact Long for integer columns, Double for floats.
  • Abandons to the normal scan (correct, just not pushed) when:
    • a zone carries no usable sum — no zone map, or an overflowed zone (Math.addExact dropped it);
    • the SUM argument is a computed expression, not a bare column ref;
    • a WHERE filters the aggregate — whole-zone stats can't answer a filtered aggregate. That is the residual tier, deliberately not built here (next increment: ZoneReducer predicate support + boundary-zone streaming).

Scope

ADR 0013 stays Proposed. AVG pushes down only when Calcite's AggregateReduceFunctionsRule has already decomposed it to SUM/COUNT; an intact AVG is left for the scan.

Tests

  • AggregatePushDownTest.sumRewritesToValuesFromZoneStatsSUM(volume) (I64 → exact Long) and SUM(low) (F64 → Double) rewrite to Values; values equal the ZoneReducer fold.
  • AggregateRuleBranchTestsum_withZoneStat_rewritesToValues (replaces the now-stale sum_hasNoZoneStat_abandonsRewrite, whose premise predated the per-zone SUM writer) + new sumOverComputedExpression_abandonsRewrite branch.
  • Existing filteredAggregateIsNotAnsweredFromWholeTableStats still green — SUM+WHERE correctly bails.

🤖 Generated with Claude Code

dfa1 and others added 2 commits June 27, 2026 17:28
Wire SUM into VortexAggregatePushDownRule. A whole-table `SUM(col)` now
rewrites to a single-row Values folded from the per-zone SUM rows via the
new VortexTable.zoneSum (delegating to reader.compute.ZoneReducer) — no
data segment decoded — joining the existing MIN/MAX/COUNT push-down.

The rule abandons to the normal scan when a zone carries no usable sum
(no zone map, or an overflowed zone) or when a WHERE filters the
aggregate (whole-zone stats can't answer a filtered aggregate — that is
the residual tier, still to come).

Until now the zone SUM fold was reachable only through the test-only
VortexAggregates helper; this makes the planner a real consumer of
ZoneReducer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit 092c772 into main Jun 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant