suxiaogang223 commented on issue #8374:
URL: 
https://github.com/apache/arrow-datafusion/issues/8374#issuecomment-1833893917

   I tried to explain the sql:
   ```sql
   explain SELECT u.* FROM users u JOIN employees e ON u."column1" = 
e."column1" ORDER BY u."column1", e."column2";
   ```
   
   On branch-33,the result is:
   ```text
   
+---------------+--------------------------------------------------------------------------------------+
   | plan_type     | plan                                                       
                          |
   
+---------------+--------------------------------------------------------------------------------------+
   | logical_plan  | Projection: u.column1, u.column2                           
                          |
   |               |   Sort: u.column1 ASC NULLS LAST, e.column2 ASC NULLS LAST 
                          |
   |               |     Projection: u.column1, u.column2, e.column2            
                          |
   |               |       Inner Join: u.column1 = e.column1                    
                          |
   |               |         SubqueryAlias: u                                   
                          |
   |               |           TableScan: users projection=[column1, column2]   
                          |
   |               |         SubqueryAlias: e                                   
                          |
   |               |           TableScan: employees projection=[column1, 
column2]                         |
   | physical_plan | SortPreservingMergeExec: [column1@0 ASC NULLS 
LAST,column2@1 ASC NULLS LAST]         |
   |               |   SortExec: expr=[column1@0 ASC NULLS LAST,column2@1 ASC 
NULLS LAST]                 |
   |               |     ProjectionExec: expr=[column1@0 as column1, column2@1 
as column2]                |
   |               |       CoalesceBatchesExec: target_batch_size=8192          
                          |
   |               |         HashJoinExec: mode=Partitioned, join_type=Inner, 
on=[(column1@0, column1@0)] |
   |               |           CoalesceBatchesExec: target_batch_size=8192      
                          |
   |               |             RepartitionExec: 
partitioning=Hash([column1@0], 8), input_partitions=1   |
   |               |               MemoryExec: partitions=1, 
partition_sizes=[1]                          |
   |               |           CoalesceBatchesExec: target_batch_size=8192      
                          |
   |               |             RepartitionExec: 
partitioning=Hash([column1@0], 8), input_partitions=1   |
   |               |               MemoryExec: partitions=1, 
partition_sizes=[1]                          |
   |               |                                                            
                          |
   
+---------------+--------------------------------------------------------------------------------------+
   2 rows in set. Query took 0.022 seconds.
   ```
   
   On branch-31, the result is:
   ```text
   
+---------------+-----------------------------------------------------------------------------------------------+
   | plan_type     | plan                                                       
                                   |
   
+---------------+-----------------------------------------------------------------------------------------------+
   | logical_plan  | Projection: u.column1, u.column2                           
                                   |
   |               |   Sort: u.column1 ASC NULLS LAST, e.column2 ASC NULLS LAST 
                                   |
   |               |     Projection: u.column1, u.column2, e.column2            
                                   |
   |               |       Inner Join: u.column1 = e.column1                    
                                   |
   |               |         SubqueryAlias: u                                   
                                   |
   |               |           TableScan: users projection=[column1, column2]   
                                   |
   |               |         SubqueryAlias: e                                   
                                   |
   |               |           TableScan: employees projection=[column1, 
column2]                                  |
   | physical_plan | ProjectionExec: expr=[column1@0 as column1, column2@1 as 
column2]                             |
   |               |   SortPreservingMergeExec: [column1@0 ASC NULLS 
LAST,column2@2 ASC NULLS LAST]                |
   |               |     SortExec: expr=[column1@0 ASC NULLS LAST,column2@2 ASC 
NULLS LAST]                        |
   |               |       ProjectionExec: expr=[column1@0 as column1, 
column2@1 as column2, column2@3 as column2] |
   |               |         CoalesceBatchesExec: target_batch_size=8192        
                                   |
   |               |           HashJoinExec: mode=Partitioned, join_type=Inner, 
on=[(column1@0, column1@0)]        |
   |               |             CoalesceBatchesExec: target_batch_size=8192    
                                   |
   |               |               RepartitionExec: 
partitioning=Hash([column1@0], 8), input_partitions=8          |
   |               |                 RepartitionExec: 
partitioning=RoundRobinBatch(8), input_partitions=1          |
   |               |                   MemoryExec: partitions=1, 
partition_sizes=[1]                               |
   |               |             CoalesceBatchesExec: target_batch_size=8192    
                                   |
   |               |               RepartitionExec: 
partitioning=Hash([column1@0], 8), input_partitions=8          |
   |               |                 RepartitionExec: 
partitioning=RoundRobinBatch(8), input_partitions=1          |
   |               |                   MemoryExec: partitions=1, 
partition_sizes=[1]                               |
   |               |                                                            
                                   |
   
+---------------+-----------------------------------------------------------------------------------------------+
   2 rows in set. Query took 0.019 seconds.
   ```
   The difference is ProjectionExec, on branch-33, the project wrongly excluded 
the e.column2, so the SortExec can't sort by e.column2.


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