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.
Use SessionState::add_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.
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".
Implementors§
impl PhysicalOptimizerRule for AggregateStatistics
impl PhysicalOptimizerRule for CombinePartialFinalAggregate
impl PhysicalOptimizerRule for EnforceDistribution
impl PhysicalOptimizerRule for EnforceSorting
Performs optimizations based upon a series of subrules. Refer to each subrule for detailed descriptions of the optimizations performed: Subrule application is ordering dependent.
Optimizer consists of 5 main parts which work sequentially
ensure_sortingWorks down-to-top to be able to remove unnecessarySortExecs,SortPreservingMergeExecs addSortExecs if necessary by a requirement and adjusts window operators.parallelize_sorts(Optional, depends on therepartition_sortsconfiguration) Responsible to identify and remove unnecessary partition unifier operators such asSortPreservingMergeExec,CoalescePartitionsExecfollowsSortExecs does possible simplifications.replace_with_order_preserving_variants()Replaces with alternative operators, for example can merge aSortExecand aCoalescePartitionsExecinto oneSortPreservingMergeExecor aSortExec+RepartitionExeccombination into an order preservingRepartitionExecsort_pushdownWorks top-down. Responsible to push down sort operators as deep as possible in the plan.replace_with_partial_sortChecks if it’s possible to replaceSortExecs withPartialSortExecoperators