Stop copying plans in LogicalPlan::with_param_values#10016
Merged
alamb merged 2 commits intoapache:mainfrom Apr 12, 2024
Merged
Stop copying plans in LogicalPlan::with_param_values#10016alamb merged 2 commits intoapache:mainfrom
LogicalPlan::with_param_values#10016alamb merged 2 commits intoapache:mainfrom
Conversation
alamb
commented
Apr 9, 2024
| /// See [`Self::with_param_values`] for examples and usage | ||
| pub fn replace_params_with_values( | ||
| &self, | ||
| self, |
Contributor
Author
There was a problem hiding this comment.
Removing the & is the API change -- this allows avoiding a clone
alamb
commented
Apr 9, 2024
| expr: Expr, | ||
| param_values: &ParamValues, | ||
| ) -> Result<Expr> { | ||
| expr.transform(&|expr| { |
Contributor
Author
There was a problem hiding this comment.
rewrite_with_subqueries handles recursing into the subqueries so this is no longer necessary
5743c2a to
cdce3f1
Compare
alamb
commented
Apr 10, 2024
| param_values: &ParamValues, | ||
| ) -> Result<LogicalPlan> { | ||
| let new_exprs = self | ||
| .expressions() |
Contributor
Author
There was a problem hiding this comment.
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) |
Contributor
Author
There was a problem hiding this comment.
new_with_exprs also copies all the other fields of the plan, so removing it results in fewer copies too
Contributor
Author
|
Thanks @andygrove and @jayzhan211 |
31 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_valuesto 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_valuessignature now takes an owned LogicalPlan rather than internallycloneing