public abstract class PlanOptimizer
The core class of the optimizer. The basic design of this class is that it
is provided a list of RuleSets. RuleSets represent all of the optimizer
rules that can be run together. The rules in the RuleSet will be run
repeatedly until either no rule in the RuleSet passes check and calls
transform or until maxIter iterations (default 500) has been made over
the RuleSet. Then the next RuleSet will be moved to. Once finished,
a given RuleSet is never returned to.
Each rule is has two parts: a pattern and and associated transformer.
Transformers have two important functions: check(), and transform().
The pattern describes a pattern of node types that the optimizer will
look to match. If that match is found anywhere in the plan, then check()
will be called. check() allows the rule to look more in depth at the
matched pattern and decide whether the rule should be run or not. For
example, one might design a rule to push filters above join that would
look for the pattern filter(join) (meaning a filter followed by a join).
But only certain types of filters can be pushed. The check() function
would need to decide whether the filter that it found was pushable or not.
If check() returns true, the rule is said to have matched, and transform()
is then called. This function is responsible for making changes in the
logical plan. Once transform is complete PlanPatcher.patchUp will be
called to do any necessary cleanup in the plan, such as resetting
Run the optimizer. This method attempts to match each of the Rules
against the plan. If a Rule matches, it then calls the check
method of the associated Transformer to give the it a chance to
check whether it really wants to do the optimization. If that
returns true as well, then Transformer.transform is called.