Skip to content

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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