Skip to content

Commit c101751

Browse files
committed
Address review: reset_cache guidance, provider note on the deprecated helper, ConfigOnlyContext invariant
1 parent 5a4626e commit c101751

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎datafusion/physical-optimizer/src/limit_pushdown.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ struct LimitInfo {
158158
///
159159
/// If a limit is encountered, a [`TreeNodeRecursion::Stop`] is returned. Otherwise,
160160
/// return a [`TreeNodeRecursion::Continue`].
161+
///
162+
/// Computes statistics with a new [`StatisticsContext`] that has no statistics
163+
/// providers. A context built from a statistics registry, as [`LimitPushdown`]
164+
/// uses, also consults the registered providers, so switching to
165+
/// [`pushdown_limit_helper_with_stats`] with such a context can change the
166+
/// result when providers are registered.
161167
#[deprecated(
162168
since = "56.0.0",
163169
note = "use `pushdown_limit_helper_with_stats` and share one `StatisticsContext` across calls"

‎datafusion/physical-optimizer/src/optimizer.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ use datafusion_common::config::ConfigOptions;
4343
use datafusion_physical_plan::statistics::StatisticsContext;
4444

4545
// Re-export from this module for backwards compatibility.
46-
pub use datafusion_session::with_statistics_context;
4746
pub use datafusion_session::{PhysicalOptimizerContext, PhysicalOptimizerRule};
4847

48+
pub use datafusion_session::with_statistics_context;
49+
4950
/// Simple context wrapping [`ConfigOptions`] for backward compatibility.
5051
///
5152
/// This struct provides a minimal implementation of [`PhysicalOptimizerContext`]
@@ -62,6 +63,7 @@ impl<'a> ConfigOnlyContext<'a> {
6263
pub fn new(config: &'a ConfigOptions) -> Self {
6364
Self {
6465
config,
66+
// No providers, matching `statistics_registry()`, which is `None`
6567
statistics_context: StatisticsContext::new(),
6668
}
6769
}

‎datafusion/physical-plan/src/statistics.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ pub enum ChildStats {
157157
/// plan rewrites. Each entry holds a strong reference to the plan node it was
158158
/// computed for, so cached nodes (and their per-partition statistics) stay
159159
/// alive until [`Self::reset_cache`] is called or the context is dropped. Reset
160-
/// a long-lived context at a lifecycle boundary to bound its memory.
160+
/// a long-lived context at a lifecycle boundary to bound its memory (see
161+
/// [`Self::reset_cache`]).
161162
///
162163
/// An optional [`StatisticsRegistry`] plugs providers into the walk: at each node
163164
/// they are consulted before the operator's built-in
@@ -199,8 +200,10 @@ impl StatisticsContext {
199200
/// Clears the memoization cache and releases its retained plan nodes.
200201
///
201202
/// Resetting is optional for correctness: each cache entry retains the plan
202-
/// node that supplied its pointer key. Use it to bound memory at a logical
203-
/// lifecycle boundary, such as after an optimizer pass.
203+
/// node that supplied its pointer key. Use it to bound memory at a
204+
/// lifecycle boundary, such as the end of a query's physical optimization.
205+
/// Do not reset a context that several optimizer rules share between those
206+
/// rules: that discards the statistics that later rules would reuse.
204207
pub fn reset_cache(&self) {
205208
let mut cache = self.cache.lock();
206209
cache.statistics.clear();

‎docs/source/library-user-guide/upgrading/56.0.0.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,10 @@ For the same reason,
797797
`datafusion_physical_optimizer::limit_pushdown::pushdown_limit_helper` is
798798
deprecated in favour of `pushdown_limit_helper_with_stats`, which takes the
799799
`StatisticsContext` from the caller. The deprecated form creates a new context
800-
on every call.
800+
on every call, without statistics providers. When providers are registered,
801+
switching to `pushdown_limit_helper_with_stats` with a context built from the
802+
statistics registry can change the result, because the providers are then
803+
consulted.
801804

802805
### `MergeIntoOp` requires the SQL-visible target qualifier
803806

0 commit comments

Comments
 (0)