Skip to content


RuleExecutor is an abstraction of rule executors that can execute batches of rules (that transform TreeNodes).


Batches of Rules

batches: Seq[Batch]

A sequence of batches of rules

Used when RuleExecutor is executed


Executing Batches of Rules

  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] ===

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] ===

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

  plan: TreeType,
  tracker: QueryPlanningTracker): TreeType


executeAndTrack is used when:


blacklistedOnceBatches: Set[String]

blacklistedOnceBatches is empty by default (Set.empty).

blacklistedOnceBatches is used when RuleExecutor is executed.

checkBatchIdempotence Internal Method

  batch: Batch,
  plan: TreeType): Unit


checkBatchIdempotence is used when RuleExecutor is executed.


  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.


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:

Execution Strategy

Strategy is an abstraction of execution strategies.


maxIterations: Int

Used when...FIXME


errorOnExceed: Boolean = false

Used when...FIXME


maxIterationsSetting: String = null

Used when...FIXME



An execution strategy that runs until fix point (and converge) or maxIterations times, whichever comes first


An execution strategy that runs only once (with maxIterations as 1)

Last update: 2020-08-29