You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simplify WindowTopN by moving it before EnforceSorting #21594
The WindowTopN physical optimizer rule currently runs afterEnforceSorting, 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 beforeEnforceSorting. 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>
Activity
SubhamSinghal commentedon Apr 13, 2026
take
saadtajwar commentedon Aug 3, 2026
Hey folks - was wondering if this is still open/if @SubhamSinghal you're working on this currently? Happy to help out if needed! Thanks!
SubhamSinghal commentedon Aug 4, 2026
Feel free to take it.
saadtajwar commentedon Aug 4, 2026
Sweet, thanks! Will dive into this over the next couple of days!
saadtajwar commentedon Aug 4, 2026
take
saadtajwar commentedon Aug 8, 2026
#24191 PR ready for review! Thanks!
refactor: moving WindowTopN before EnsureRequirements (apache#24191)
refactor: moving WindowTopN before EnsureRequirements (apache#24191)