mingmwang commented on PR #5745:
URL: 
https://github.com/apache/arrow-datafusion/pull/5745#issuecomment-1486341433

   > @mingmwang You gave a great idea - it should be **a physical plan 
optimization!** 💡
   > 
   > The optimization should push down partial aggregate though union:
   > 
   > ```
   > ...
   > | logical_plan                                               | Aggregate: 
groupBy=[[]], aggr=[[COUNT(UInt8(1))]]                                          
                                                                              |
   > |                                                            |   Union     
                                                                                
                                                                             |
   > |                                                            |     
TableScan: my_table projection=[c1]                                             
                                                                                
     |
   > |                                                            |     
Projection: my_table2.c1 AS my_table.c1                                         
                                                                                
     |
   > |                                                            |       
TableScan: my_table2 projection=[c1]
   > ...
   > | physical_plan                                              | 
AggregateExec: mode=Final, gby=[], aggr=[COUNT(UInt8(1))]                       
                                                                                
         |
   > |                                                            |   
CoalescePartitionsExec                                                          
                                                                                
       |                                                                        
                                |
   > |                                                            |       
RepartitionExec: partitioning=RoundRobinBatch(10), input_partitions=2           
                                                                                
   |
   > |                                                            |         
UnionExec      
   > |                                                            |           
AggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))]                     
                                                                                
                                               |
   > |                                                            |             
CsvExec: files={1 group: 
[[/home/hello/repo/arrow-datafusion/datafusion/core/tests/data/aggregate_simple.csv]]},
 has_header=true, limit=None, projection=[c1]    |
   > |                                                            |           
AggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))]   
   > |                                                            |             
ProjectionExec: expr=[c1@0 as my_table.c1]                                      
                                                                               |
   > |                                                            |             
  CsvExec: files={1 group: 
[[/home/hello/repo/arrow-datafusion/datafusion/core/tests/data/aggregate_simple2.csv]]},
 has_header=true, limit=None, projection=[c1] |
   > |                                                            |             
                                                                                
                                                                             |
   > 
+------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   > ```
   > 
   > Optimization in the logical plan gave unnecessary doubled final-partial 
aggregate pair.
   > 
   > @mingmwang What do you think?
   
   I think even during the physical planning phase, push down the partial 
aggregate though repartition + union might not give performance benefit, 
because it might reduce the parallism of the partial aggregate.


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