Skip to content
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

implement rewrite for ExtractEquijoinPredicate and avoid clone in filter #10165

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

Lordworms
Copy link
Contributor

Which issue does this PR close?

part of #9637

Closes #.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the optimizer Optimizer rules label Apr 21, 2024
let (equijoin_predicates, non_equijoin_expr) =
split_eq_and_noneq_join_predicate(
expr,
left_schema,
right_schema,
)?;

let optimized_plan = (!equijoin_predicates.is_empty()).then(|| {
let mut new_on = on.clone();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here to avoid clone of vector on

Comment on lines -84 to -86
left: left.clone(),
right: right.clone(),
on: new_on,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here to avoid clone of arc

}
}

fn split_eq_and_noneq_join_predicate(
filter: &Expr,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here we directly split filter to avoid further clone

@@ -141,13 +193,13 @@ fn split_eq_and_noneq_join_predicate(
if can_hash(&left_expr_type) && can_hash(&right_expr_type) {
accum_join_keys.push((left_expr, right_expr));
} else {
accum_filters.push(expr.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

avoid clone

"extract_equijoin_predicate"
}
/// split with ownership
fn split_conjunction_own(expr: Expr) -> Vec<Expr> {
Copy link
Contributor Author

@Lordworms Lordworms Apr 21, 2024

Choose a reason for hiding this comment

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

here implement a ownership version of split conjunction to avoid clone while passing reference

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok got it

@Lordworms Lordworms marked this pull request as ready for review April 21, 2024 22:31
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @Lordworms -- I think this PR looks very good 👌 .

I left a few suggestions that I think could make it better if you have some time. Otherwise we can do them as follow on PRs

"extract_equijoin_predicate"
}
/// split with ownership
fn split_conjunction_own(expr: Expr) -> Vec<Expr> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -67,66 +88,97 @@ impl OptimizerRule for ExtractEquijoinPredicate {
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might be able to avoid a level of indenting if you did the entire match here, like:

 match plan {
            LogicalPlan::Join(Join {
                left,
                right,
                mut on,
                filter: Some(expr),
                join_type,
                join_constraint,
            }) => {

Then you could avoid reassembling LogicalPlan::Join as well

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @Lordworms

@alamb alamb merged commit d9ebd2b into apache:main Apr 22, 2024
23 checks passed
ccciudatu pushed a commit to hstack/arrow-datafusion that referenced this pull request Apr 26, 2024
…ter (apache#10165)

* implement rewrite for ExtractEquijoinPredicate and avoid clone in filter

* fix clippy

* optimize code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants