RuleExecutors¶
RuleExecutor is an abstraction of rule executors that can execute batches of rules (that transform TreeNodes).
Contract¶
Batches of Rules¶
batches: Seq[Batch]
A sequence of batches of rules
Used when RuleExecutor is executed
Implementations¶
- Logical Adaptive Optimizer
- Logical Analyzer
ExpressionCanonicalizer- Logical Optimizers
Executing Batches of Rules¶
execute(
plan: TreeType): TreeType
execute iterates over rule batches and applies rules sequentially to the input plan.
execute tracks the number of iterations and the time of executing each rule (with a plan).
When a rule changes a plan, you should see the following TRACE message in the logs:
=== Applying Rule [ruleName] ===
[currentAndModifiedPlansSideBySide]
After the number of iterations has reached the number of iterations for the batch's Strategy it stops execution and prints out the following WARN message to the logs:
Max iterations ([iteration]) reached for batch [batchName]
When the plan has not changed (after applying rules), you should see the following TRACE message in the logs and execute moves on to applying the rules in the next batch. The moment is called fixed point (i.e. when the execution converges).
Fixed point reached for batch [batchName] after [iteration] iterations.
After the batch finishes, if the plan has been changed by the rules, you should see the following DEBUG message in the logs:
=== Result of Batch [batchName] ===
[currentAndModifiedPlansSideBySide]
Otherwise, when the rules had no changes to a plan, you should see the following TRACE message in the logs:
Batch [batchName] has no effect.
Tracking Time of Executing Batches of Rules¶
executeAndTrack(
plan: TreeType,
tracker: QueryPlanningTracker): TreeType
executeAndTrack...FIXME
executeAndTrack is used when:
Analyzeris requested to executeAndCheckQueryExecutionis requested for the optimized logical plan
blacklistedOnceBatches¶
blacklistedOnceBatches: Set[String]
blacklistedOnceBatches is empty by default (Set.empty).
blacklistedOnceBatches is used when RuleExecutor is executed.
checkBatchIdempotence Internal Method¶
checkBatchIdempotence(
batch: Batch,
plan: TreeType): Unit
checkBatchIdempotence...FIXME
checkBatchIdempotence is used when RuleExecutor is executed.
isPlanIntegral¶
isPlanIntegral(
plan: TreeType): Boolean
isPlanIntegral is true by default.
isPlanIntegral is used when RuleExecutor is executed.
Scala Definition¶
abstract class RuleExecutor[TreeType <: TreeNode[_]] {
// body omitted
}
The definition of the RuleExecutor abstract class uses TreeType type parameter that is constrained by a upper type bound (TreeNode[_]). It says that TreeType type variable can only be a subtype of type TreeNode.
Tip
Read up on <: type operator in Scala in Upper Type Bounds.
Rule Batch — Collection of Rules¶
Batch is a named collection of rules with an execution strategy.
Batch is defined by the following:
- Batch Name
- Execution Strategy
- Collection of rules
Execution Strategy¶
Strategy is an abstraction of execution strategies.
maxIterations¶
maxIterations: Int
Used when...FIXME
errorOnExceed¶
errorOnExceed: Boolean = false
Used when...FIXME
maxIterationsSetting¶
maxIterationsSetting: String = null
Used when...FIXME
Implementations¶
FixedPoint¶
An execution strategy that runs until fix point (and converge) or maxIterations times, whichever comes first
Once¶
An execution strategy that runs only once (with maxIterations as 1)