HaoYang670 commented on issue #4772:
URL: 
https://github.com/apache/arrow-datafusion/issues/4772#issuecomment-1404486620

   Hi @Jefffrey, actually I am not sure whether we should do this. It is just 
something appearing in my mind one day.
   
   (sorry it should be the `aggregation functions` but not `empty projection` 
in the title)
   
   For `union all`, we can push down the aggregation functions to the child 
plans. For example,
   for a query `select count(*) from (select * from t1 union select * from 
t2)`, we can optimize the logical plan to count each child plan and then sum 
them together.
   ```
   Projection: Sum(col1) as COUNT(UInt8(1))                                 
     Aggregate: groupBy=[[]], aggr=[[Sum(col1)]]           
       Union                   
         Projection: COUNT(UInt8(1)) as  col1                                
           Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]                    
                 
             TableScan: t projection=[a]        
         Projection: COUNT(UInt8(1)) as col1                                
           Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]                    
    
             TableScan: t projection=[a]
   ```
   
   And it is similar for min, max, avg ...


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

Reply via email to