Is your feature request related to a problem or challenge?
Discussion thread
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
Is your feature request related to a problem or challenge?
Discussion thread
The
WindowTopNphysical optimizer rule currently runs afterEnforceSorting, which means it must pattern-match throughSortExecnodes thatEnforceSortinginserts:Describe the solution you'd like
Move
WindowTopNto run beforeEnforceSorting. BeforeEnforceSortingruns, the plan is simpler —BoundedWindowAggExecdeclares its required ordering/distribution but noSortExecexists yet:Describe alternatives you've considered
No response
Additional context
No response