-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Stop copying LogicalPlan and Exprs in RewriteDisjunctivePredicate
#10305
Conversation
RewriteDisjunctivePredicate
@@ -56,29 +58,34 @@ use datafusion_expr::{Expr, LogicalPlan, Operator}; | |||
/// | |||
/// ```sql | |||
/// where | |||
/// p_partkey = l_partkey |
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.
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)); |
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 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)); |
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.
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, |
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.
Should avoid some clones here by eliminating to_vec()
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 great @rohitrastogi -- thank you. A very nice first contribution 🙏
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.
lgtm thanks @rohitrastogi
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?