-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Push the limits past window functions #17347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
datafusion/physical-optimizer/src/limit_pushdown_past_window.rs
Outdated
Show resolved
Hide resolved
datafusion/physical-optimizer/src/limit_pushdown_past_window.rs
Outdated
Show resolved
Hide resolved
7ccfcdb
to
3906548
Compare
3906548
to
307e0a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @avantgardnerio for this PR
if let Some(window) = node.as_any().downcast_ref::<BoundedWindowAggExec>() { | ||
for expr in window.window_expr().iter() { | ||
let frame = expr.get_window_frame(); | ||
if frame.units != WindowFrameUnits::Rows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, we update latest_max
only for WindowFrameUnits::Rows
cases. If I am not mistaken, it is also valid to update latest_max
for WindowFrameUnits::Range
and WindowFrameUnits::Groups
as longs as end_bound
is WindowFrameBound::Preceding(_)
. I think, we can extend checks to include this use case also.
This should change the plan for following kind of queries
SELECT
c9,
SUM(c9) OVER(ORDER BY c9 ASC RANGE BETWEEN 5 PRECEDING AND 1 PRECEDING) as sum1
FROM aggregate_test_100
LIMIT 5
However, we can do this change in subsequent PRs. I think in current form, this PR is correct and we can merge as is. Thanks @avantgardnerio for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I will file a subsequent PR 😄
Which issue does this PR close?
Rationale for this change
We would like plans with window functions to go faster.
What changes are included in this PR?
A proof-of-concept level optimizer rule push limits past some window functions.
Are these changes tested?
So far only by the existing sqllogictest suite.
Are there any user-facing changes?
Queries with window functions may go faster, particularly if the
TableProvider
supports TopK pushdown.