Skip to content

Commit c4ba6d9

Browse files
committed
fix: do not recompute hash join exec properties if not required
1 parent 86cb815 commit c4ba6d9

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

datafusion/physical-plan/src/execution_plan.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ pub fn reset_plan_states(plan: Arc<dyn ExecutionPlan>) -> Result<Arc<dyn Executi
15041504
/// replace is requested.
15051505
/// The size of `children` must be equal to the size of `ExecutionPlan::children()`.
15061506
pub fn has_same_children_properties(
1507-
plan: &Arc<impl ExecutionPlan>,
1507+
plan: &impl ExecutionPlan,
15081508
children: &[Arc<dyn ExecutionPlan>],
15091509
) -> Result<bool> {
15101510
let old_children = plan.children();
@@ -1527,7 +1527,10 @@ pub fn has_same_children_properties(
15271527
#[macro_export]
15281528
macro_rules! check_if_same_properties {
15291529
($plan: expr, $children: expr) => {
1530-
if $crate::execution_plan::has_same_children_properties(&$plan, &$children)? {
1530+
if $crate::execution_plan::has_same_children_properties(
1531+
$plan.as_ref(),
1532+
&$children,
1533+
)? {
15311534
let plan = $plan.with_new_children_and_same_properties($children);
15321535
return Ok(::std::sync::Arc::new(plan));
15331536
}

datafusion/physical-plan/src/joins/hash_join/exec.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ use std::sync::{Arc, OnceLock};
2323
use std::{any::Any, vec};
2424

2525
use crate::ExecutionPlanProperties;
26-
use crate::execution_plan::{EmissionType, boundedness_from_children, stub_properties};
26+
use crate::execution_plan::{
27+
EmissionType, boundedness_from_children, has_same_children_properties,
28+
stub_properties,
29+
};
2730
use crate::filter_pushdown::{
2831
ChildFilterDescription, ChildPushdownResult, FilterDescription, FilterPushdownPhase,
2932
FilterPushdownPropagation,
@@ -373,9 +376,9 @@ impl HashJoinExecBuilder {
373376
children.len() == 2,
374377
"wrong number of children passed into `HashJoinExecBuilder`"
375378
);
379+
self.preserve_properties &= has_same_children_properties(&self.exec, &children)?;
376380
self.exec.right = children.swap_remove(1);
377381
self.exec.left = children.swap_remove(0);
378-
self.preserve_properties = false;
379382
Ok(self)
380383
}
381384

datafusion/physical-plan/src/sorts/sort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ impl ExecutionPlan for SortExec {
12161216
assert_eq!(children.len(), 1, "SortExec should have exactly one child");
12171217
new_sort.input = Arc::clone(&children[0]);
12181218

1219-
if !has_same_children_properties(&self, &children)? {
1219+
if !has_same_children_properties(self.as_ref(), &children)? {
12201220
// Recompute the properties based on the new input since they may have changed
12211221
let (cache, sort_prefix) = Self::compute_properties(
12221222
&new_sort.input,

0 commit comments

Comments
 (0)