-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
@@ -1528,25 +1533,35 @@ impl LogicalPlan { | |||
/// | |||
/// See [`Self::with_param_values`] for examples and usage | |||
pub fn replace_params_with_values( | |||
&self, | |||
self, |
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.
Removing the &
is the API change -- this allows avoiding a clone
expr: Expr, | ||
param_values: &ParamValues, | ||
) -> Result<Expr> { | ||
expr.transform(&|expr| { |
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.
rewrite_with_subqueries handles recursing into the subqueries so this is no longer necessary
5743c2a
to
cdce3f1
Compare
param_values: &ParamValues, | ||
) -> Result<LogicalPlan> { | ||
let new_exprs = self | ||
.expressions() |
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.
expressions clone
s Exprs
.map(|inp| inp.replace_params_with_values(param_values)) | ||
.collect::<Result<Vec<_>>>()?; | ||
|
||
self.with_new_exprs(new_exprs, new_inputs_with_values) |
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.
new_with_exprs
also copies all the other fields of the plan, so removing it results in fewer copies too
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
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.
👍
Thanks @andygrove and @jayzhan211 |
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 planAre 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 internallyclone
ing