kosiew commented on code in PR #25929:
URL: https://github.com/apache/datafusion/pull/25929#discussion_r4163958857


##########
datafusion/physical-plan/src/statistics.rs:
##########
@@ -207,19 +224,80 @@ impl StatisticsContext {
         plan: &dyn ExecutionPlan,
         args: &StatisticsArgs,
     ) -> Result<Arc<Statistics>> {
-        self.compute_base(plan, args, false)
+        self.compute_base(plan, None, args, false)
+            .map(|(statistics, _)| statistics)
+    }
+
+    /// Like [`Self::compute`], but the cache retains `plan` so the root's own
+    /// statistics are memoized as well as its descendants'.
+    ///
+    /// Prefer this when sharing one context across repeated calls on the same
+    /// nodes, such as an optimizer pass.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// # use std::sync::Arc;
+    /// # use arrow::datatypes::{DataType, Field, Schema};
+    /// # use datafusion_common::Statistics;
+    /// # use datafusion_common::stats::Precision;
+    /// # use datafusion_physical_plan::ExecutionPlan;
+    /// # use datafusion_physical_plan::statistics::{StatisticsArgs, 
StatisticsContext};
+    /// # use datafusion_physical_plan::test::exec::StatisticsExec;
+    ///
+    /// let schema = Schema::new(vec![Field::new("a", DataType::Int32, 
false)]);
+    /// let stats = 
Statistics::new_unknown(&schema).with_num_rows(Precision::Exact(100));
+    /// let plan: Arc<dyn ExecutionPlan> = Arc::new(StatisticsExec::new(stats, 
schema));
+    ///
+    /// let context = StatisticsContext::new();
+    /// let first = context.compute_arc(&plan, &StatisticsArgs::new())?;
+    /// let second = context.compute_arc(&plan, &StatisticsArgs::new())?;
+    ///
+    /// // The second call is a cache hit for the root.
+    /// assert!(Arc::ptr_eq(&first, &second));
+    /// assert_eq!(first.num_rows, Precision::Exact(100));
+    /// # Ok::<(), datafusion_common::DataFusionError>(())
+    /// ```
+    pub fn compute_arc(

Review Comment:
   I switched enforce_distribution.rs:1012 to call `compute_arc(&child, ...)` 
and fold removal of the obsolete `Arc::ptr_eq`/`reset_cache()` guard and 
reset-specific documentation in 
   
[f8f4a8d](https://github.com/apache/datafusion/pull/25929/commits/f8f4a8deabd96de3b9432c7a27812578e0338c1d)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to