xiangfu0 opened a new pull request, #16399:
URL: https://github.com/apache/pinot/pull/16399

   ## Overview
   This PR implements a query optimization feature that speeds up queries like 
`SELECT sum(met + 2)` by rewriting them to the mathematically equivalent but 
more efficient `SELECT sum(met) + 2 * count(1)` using the distributive property 
of addition.
   
   ## Features
   - ✅ Optimizes `sum(column + constant)` → `sum(column) + constant * count(1)`
   - ✅ Optimizes `sum(constant + column)` → `sum(column) + constant * count(1)` 
 
   - ✅ Optimizes `sum(column - constant)` → `sum(column) - constant * count(1)`
   - ✅ Optimizes `sum(constant - column)` → `constant * count(1) - sum(column)`
   - ✅ Handles nested expressions with multiple constants
   - ✅ Preserves query semantics while improving performance
   
   ## Performance Impact
   This optimization can significantly speed up aggregation queries by:
   - Reducing computational complexity during segment processing
   - Leveraging efficient count operations
   - Maintaining mathematical correctness
   
   ## Example
   **Before:** `SELECT sum(revenue + 100) FROM sales`
   **After:** `SELECT sum(revenue) + 100 * count(1) FROM sales`
   
   ## Testing
   - ✅ Comprehensive unit tests covering all optimization patterns
   - ✅ Edge case handling (nested expressions, multiple constants)
   - ✅ Validation that non-optimizable queries remain unchanged
   
   ## Files Modified
   - `AggregationOptimizer.java` - New optimizer implementation
   - `AggregationOptimizerTest.java` - Comprehensive test suite  
   - `QueryRewriterFactory.java` - Integration into query rewriting pipeline


-- 
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