Skip to content

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
///
/// ```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.

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.

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
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.

Stop copying LogicalPlan and Exprs in RewriteDisjunctivePredicate

3 participants