Class PlannerRule<T extends Bindable>
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.PlannerRule<T>
-
- Type Parameters:
T
- a parent planner expression type of all possible root planner expressions that this rule could match
- Direct Known Subclasses:
CombineFilterRule
,FilterWithElementWithComparisonRule
,FindPossibleIndexForAndPredicateRule
,FlattenNestedAndPredicateRule
,FullUnorderedExpressionToScanPlanRule
,ImplementDistinctRule
,ImplementFilterRule
,ImplementTypeFilterRule
,ImplementUnorderedUnionRule
,LogicalToPhysicalScanRule
,OrToUnorderedUnionRule
,PushConjunctElementWithComparisonIntoExistingScanRule
,PushDistinctFilterBelowFilterRule
,PushElementWithComparisonIntoExistingScanRule
,PushSortIntoExistingIndexRule
,PushTypeFilterBelowFilterRule
,RemoveRedundantTypeFilterRule
,SortToIndexRule
@API(EXPERIMENTAL) public abstract class PlannerRule<T extends Bindable> extends Object
Classes that inherit fromPlannerRule
form the base of the Cascades planning system. During the planning process, rules are matched to a currentRelationalExpression
and then provide zero or more logically equivalent expressions. The rule matching occurs in two stages: first, the planner examines thematcher
of the rule, which is aTypeMatcher
expression that expresses the operators that the rule applies to and the hierarchical structure that they take on in the expression tree. If the rule matches the binding, itsonMatch(PlannerRuleCall)
method is called, with a parameter that provides the planner'sPlanContext
and access to the map of bindings, among other things. This method can inspect the operators bound during the structural matching and implement other logic. TheonMatch()
method returns logically equivalent expressions to the planner by calling thePlannerRuleCall.yield(ExpressionRef)
method on its rule call, with a newExpressionRef
. Theyield()
method can be called more than once, or zero times if no alternative expressions are found. A rule should not attempt to modify any of the bound objects that the rule call provides. Nearly all such objects are immutable, and the mutable ones are hidden behind interfaces that do not expose mutation methods. In particular, a rule should never cast anExpressionRef
in an attempt to access it. APlannerRule
should not store state between successive calls toonMatch(PlannerRuleCall)
, since it may be reused an arbitrary number of times and may be reinstantiated at any time. To simplify cleanup, any state that needs to be shared within a rule call should be encapsulated in a helper object (such as a static inner class) or documented carefully.
-
-
Constructor Summary
Constructors Constructor Description PlannerRule(ExpressionMatcher<T> matcher)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ExpressionMatcher<T>
getMatcher()
Optional<Class<? extends Bindable>>
getRootOperator()
Returns the class of the operator at the root of the binding expression, if this rule uses a non-trivial binding.abstract void
onMatch(PlannerRuleCall call)
String
toString()
-
-
-
Constructor Detail
-
PlannerRule
public PlannerRule(@Nonnull ExpressionMatcher<T> matcher)
-
-
Method Detail
-
getRootOperator
public Optional<Class<? extends Bindable>> getRootOperator()
Returns the class of the operator at the root of the binding expression, if this rule uses a non-trivial binding. Used primarily for indexing rules for more efficient rule search.- Returns:
- the class of the root of this rule's binding, or
Optional.empty()
if the rule matches anything - See Also:
PlannerRuleSet
-
onMatch
public abstract void onMatch(@Nonnull PlannerRuleCall call)
-
getMatcher
@Nonnull public ExpressionMatcher<T> getMatcher()
-
-