[fix](aggregate) Restrict sum literal reassociation to integers - #67801
Merged
Merged
Conversation
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 10, 2026 10:16
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
TPC-H: Total hot run time: 16783 ms |
Contributor
TPC-DS: Total hot run time: 81273 ms |
Contributor
ClickBench: Total hot run time: 14.63 s |
starocean999
approved these changes
Sep 12, 2026
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.
Problem
When a query contains multiple aggregates such as SUM(x + 1.0) and SUM(x + 2.0), the optimizer reassociates them into SUM(x) plus COUNT(x) times each literal. For floating-point inputs this changes IEEE-754 rounding from per-row addition to post-aggregation addition and can return a different result.
Root cause
SumLiteralRewrite accepted both integer and floating-point literals, but did not require the analyzed input expression and arithmetic result to be integer types. The transformation is not semantics-preserving for floating-point arithmetic.
Reproduction
With DOUBLE values 1e16 and -1e16, the two original aggregates produce 0 and 4. Before this change, the rewritten plan produced 2 and 4 and exposed COUNT in the aggregate plan.
Fix
Restrict the reassociation to expressions whose analyzed child, non-literal operand, and literal operand are all integer-like. Floating-point and decimal expressions remain unchanged. Existing widening integer-cast handling is preserved. Integer overflow behavior is intentionally unchanged.
Tests