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

   ### Is your feature request related to a problem or challenge?
   
   [Discussion thread]( 
https://github.com/apache/datafusion/pull/21479#discussion_r3068890632)
   
   The `WindowTopN` physical optimizer rule currently runs **after** 
`EnforceSorting`, which means it must pattern-match through `SortExec` nodes 
that `EnforceSorting` inserts:     
                                                                                
                                                                                
                       
     ```                                                                        
                                                                                
                       
     FilterExec(rn <= K)                                                        
                                                                                
                       
       [optional ProjectionExec]                                                
                                                                                
                       
         BoundedWindowAggExec(ROW_NUMBER PARTITION BY ... ORDER BY ...)
           SortExec(partition_keys, order_keys)   ← inserted by EnforceSorting
     ```
   
   
   ### Describe the solution you'd like
   
   Move `WindowTopN` to run **before** `EnforceSorting`. Before 
`EnforceSorting` runs, the plan is simpler — `BoundedWindowAggExec` declares 
its required ordering/distribution but no `SortExec` exists yet:
   
     ```
     FilterExec(rn <= K)
       [optional ProjectionExec]
         BoundedWindowAggExec(ROW_NUMBER PARTITION BY ... ORDER BY ...)
           <input without SortExec>
     ```
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


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