yashrb24 opened a new issue, #27085:
URL: https://github.com/apache/datafusion/issues/27085

   ### Is your feature request related to a problem or challenge?
   
   Queries with many filtered aggregates can repeat work. For example:
   ```sql
   SELECT
     SUM(sales) FILTER (WHERE region = 'West'),
     COUNT(*)   FILTER (WHERE region = 'West'),
     AVG(cost)  FILTER (WHERE region = 'East'),
     COUNT(*)   FILTER (WHERE region = 'East')
   FROM orders;
   ```
   
   * Today, each aggregate processes its filter and prepares its own matching 
rows.
      - For the eg here, that means the two `West` aggregates can repeat the 
same selection work.
   * The query also processes the `West` and `East` filters separately
      - a row can match at most one of them at a time anyway
   
   ### Describe the solution you'd like
   
   So there are two opportunities here
   
   1. Select matching rows once and reuse them across aggregates using that 
filter
   2. Route rows for mutually exclusive filters
      - This will need some heuristics on when it's worth the extra effort of 
routing
      - Also a physical optimizer rule would be needed in cases the filter has 
been projected as a boolean column
   
   I want to take this up as two separate PRs
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   This pattern occurs in regular aggregate queries. Original inspriation is 
PIVOT-style queries which are often expressed as filtered aggregates on 
multiple entries. Though first-class support for 
[PIVOT](https://github.com/apache/datafusion/issues/12907) is still open. 
   
   ### Willingness to contribute
   
   I plan to contribute to this feature independently


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