Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Stop copying LogicalPlan and Exprs in CommonSubexprEliminate (2-3% planning speed improvement)#10835
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
Uh oh!
There was an error while loading. Please reload this page.
Stop copying LogicalPlan and Exprs in CommonSubexprEliminate (2-3% planning speed improvement)
#10835
Changes from all commits
f1fb3c7e7ef4b94bcabb75a073818397ad53ba54603f4cc9e67f6be203e4cbdc820f8b3639de48dd6256550e445File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -870,37 +870,7 @@ impl LogicalPlan { | ||
| LogicalPlan::Filter { .. } => { | ||
| assert_eq!(1, expr.len()); | ||
| let predicate = expr.pop().unwrap(); | ||
| // filter predicates should not contain aliased expressions so we remove any aliases | ||
| // before this logic was added we would have aliases within filters such as for | ||
| // benchmark q6: | ||
| // | ||
| // lineitem.l_shipdate >= Date32(\"8766\") | ||
| // AND lineitem.l_shipdate < Date32(\"9131\") | ||
| // AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount >= | ||
| // Decimal128(Some(49999999999999),30,15) | ||
| // AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount <= | ||
| // Decimal128(Some(69999999999999),30,15) | ||
| // AND lineitem.l_quantity < Decimal128(Some(2400),15,2) | ||
| let predicate = predicate | ||
| .transform_down(|expr| { | ||
| match expr { | ||
| Expr::Exists { .. } | ||
| | Expr::ScalarSubquery(_) | ||
| | Expr::InSubquery(_) => { | ||
| // subqueries could contain aliases so we don't recurse into those | ||
| Ok(Transformed::new(expr, false, TreeNodeRecursion::Jump)) | ||
| } | ||
| Expr::Alias(_) => Ok(Transformed::new( | ||
| expr.unalias(), | ||
| true, | ||
| TreeNodeRecursion::Jump, | ||
| )), | ||
| _ => Ok(Transformed::no(expr)), | ||
| } | ||
| }) | ||
| .data()?; | ||
| let predicate = Filter::remove_aliases(predicate)?.data; | ||
| Filter::try_new(predicate, Arc::new(inputs.swap_remove(0))) | ||
| .map(LogicalPlan::Filter) | ||
| @@ -2230,6 +2200,38 @@ impl Filter { | ||
| } | ||
| false | ||
| } | ||
| /// Remove aliases from a predicate for use in a `Filter` | ||
| /// | ||
| /// filter predicates should not contain aliased expressions so we remove | ||
| /// any aliases. | ||
| /// | ||
| /// before this logic was added we would have aliases within filters such as | ||
| /// for benchmark q6: | ||
| /// | ||
| /// ```sql | ||
| /// lineitem.l_shipdate >= Date32(\"8766\") | ||
| /// AND lineitem.l_shipdate < Date32(\"9131\") | ||
| /// AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount >= | ||
| /// Decimal128(Some(49999999999999),30,15) | ||
| /// AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount <= | ||
| /// Decimal128(Some(69999999999999),30,15) | ||
| /// AND lineitem.l_quantity < Decimal128(Some(2400),15,2) | ||
| /// ``` | ||
| pub fn remove_aliases(predicate: Expr) -> Result<Transformed<Expr>> { | ||
Contributor 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. I wonder if it make sense to move this method into ContributorAuthor 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. I think it does -- I will do so as a follow on PR ContributorAuthor 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. | ||
| predicate.transform_down(|expr| { | ||
| match expr { | ||
| Expr::Exists { .. } | Expr::ScalarSubquery(_) | Expr::InSubquery(_) => { | ||
| // subqueries could contain aliases so we don't recurse into those | ||
| Ok(Transformed::new(expr, false, TreeNodeRecursion::Jump)) | ||
| } | ||
| Expr::Alias(Alias { expr, .. }) => { | ||
| Ok(Transformed::new(*expr, true, TreeNodeRecursion::Jump)) | ||
| } | ||
| _ => Ok(Transformed::no(expr)), | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| /// Window its input based on a set of window spec and window function (e.g. SUM or RANK) | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
This code is extract into
Filter::remove_aliasesas it is needed for CSE.