[fix](aggregate) Keep cast aggregates out of storage pushdown - #67737
Open
morrySnow wants to merge 1 commit into
Open
[fix](aggregate) Keep cast aggregates out of storage pushdown#67737morrySnow wants to merge 1 commit into
morrySnow wants to merge 1 commit into
Conversation
Storage-layer aggregation reads source column values, so pushing COUNT, MIN, or MAX through CAST/TRY_CAST can change nullability or extrema and return incorrect results. Restrict storage aggregation arguments to raw slots and keep explicit casts in row evaluation. Add direct and projected cast coverage. Issue Number: None
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 9, 2026 10:39
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 |
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
Storage-layer aggregation could be selected for
COUNT,MIN, andMAXwhose argument was a numeric
CASTorTRY_CAST. The storage scan aggregatesthe source column directly and cannot preserve the cast's value and null
semantics, so the optimization can change query results.
For example, with a non-null
DOUBLEcolumn containing42,2147483647,2147483648,-2147483649, and1e20, and with strict casts disabled:Only two casts are non-null, so both counts must be
2. Before this change,the scan used
pushAggOp=COUNTand returned5. A similar narrowing cast fromBIGINTvalues-200, 0, 200toTINYINTmade cast-basedMIN/MAXusepushAggOp=MINMAXand returnNULLinstead of0.Root cause
The eligibility check treated a numeric cast of a slot as equivalent to the
slot itself. However, the storage aggregation descriptor carries the source
slot and operation, not an expression evaluator for the cast. Numeric casts
are not necessarily lossless: they can introduce nulls on overflow and can
change values relevant to extrema.
Fix
Restrict storage-layer aggregation arguments to raw slot references. Keep any
explicit
CASTorTRY_CASTin the regular row-evaluation and aggregationpath, including casts exposed through a project alias. This conservative rule
preserves correctness for all scan types and all supported aggregate
operations while retaining pushdown for unmodified columns.
Tests
COUNT,MIN, andMAXarguments usingCAST/TRY_CAST, plus a projected cast alias.PhysicalStorageLayerAggregateTest: 8 tests passed, 0 failed.2, allfour cast-based extrema return
0, and the scan plans showpushAggOp=NONE.Issue Number: None