diff --git a/datafusion/physical-expr/src/expressions/dynamic_filters.rs b/datafusion/physical-expr/src/expressions/dynamic_filters.rs index 7703d201aaea9..643745ac0f07e 100644 --- a/datafusion/physical-expr/src/expressions/dynamic_filters.rs +++ b/datafusion/physical-expr/src/expressions/dynamic_filters.rs @@ -310,14 +310,14 @@ impl DynamicFilterPhysicalExpr { /// that created the filter). This is useful to avoid computing expensive filter /// expressions when no consumer will actually use them. /// - /// Note: We check the inner Arc's strong_count, not the outer Arc's count, because - /// when filters are transformed (e.g., via reassign_expr_columns during filter pushdown), - /// new outer Arc instances are created via with_new_children(), but they all share the - /// same inner `Arc>`. This is what allows filter updates to propagate to - /// consumers even after transformation. + /// # Implementation Details + /// + /// We check both Arc counts to handle two cases: + /// - Transformed filters (via `with_new_children`) share the inner Arc (inner count > 1) + /// - Direct clones (via `Arc::clone`) increment the outer count (outer count > 1) pub fn is_used(self: &Arc) -> bool { // Strong count > 1 means at least one consumer is holding a reference beyond the producer. - Arc::strong_count(&self.inner) > 1 + Arc::strong_count(self) > 1 || Arc::strong_count(&self.inner) > 1 } fn render( diff --git a/datafusion/physical-plan/src/joins/hash_join/exec.rs b/datafusion/physical-plan/src/joins/hash_join/exec.rs index b290b8549c53b..beca48a5b7d50 100644 --- a/datafusion/physical-plan/src/joins/hash_join/exec.rs +++ b/datafusion/physical-plan/src/joins/hash_join/exec.rs @@ -631,10 +631,8 @@ impl HashJoinExec { /// /// This method is intended for testing only and should not be used in production code. #[doc(hidden)] - pub fn dynamic_filter_for_test(&self) -> Option> { - self.dynamic_filter - .as_ref() - .map(|df| Arc::clone(&df.filter)) + pub fn dynamic_filter_for_test(&self) -> Option<&Arc> { + self.dynamic_filter.as_ref().map(|df| &df.filter) } /// Calculate order preservation flags for this hash join.