Skip to content

Stop copying LogicalPlan and Exprs in DecorrelatePredicateSubquery #10318

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
merged 2 commits into from
May 1, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 30, 2024

Which issue does this PR close?

Part of #9637
Closes #10289

Rationale for this change

Reduce copying in

What changes are included in this PR?

  1. Avoid clones in DecorrelatePredicateSubquery

Are these changes tested?

covered by existing tests

Are there any user-facing changes?

No

Copy link
Contributor Author

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

I think it is easier to see what is actually changed in this PR using whitespace blind diff: https://github.com/apache/datafusion/pull/10318/files?w=1

.iter()
.any(|expr| matches!(expr, Expr::InSubquery(_) | Expr::Exists(_)));
if !has_subqueries {
return Ok(Transformed::no(LogicalPlan::Filter(filter)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the common case where there are no subqueries there will be no rewriting / cloning (which is the same as main


// iterate through all exists clauses in predicate, turning each into a join
let mut cur_input = filter.input.as_ref().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.

this is one avoided clone of the input plan

query,
where_in_expr: Some(expr),
negated: false,
} => in_subquery(expr, query.subquery.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.

these are clones of Arcs so while this PR removes them and it is less cloning realistically it doesn't matter

@@ -37,7 +37,7 @@ use std::sync::Arc;
use arrow::datatypes::{DataType, Schema};
use arrow::record_batch::RecordBatch;

use datafusion_common::Result;
use datafusion_common::{internal_err, Result};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the change from #10317 to get the CI to pass

@alamb alamb changed the title Avoid clones in DecorrelatePredicateSubquery Stop copying LogicalPlan and Exprs in DecorrelatePredicateSubquery Apr 30, 2024
Copy link
Member

@waynexia waynexia 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! Except for avoiding clones, using if let to reduce one nest block is also great 👍

@alamb
Copy link
Contributor Author

alamb commented May 1, 2024

Thanks for the review @waynexia

@alamb alamb merged commit e3487ee into apache:main May 1, 2024
24 of 25 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop copying LogicalPlan and Exprs in DecorrelatePredicateSubquery
2 participants