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
Commit 7e102d7
Browse filesBrowse the repository at this point in the historyBrowse files
fix: Avoid pushing down sort under limits (#25408)
## Which issue does this PR close?
- Closes#25378.
## Rationale for this change
Currently, `ORDER BY` on top of `LIMIT/OFFSET` subquery is currently
planned as a TopK sort below the limit operator, which has to consume
the whole input.
## What changes are included in this PR?
Keep a sort above `GlobalLimitExec/LocalLimitExec`, unless the limit is
directly above a SortExec whose ordering the pushed sort refines. Also
stop pushing a sort through fetch-carrying operators that have no output
ordering.
## What is the testing strategy for this PR?
Additional SLT tests in `limit.slt` and unit tests checking various plan
shapes and inputs.
## Are there any user-facing changes?
Plans for `ORDER BY` over a `LIMIT` / `OFFSET` subquery change: the sort
stays
above the limit, so the input can stop early and the limit keeps the
first rows
it sees rather than the smallest ones. No API changes.
---------
Signed-off-by: Adam Gutglick <[email protected]>
EXPLAIN SELECT row_number() OVER (ORDER BY id) AS rn, id
497
+
FROM (SELECT id FROM window_over_limit WHERE kind = 'a' LIMIT 5 OFFSET 5);
498
+
----
499
+
logical_plan
500
+
01)Projection: row_number() ORDER BY [window_over_limit.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW AS rn, window_over_limit.id
501
+
02)--WindowAggr: windowExpr=[[row_number() ORDER BY [window_over_limit.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]
01)ProjectionExec: expr=[row_number() ORDER BY [window_over_limit.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@1 as rn, id@0 as id]
508
+
02)--BoundedWindowAggExec: wdw=[row_number() ORDER BY [window_over_limit.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "row_number() ORDER BY [window_over_limit.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": UInt64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]
0 commit comments