Skip to content

remove recursion in optimizer rules - #4650

Merged
alamb merged 1 commit into
apache:masterfrom
jackwener:remove_recursion
Dec 20, 2022
Merged

remove recursion in optimizer rules#4650
alamb merged 1 commit into
apache:masterfrom
jackwener:remove_recursion

Conversation

@jackwener

@jackwenerjackwener commented Dec 15, 2022

Copy link
Copy Markdown
Member

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?

Comment on lines +1330 to +1341
pub predicate: Expr,
/// The incoming logical plan
input: Arc<LogicalPlan>,
pub input: Arc<LogicalPlan>,

Copy link
Copy Markdown
MemberAuthor

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 .

Copy link
Copy Markdown
Contributor

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

Comment on lines +47 to +52
LogicalPlan::Filter(Filter {
predicate: Expr::Literal(ScalarValue::Boolean(Some(v))),
input,
}) => {

Copy link
Copy Markdown
MemberAuthor

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

Copy link
Copy Markdown
Contributor

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)ifmatches(!filter.expr(),Expr::Literal(ScalarValue::Boolean(Some(v))))){ ...

@github-actionsgithub-actionsBot added core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules labels Dec 15, 2022
@jackwener

Copy link
Copy Markdown
MemberAuthor

Rely on #4618

@alamb
alamb marked this pull request as draft December 15, 2022 19:51
@alamb

Copy link
Copy Markdown
Contributor

Marking as draft as it builds on #4618

@jackwener
jackwener marked this pull request as ready for review December 19, 2022 05:32

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

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:

  1. If possible I think it would be worth the time trying to avoid making Filter fields pub as we have discussed earlier. I left a suggestion on how maybe that could be done.
  2. Double check the Top Down vs Bottom Up changes in sql optimizer passes

Really nicely done and thank you again.

Comment on lines +1330 to +1341
pub predicate: Expr,
/// The incoming logical plan
input: Arc<LogicalPlan>,
pub input: Arc<LogicalPlan>,

Copy link
Copy Markdown
Contributor

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

"decorrelate_where_in"
}

fn apply_order(&self) -> Option<ApplyOrder> {

Copy link
Copy Markdown
Contributor

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 👨‍🍳 👌

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

Copy link
Copy Markdown
Contributor

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 🤔

Copy link
Copy Markdown
MemberAuthor

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.

Comment on lines +47 to +52
LogicalPlan::Filter(Filter {
predicate: Expr::Literal(ScalarValue::Boolean(Some(v))),
input,
}) => {

Copy link
Copy Markdown
Contributor

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)ifmatches(!filter.expr(),Expr::Literal(ScalarValue::Boolean(Some(v))))){ ...

@jackwener

Copy link
Copy Markdown
MemberAuthor

If possible I think it would be worth the time trying to avoid making Filter fields pub as we have discussed earlier. I left a suggestion on how maybe that could be done.

I find a good way to resolve it by adding #[non_exhaustive]

@alamb

Copy link
Copy Markdown
Contributor

I find a good way to resolve it by adding #[non_exhaustive]

This is reasonable (it will prevent construction outside of the crate, so in datafusion core and planner) 👍 nice

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jackwener

@alamb
alamb merged commit 2792113 into apache:masterDec 20, 2022
@ursabot

Copy link
Copy Markdown

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.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@jackwener
jackwener deleted the remove_recursion branch December 21, 2022 01:55
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratelogical-exprLogical plan and expressionsoptimizerOptimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jackwener@alamb@ursabot