-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support limit push down for offset_plan #2566
Conversation
|
||
self.limit(plan, query.limit) | ||
//make limit as offset's input will enable limit push down simply | ||
self.offset(plan, query.offset) |
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.
If there is an offset
in sql, we will put it as root node in plan tree. So it will easily push new_limit
to limit operator.
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.
Don't we need to apply the offset before the limit here?
It looks like we don't currently have a test with both a non-zero offset and a limit. Could you add one here so we can see what the plan looks like?
Per https://www.postgresql.org/docs/current/queries-limit.html If both OFFSET and LIMIT appear, then OFFSET rows are skipped before starting to count the LIMIT rows that are returned.
and I am not sure this change will ensure that
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.
form the explain from pg
postgres=# explain analyze select * from users limit 5 offset 7;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Limit (cost=0.17..0.29 rows=5 width=80) (actual time=0.117..0.226 rows=5 loops=1)
-> Seq Scan on users (cost=0.00..239.02 rows=10002 width=80) (actual time=0.013..0.082 rows=12 loops=1)
Planning Time: 0.060 ms
Execution Time: 0.350 ms
(4 rows)
I think in PG, the limit operator has a param with offset
, in DF we separate it. So we need apply offset after limit a+b
add test #2566 (comment)
Co-authored-by: Andy Grove <andygrove73@gmail.com>
#[test] | ||
fn test_offset_after_limit_with_limit_push() { | ||
let sql = "select id from person where person.id > 100 LIMIT 5 OFFSET 3;"; | ||
let expected = "Offset: 3\ | ||
\n Limit: 8\ | ||
\n Projection: #person.id\ | ||
\n Filter: #person.id > Int64(100)\ | ||
\n TableScan: person projection=None"; | ||
|
||
quick_test_with_limit_pushdown(sql, expected); | ||
} | ||
|
||
#[test] | ||
fn test_offset_before_limit_with_limit_push() { | ||
let sql = "select id from person where person.id > 100 OFFSET 3 LIMIT 5;"; | ||
let expected = "Offset: 3\ | ||
\n Limit: 8\ | ||
\n Projection: #person.id\ | ||
\n Filter: #person.id > Int64(100)\ | ||
\n TableScan: person projection=None"; | ||
quick_test_with_limit_pushdown(sql, expected); | ||
} | ||
|
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.
Add test
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! That makes it much clearer
* support offset push down * change the limit and offset order * add test for join and subquery * fmt * Apply suggestions from code review Co-authored-by: Andy Grove <andygrove73@gmail.com> * add sql test in planner.rs * add sql test in planner.rs * fix clippy Co-authored-by: Andy Grove <andygrove73@gmail.com>
* support offset push down * change the limit and offset order * add test for join and subquery * fmt * Apply suggestions from code review Co-authored-by: Andy Grove <andygrove73@gmail.com> * add sql test in planner.rs * add sql test in planner.rs * fix clippy Co-authored-by: Andy Grove <andygrove73@gmail.com>
* support offset push down * change the limit and offset order * add test for join and subquery * fmt * Apply suggestions from code review Co-authored-by: Andy Grove <andygrove73@gmail.com> * add sql test in planner.rs * add sql test in planner.rs * fix clippy Co-authored-by: Andy Grove <andygrove73@gmail.com>
Which issue does this PR close?
Closes #2550.
like in pg
if we have
limit a + offset b
will push limita+b
to tableScanRationale for this change
What changes are included in this PR?
Are there any user-facing changes?