Class LogicalPlanOptimizer
java.lang.Object
org.elasticsearch.xpack.esql.rule.RuleExecutor<LogicalPlan>
org.elasticsearch.xpack.esql.rule.ParameterizedRuleExecutor<LogicalPlan,LogicalOptimizerContext>
org.elasticsearch.xpack.esql.optimizer.LogicalPlanOptimizer
public class LogicalPlanOptimizer
extends ParameterizedRuleExecutor<LogicalPlan,LogicalOptimizerContext>
This class is part of the planner
Global optimizations based strictly on the structure of the query (i.e. not factoring in information about the backing indices). The bulk of query transformations happen in this step.
Global optimizations based strictly on the structure of the query (i.e. not factoring in information about the backing indices). The bulk of query transformations happen in this step. This has three important sub-phases:
- The
substitutions()phase rewrites things to expand out shorthand in the syntax. For example, a nested expression embedded in a stats gets replaced with an eval followed by a stats, followed by another eval. This phase also applies surrogates, such as replacing an average with a sum divided by a count. operators(boolean)(NB: The word "operator" is extremely overloaded and referrers to many different things.) transform the tree in various different ways. This includes folding (i.e. computing constant expressions at parse time), combining expressions, dropping redundant clauses, and some normalization such as putting literals on the right whenever possible. These rules are run in a loop until none of the rules make any changes to the plan (there is also a safety shut off after many iterations, although hitting that is considered a bug)cleanup()Which can replace sorts+limit with a TopN
Note that the operators(boolean) and cleanup() steps are reapplied at the
LocalLogicalPlanOptimizer layer.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.rule.RuleExecutor
RuleExecutor.Batch<TreeType extends Node<TreeType>>, RuleExecutor.ExecutionInfo, RuleExecutor.Limiter, RuleExecutor.Transformation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected List<RuleExecutor.Batch<LogicalPlan>> batches()protected static RuleExecutor.Batch<LogicalPlan> cleanup()protected static RuleExecutor.Batch<LogicalPlan> operators(boolean local) optimize(LogicalPlan verified) protected static List<RuleExecutor.Batch<LogicalPlan>> rules()protected static RuleExecutor.Batch<LogicalPlan> Methods inherited from class org.elasticsearch.xpack.esql.rule.ParameterizedRuleExecutor
context, transformMethods inherited from class org.elasticsearch.xpack.esql.rule.RuleExecutor
execute, executeWithInfo
-
Constructor Details
-
LogicalPlanOptimizer
-
-
Method Details
-
optimize
-
batches
- Specified by:
batchesin classRuleExecutor<LogicalPlan>
-
rules
-
substitutions
-
operators
-
cleanup
-