-
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
remove recursion in optimizer rules #4650
Conversation
pub predicate: Expr, | ||
/// The incoming logical plan | ||
input: Arc<LogicalPlan>, | ||
pub input: Arc<LogicalPlan>, |
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.
pub them because I need pattern-match in rules.
Discussion about it in #4464.
cc @alamb @andygrove @tustvold .
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.
I think it is ok -- it would be nice to add some comments explaining a Filter
should not be created directly but instead use try_new()
and that these fields are only pub
to support pattern matching
LogicalPlan::Filter(Filter { | ||
predicate: Expr::Literal(ScalarValue::Boolean(Some(v))), | ||
input, | ||
}) => { |
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.
Nested Pattern-match here, so I make filter public
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.
I wonder if you could use a match guard?
LogicalPlan::Filter(filter) if matches(!filter.expr(), Expr::Literal(ScalarValue::Boolean(Some(v))))) {
...
88cdde8
to
045926e
Compare
Rely on #4618 |
Marking as draft as it builds on #4618 |
045926e
to
9622d47
Compare
b21faa9
to
4e2afb7
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.
As usual this is looking great @jackwener . Thank you 🙏
From my perspective this PR is basically ready to go except for:
- If possible I think it would be worth the time trying to avoid making
Filter
fieldspub
as we have discussed earlier. I left a suggestion on how maybe that could be done. - Double check the Top Down vs Bottom Up changes in sql optimizer passes
Really nicely done and thank you again.
pub predicate: Expr, | ||
/// The incoming logical plan | ||
input: Arc<LogicalPlan>, | ||
pub input: Arc<LogicalPlan>, |
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.
I think it is ok -- it would be nice to add some comments explaining a Filter
should not be created directly but instead use try_new()
and that these fields are only pub
to support pattern matching
} | ||
} | ||
|
||
fn name(&self) -> &str { | ||
"decorrelate_where_in" | ||
} | ||
|
||
fn apply_order(&self) -> Option<ApplyOrder> { |
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 is a really nice pattern 👨🍳 👌
@@ -1,17 +1,17 @@ | |||
Sort: supplier.s_name ASC NULLS LAST | |||
Projection: supplier.s_name, supplier.s_address | |||
LeftSemi Join: supplier.s_suppkey = __sq_2.ps_suppkey | |||
LeftSemi Join: supplier.s_suppkey = __sq_1.ps_suppkey |
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.
these changes imply the decorrelate passes used to be applied bottom up and after this PR they are applied top-down
Is that intentional? Or maybe I am misreading the diff 🤔
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.
😂 original implementation mix TopDown
and BottomUp
.
It use TopDown
overall, but use BottomUp
when match the subPlan.
I think it's a small mistake in original code but don't affect correctness.
LogicalPlan::Filter(Filter { | ||
predicate: Expr::Literal(ScalarValue::Boolean(Some(v))), | ||
input, | ||
}) => { |
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.
I wonder if you could use a match guard?
LogicalPlan::Filter(filter) if matches(!filter.expr(), Expr::Literal(ScalarValue::Boolean(Some(v))))) {
...
I find a good way to resolve it by adding |
4e2afb7
to
e7a961e
Compare
This is reasonable (it will prevent construction outside of the crate, so in datafusion core and planner) 👍 nice |
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 @jackwener
Benchmark runs are scheduled for baseline = fe477e4 and contender = 2792113. 2792113 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #.
Rationale for this change
Remove recursion in optimizer rules. and utilize the optimizer traverse the plan tree.
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?