datafusion_optimizer::optimizer

Trait OptimizerRule

Source
pub trait OptimizerRule: Debug {
    // 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)
 Cross Join
  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 ScalarSubqueryToJoin

Source§

impl OptimizerRule for SimplifyExpressions

Source§

impl OptimizerRule for SingleDistinctToGroupBy

Source§

impl OptimizerRule for UnwrapCastInComparison