feat(calcite): push whole-table SUM down to zone-map stats#184
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Wires
SUMintoVortexAggregatePushDownRule. A whole-tableSELECT SUM(col)now rewrites to a single-rowValuesfolded from the per-zoneSUMrows — no data segment decoded — joining the existingMIN/MAX/COUNTpush-down (ADR 0013 §6, ADR 0018 Phase 2).The fold goes through the new
VortexTable.zoneSum(column), which delegates toreader.compute.ZoneReducer.sum(extracted in #183). Until now that fold was reachable only through the test-onlyVortexAggregateshelper; this makes the planner a real consumer ofZoneReducer— the seam justification from #183.Behaviour
SUM(col)over the whole table → metadata-onlyValues, exactLongfor integer columns,Doublefor floats.Math.addExactdropped it);SUMargument is a computed expression, not a bare column ref;WHEREfilters the aggregate — whole-zone stats can't answer a filtered aggregate. That is the residual tier, deliberately not built here (next increment:ZoneReducerpredicate support + boundary-zone streaming).Scope
ADR 0013 stays Proposed.
AVGpushes down only when Calcite'sAggregateReduceFunctionsRulehas already decomposed it toSUM/COUNT; an intactAVGis left for the scan.Tests
AggregatePushDownTest.sumRewritesToValuesFromZoneStats—SUM(volume)(I64 → exactLong) andSUM(low)(F64 →Double) rewrite toValues; values equal theZoneReducerfold.AggregateRuleBranchTest—sum_withZoneStat_rewritesToValues(replaces the now-stalesum_hasNoZoneStat_abandonsRewrite, whose premise predated the per-zone SUM writer) + newsumOverComputedExpression_abandonsRewritebranch.filteredAggregateIsNotAnsweredFromWholeTableStatsstill green —SUM+WHEREcorrectly bails.🤖 Generated with Claude Code