This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new c8a3d5898 Minor: Avoid some extra plan construction (#5761)
c8a3d5898 is described below
commit c8a3d589889dd1e67047de89db8b4ff56f90f04c
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Mar 28 20:05:50 2023 +0200
Minor: Avoid some extra plan construction (#5761)
---
datafusion/expr/src/tree_node/plan.rs | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/datafusion/expr/src/tree_node/plan.rs
b/datafusion/expr/src/tree_node/plan.rs
index 122359bf0..e948f90da 100644
--- a/datafusion/expr/src/tree_node/plan.rs
+++ b/datafusion/expr/src/tree_node/plan.rs
@@ -108,11 +108,20 @@ impl TreeNode for LogicalPlan {
where
F: FnMut(Self) -> Result<Self>,
{
- let children = self.inputs().into_iter().cloned().collect::<Vec<_>>();
- if !children.is_empty() {
- let new_children: Result<Vec<_>> =
- children.into_iter().map(transform).collect();
- self.with_new_inputs(new_children?.as_slice())
+ let old_children = self.inputs();
+ let new_children = old_children
+ .iter()
+ .map(|&c| c.clone())
+ .map(transform)
+ .collect::<Result<Vec<_>>>()?;
+
+ // if any changes made, make a new child
+ if old_children
+ .iter()
+ .zip(new_children.iter())
+ .any(|(c1, c2)| c1 != &c2)
+ {
+ self.with_new_inputs(new_children.as_slice())
} else {
Ok(self)
}