Repository navigation
perf(calcite): total decimal SUM/AVG exactly as unscaled longs in the scan - #563
Merged
Merged
Conversation
… scan Zone statistics carry no decimal sum, so every SUM or AVG of a decimal column was left to Calcite, which adds a BigDecimal per row. DecimalArray.getUnscaledLong reads a value's unscaled long without a BigDecimal (the direct-buffer, byte-parts and constant arrays read it straight from their storage). Every value of a decimal with precision 18 or less fits a long, so: - VortexTable.decimalFold totals a whole-table or filtered decimal SUM with Math.addExact, and also backs COUNT/MIN/MAX of a decimal column when the zone fold declines; - the grouped kernel gains a decimal lane, so GROUP BY ... SUM(decimal) folds in the scan too. A precision past 18 or a sum past a long declines to Calcite. DECIMAL literals are now exact (they went through a double), and the rule handles $SUM0, which Calcite reduces AVG to, so AVG pushes down too. Raincloud, best of 3, ms: store_sales sum(ss_net_paid), sum(ss_net_profit) 143 -> 25 customer group by c_mktsegment, sum(c_acctbal) 65 -> 15 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WtuVGQ5h5Lk6Zn4JnkxF1K
dfa1
force-pushed
the
feat/decimal-sum
branch
from
October 18, 2026 11:18
41d2ab0 to
95d21be
Compare
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.
Stacked on #562 (rebased onto main once it merges).
Zone statistics carry no decimal sum, so every decimal
SUM/AVGwas left to Calcite (aBigDecimalper row).DecimalArray.getUnscaledLong(i)reads the unscaled value without aBigDecimal; precision ≤ 18 always fits a long.VortexTable.decimalFoldtotals a whole-table or filtered decimalSUMwithMath.addExact(and backsCOUNT/MIN/MAXof a decimal column when the zone fold declines); the grouped kernel gains a decimal lane.DECIMALliterals are now exact (they went through a double), and$SUM0(Calcite's reduction ofAVG) is handled.sum(ss_net_paid), sum(ss_net_profit)group by c_mktsegment, sum(c_acctbal)Tests
getUnscaledLongat every width (and past a long), byte-parts; grouped decimal lane (exact at scale, overflow and precision > 18 decline).DecimalSumTest: whole-table, filtered (SUM/AVG/COUNT) and grouped against scanning oracles.DECIMAL(10, 2).🤖 Generated with Claude Code
https://claude.ai/code/session_01WtuVGQ5h5Lk6Zn4JnkxF1K