morrySnow opened a new pull request, #67884:
URL: https://github.com/apache/doris/pull/67884

   ## Problem
   
   Aggregate group-key simplification could replace several expressions derived 
from one input column with the input column itself. Derived expressions can map 
distinct input values to the same output, so the replacement can split one SQL 
group into multiple groups and return incorrect aggregate results.
   
   ## Root cause
   
   The rule treated arithmetic with constants and selected cast chains as 
injective based on the shape of their inputs. That reasoning did not prove that 
the complete, typed expression preserves distinctness after overflow, rounding, 
truncation, or other result-type semantics.
   
   ## Reproduction
   
   Insert integer values `1` and `2`, then group by both `x / 1000000.0` and `x 
/ 2000000.0`. Both decimal expressions evaluate to the same tuple for the two 
rows, so the expected result is one group with count `2`. The old rewrite 
grouped by `x` instead and returned two groups with count `1`.
   
   ## Fix
   
   - Restrict group keys eligible for this simplification to bare slots.
   - Collapse the grouping list only when every entry is the same slot.
   - Keep arithmetic expressions and casts unchanged unless a future 
implementation can prove injectivity for the complete typed expression.
   - Add focused coverage for arithmetic, decimal, cast, and other 
derived-expression boundaries.
   
   ## Tests
   
   - `./run-fe-ut.sh --run 
org.apache.doris.nereids.rules.rewrite.SimplifyAggGroupByTest` (10 tests passed)
   - `DISABLE_BUILD_UI=ON ./build.sh --fe`
   - `./run-regression-test.sh --run -s simplify_agg_group_by` against a local 
FE/BE sandbox (1 suite passed)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to