Trait datafusion_optimizer::optimizer::OptimizerRule

source ·
pub trait OptimizerRule {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn try_optimize(
        &self,
        _plan: &LogicalPlan,
        _config: &dyn OptimizerConfig,
    ) -> Result<Option<LogicalPlan>> { ... }
    fn apply_order(&self) -> Option<ApplyOrder> { ... }
    fn supports_rewrite(&self) -> bool { ... }
    fn rewrite(
        &self,
        _plan: LogicalPlan,
        _config: &dyn OptimizerConfig,
    ) -> Result<Transformed<LogicalPlan>, DataFusionError> { ... }
}
Expand description

OptimizerRules transforms one LogicalPlan into another which computes the same results, but in a potentially more efficient way. If there are no suitable transformations for the input plan, the optimizer should simply return it unmodified.

To change the semantics of a LogicalPlan, see AnalyzerRule

Use SessionState::add_optimizer_rule to register additional OptimizerRules.

Required Methods§

source

fn name(&self) -> &str

A human readable name for this optimizer rule

Provided Methods§

source

fn try_optimize( &self, _plan: &LogicalPlan, _config: &dyn OptimizerConfig, ) -> Result<Option<LogicalPlan>>

👎Deprecated since 40.0.0: please implement supports_rewrite and rewrite instead

Try and rewrite plan to an optimized form, returning None if the plan cannot be optimized by this rule.

Note this API will be deprecated in the future as it requires cloneing the input plan, which can be expensive. OptimizerRules should implement Self::rewrite instead.

source

fn apply_order(&self) -> Option<ApplyOrder>

How should the rule be applied by the optimizer? See comments on ApplyOrder for details.

If returns None, the default, the rule must handle recursion itself

source

fn supports_rewrite(&self) -> bool

Does this rule support rewriting owned plans (rather than by reference)?

source

fn rewrite( &self, _plan: LogicalPlan, _config: &dyn OptimizerConfig, ) -> Result<Transformed<LogicalPlan>, DataFusionError>

Try to rewrite plan to an optimized form, returning Transformed::yes if the plan was rewritten and Transformed::no if it was not.

Note: this function is only called if Self::supports_rewrite returns true. Otherwise the Optimizer calls Self::try_optimize

Implementors§

source§

impl OptimizerRule for CommonSubexprEliminate

source§

impl OptimizerRule for DecorrelatePredicateSubquery

source§

impl OptimizerRule for EliminateCrossJoin

Eliminate cross joins by rewriting them to inner joins when possible.

§Example

The initial plan for this query:

select ... from a, b where a.x = b.y and b.xx = 100;

Looks like this:

Filter(a.x = b.y AND b.xx = 100)
 CrossJoin
  TableScan a
  TableScan b

After the rule is applied, the plan will look like this:

Filter(b.xx = 100)
  InnerJoin(a.x = b.y)
    TableScan a
    TableScan b

§Other Examples

  • ‘select … from a, b where a.x = b.y and b.xx = 100;’
  • ‘select … from a, b where (a.x = b.y and b.xx = 100) or (a.x = b.y and b.xx = 200);’
  • ’select … from a, b, c where (a.x = b.y and b.xx = 100 and a.z = c.z)
  • or (a.x = b.y and b.xx = 200 and a.z=c.z);’
  • ‘select … from a, b where a.x > b.y’

For above queries, the join predicate is available in filters and they are moved to join nodes appropriately

This fix helps to improve the performance of TPCH Q19. issue#78

source§

impl OptimizerRule for EliminateDuplicatedExpr

source§

impl OptimizerRule for EliminateFilter

source§

impl OptimizerRule for EliminateGroupByConstant

source§

impl OptimizerRule for EliminateJoin

source§

impl OptimizerRule for EliminateLimit

source§

impl OptimizerRule for EliminateNestedUnion

source§

impl OptimizerRule for EliminateOneUnion

source§

impl OptimizerRule for EliminateOuterJoin

Attempt to eliminate outer joins.

source§

impl OptimizerRule for ExtractEquijoinPredicate

source§

impl OptimizerRule for FilterNullJoinKeys

source§

impl OptimizerRule for OptimizeProjections

source§

impl OptimizerRule for PropagateEmptyRelation

source§

impl OptimizerRule for PushDownFilter

source§

impl OptimizerRule for PushDownLimit

Push down Limit.

source§

impl OptimizerRule for ReplaceDistinctWithAggregate

source§

impl OptimizerRule for RewriteDisjunctivePredicate

source§

impl OptimizerRule for ScalarSubqueryToJoin

source§

impl OptimizerRule for SimplifyExpressions

source§

impl OptimizerRule for SingleDistinctToGroupBy

source§

impl OptimizerRule for UnwrapCastInComparison