Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Stop copying plans in LogicalPlan::with_param_values #10016

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Apr 9, 2024

Which issue does this PR close?

Part of #9637

Rationale for this change

Now that we have the nice TreeNode API that avoids copying, we can use it to
stop copying plan nodes in other places. Not only is this less code it is more
efficient.

Also helps with #8819

What changes are included in this PR?

Update LogicalPlan::replace_params_with_values to take an owned LogicalPlan and rewrite it in place rather than create an entirely new plan

Are these changes tested?

By existing tests

Are there any user-facing changes?

LogicalPlan::replace_params_with_values signature now takes an owned LogicalPlan rather than internally cloneing

@alamb alamb added the api change Changes the API exposed to users of the crate label Apr 9, 2024
@alamb alamb marked this pull request as draft April 9, 2024 15:00
@github-actions github-actions bot added the logical-expr Logical plan and expressions label Apr 9, 2024
@@ -1528,25 +1533,35 @@ impl LogicalPlan {
///
/// See [`Self::with_param_values`] for examples and usage
pub fn replace_params_with_values(
&self,
self,
Copy link
Contributor Author

@alamb alamb Apr 9, 2024

Choose a reason for hiding this comment

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

Removing the & is the API change -- this allows avoiding a clone

expr: Expr,
param_values: &ParamValues,
) -> Result<Expr> {
expr.transform(&|expr| {
Copy link
Contributor Author

@alamb alamb Apr 9, 2024

Choose a reason for hiding this comment

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

rewrite_with_subqueries handles recursing into the subqueries so this is no longer necessary

@alamb alamb force-pushed the alamb/stop_copy_on_params branch from 5743c2a to cdce3f1 Compare April 10, 2024 13:53
param_values: &ParamValues,
) -> Result<LogicalPlan> {
let new_exprs = self
.expressions()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

expressions clones Exprs

.map(|inp| inp.replace_params_with_values(param_values))
.collect::<Result<Vec<_>>>()?;

self.with_new_exprs(new_exprs, new_inputs_with_values)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new_with_exprs also copies all the other fields of the plan, so removing it results in fewer copies too

@alamb alamb marked this pull request as ready for review April 10, 2024 19:27
Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 2def10f into apache:main Apr 12, 2024
24 checks passed
@alamb
Copy link
Contributor Author

alamb commented Apr 12, 2024

Thanks @andygrove and @jayzhan211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants