-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support limit push down for offset_plan #2566
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
Changes from all commits
35bbdd5
a6aaed5
302fd4b
27879cc
365dbf0
20366bd
aa87825
59a1813
613de25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,9 +296,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |
|
|
||
| let plan = self.order_by(plan, query.order_by)?; | ||
|
|
||
| let plan: LogicalPlan = self.offset(plan, query.offset)?; | ||
| let plan: LogicalPlan = self.limit(plan, query.limit)?; | ||
|
|
||
| self.limit(plan, query.limit) | ||
| //make limit as offset's input will enable limit push down simply | ||
| self.offset(plan, query.offset) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. form the explain from pg I think in PG, the limit operator has a param with add test #2566 (comment) |
||
| } | ||
|
|
||
| fn set_expr_to_plan( | ||
|
|
@@ -2647,6 +2648,9 @@ fn parse_sql_number(n: &str) -> Result<Expr> { | |
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::datasource::empty::EmptyTable; | ||
| use crate::execution::context::ExecutionProps; | ||
| use crate::optimizer::limit_push_down::LimitPushDown; | ||
| use crate::optimizer::optimizer::OptimizerRule; | ||
| use crate::{assert_contains, logical_plan::create_udf, sql::parser::DFParser}; | ||
| use datafusion_expr::{ScalarFunctionImplementation, Volatility}; | ||
|
|
||
|
|
@@ -4375,6 +4379,16 @@ mod tests { | |
| assert_eq!(format!("{:?}", plan), expected); | ||
| } | ||
|
|
||
| fn quick_test_with_limit_pushdown(sql: &str, expected: &str) { | ||
| let plan = logical_plan(sql).unwrap(); | ||
| let rule = LimitPushDown::new(); | ||
| let optimized_plan = rule | ||
| .optimize(&plan, &ExecutionProps::new()) | ||
| .expect("failed to optimize plan"); | ||
| let formatted_plan = format!("{:?}", optimized_plan); | ||
| assert_eq!(formatted_plan, expected); | ||
| } | ||
|
|
||
| struct MockContextProvider {} | ||
|
|
||
| impl ContextProvider for MockContextProvider { | ||
|
|
@@ -4823,10 +4837,10 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| fn test_offset_with_limit() { | ||
| fn test_zero_offset_with_limit() { | ||
| let sql = "select id from person where person.id > 100 LIMIT 5 OFFSET 0;"; | ||
| let expected = "Limit: 5\ | ||
| \n Offset: 0\ | ||
| let expected = "Offset: 0\ | ||
| \n Limit: 5\ | ||
| \n Projection: #person.id\ | ||
| \n Filter: #person.id > Int64(100)\ | ||
| \n TableScan: person projection=None"; | ||
|
|
@@ -4847,6 +4861,29 @@ mod tests { | |
| quick_test(sql, expected); | ||
| } | ||
|
|
||
| #[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); | ||
| } | ||
|
|
||
|
Comment on lines
+4864
to
+4886
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! That makes it much clearer |
||
| fn assert_field_not_found(err: DataFusionError, name: &str) { | ||
| match err { | ||
| DataFusionError::SchemaError { .. } => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.