pub trait PhysicalOptimizerRule: Debug + Any {
// Required methods
fn optimize(
&self,
plan: Arc<dyn ExecutionPlan>,
config: &ConfigOptions,
) -> Result<Arc<dyn ExecutionPlan>>;
fn name(&self) -> &str;
fn schema_check(&self) -> bool;
// Provided method
fn optimize_with_context(
&self,
plan: Arc<dyn ExecutionPlan>,
context: &dyn PhysicalOptimizerContext,
) -> Result<Arc<dyn ExecutionPlan>> { ... }
}Expand description
PhysicalOptimizerRule transforms one ExecutionPlan into another which
computes the same results, but in a potentially more efficient way.
The returned plan must be valid and produce the same results as the input
plan. See PhysicalOptimizer for more details.
Use SessionStateBuilder::with_physical_optimizer_rule to register additional
PhysicalOptimizerRules.
Required Methods§
Sourcefn optimize(
&self,
plan: Arc<dyn ExecutionPlan>,
config: &ConfigOptions,
) -> Result<Arc<dyn ExecutionPlan>>
fn optimize( &self, plan: Arc<dyn ExecutionPlan>, config: &ConfigOptions, ) -> Result<Arc<dyn ExecutionPlan>>
Rewrite plan to an optimized form.
This is the primary optimization method. For rules that need access to
the statistics registry, override optimize_with_context instead.
Sourcefn schema_check(&self) -> bool
fn schema_check(&self) -> bool
A flag to indicate whether the physical planner should validate that the rule will not change the schema of the plan after the rewriting. Some of the optimization rules might change the nullable properties of the schema and should disable the schema check.
The planner reads this from the rule it holds, so a rule that runs
other rules inside its own optimize must account for what the
whole wrapped transformation does to the schema, not just its own body:
- A wrapper around a single rule should forward that rule’s value.
- A wrapper that runs multiple rules should return
trueonly if the complete wrapped transformation preserves the schema contract. When that is derived solely from the wrapped rules, every wrapped rule must enable the check (all(), notany()): if any wrapped rule is allowed to change the schema, returningtruemakes the checker assert a change it should tolerate. - A wrapper mixing schema-preserving and schema-changing rules cannot be expressed as a single flag; validate per-rule inside the wrapper so the inner checks are retained.
When the flag can be derived from the wrapped rules, all() (not
any()) is the safe combinator:
fn schema_check(&self) -> bool {
self.wrapped.iter().all(|rule| rule.schema_check())
}Returning a blanket false still silently disables validation for
everything inside, including rules that asked for it.
Provided Methods§
Sourcefn optimize_with_context(
&self,
plan: Arc<dyn ExecutionPlan>,
context: &dyn PhysicalOptimizerContext,
) -> Result<Arc<dyn ExecutionPlan>>
fn optimize_with_context( &self, plan: Arc<dyn ExecutionPlan>, context: &dyn PhysicalOptimizerContext, ) -> Result<Arc<dyn ExecutionPlan>>
Rewrite plan with access to extended context (statistics registry, etc.).
Override this method if you need access to the statistics registry for
enhanced statistics lookup. The default implementation simply calls
optimize with the config options from the context.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".