Skip to content

Stop copying LogicalPlan and Exprs in RewriteDisjunctivePredicate #10305

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

rohitrastogi
Copy link
Contributor

@rohitrastogi rohitrastogi commented Apr 29, 2024

Which issue does this PR close?

Part of #9637
Closes #10213

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 29, 2024
@rohitrastogi rohitrastogi changed the title Rohit/rewrite disjunctive predicate Stop copying LogicalPlan and Exprs in RewriteDisjunctivePredicate Apr 29, 2024
@@ -56,29 +58,34 @@ use datafusion_expr::{Expr, LogicalPlan, Operator};
///
/// ```sql
/// where
/// p_partkey = l_partkey
Copy link
Contributor Author

@rohitrastogi rohitrastogi Apr 30, 2024

Choose a reason for hiding this comment

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

Fixed typo - first SQL block did not show original query before expressions were simplified.

args.retain(|expr| !exist_exprs.contains(expr));
if !args.is_empty() {
if args.len() == 1 {
new_or_predicates.push(args.remove(0));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe remove() should be O(1) here and below as there's just one item in the vector.

@@ -239,8 +252,7 @@ fn flatten_and_predicates(
for predicate in and_predicates {
match predicate {
Predicate::And { args } => {
flattened_predicates
.extend_from_slice(flatten_and_predicates(args).as_slice());
flattened_predicates.append(&mut flatten_and_predicates(args));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Append should move the predicates instead of cloning them.

@@ -305,31 +316,30 @@ fn delete_duplicate_predicates(or_predicates: &[Predicate]) -> Predicate {
}
if exist_exprs.is_empty() {
return Predicate::Or {
args: or_predicates.to_vec(),
args: or_predicates,
Copy link
Contributor Author

@rohitrastogi rohitrastogi Apr 30, 2024

Choose a reason for hiding this comment

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

Should avoid some clones here by eliminating to_vec()

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.

This is great @rohitrastogi -- thank you. A very nice first contribution 🙏

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @rohitrastogi

@comphead comphead merged commit 60e5003 into apache:main May 1, 2024
25 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop copying LogicalPlan and Exprs in RewriteDisjunctivePredicate
3 participants