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
OptimizerRule
s 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
OptimizerRule
s.
Required Methods§
Provided Methods§
Sourcefn try_optimize(
&self,
_plan: &LogicalPlan,
_config: &dyn OptimizerConfig,
) -> Result<Option<LogicalPlan>>
👎Deprecated since 40.0.0: please implement supports_rewrite and rewrite instead
fn try_optimize( &self, _plan: &LogicalPlan, _config: &dyn OptimizerConfig, ) -> Result<Option<LogicalPlan>>
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 clone
ing
the input plan, which can be expensive. OptimizerRules should implement
Self::rewrite
instead.
Sourcefn apply_order(&self) -> Option<ApplyOrder>
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
Sourcefn supports_rewrite(&self) -> bool
fn supports_rewrite(&self) -> bool
Does this rule support rewriting owned plans (rather than by reference)?
Sourcefn rewrite(
&self,
_plan: LogicalPlan,
_config: &dyn OptimizerConfig,
) -> Result<Transformed<LogicalPlan>, DataFusionError>
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§
impl OptimizerRule for CommonSubexprEliminate
impl OptimizerRule for DecorrelatePredicateSubquery
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
impl OptimizerRule for EliminateDuplicatedExpr
impl OptimizerRule for EliminateFilter
impl OptimizerRule for EliminateGroupByConstant
impl OptimizerRule for EliminateJoin
impl OptimizerRule for EliminateLimit
impl OptimizerRule for EliminateNestedUnion
impl OptimizerRule for EliminateOneUnion
impl OptimizerRule for EliminateOuterJoin
Attempt to eliminate outer joins.
impl OptimizerRule for ExtractEquijoinPredicate
impl OptimizerRule for FilterNullJoinKeys
impl OptimizerRule for OptimizeProjections
impl OptimizerRule for PropagateEmptyRelation
impl OptimizerRule for PushDownFilter
impl OptimizerRule for PushDownLimit
Push down Limit.