class RuleQueue extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
RuleQueue.PhaseMatchList
PhaseMatchList represents a set of
rule-matches
for a particular
phase of the planner's execution. |
private class |
RuleQueue.RelImportanceComparator
Compares
RelNode objects according to their cached 'importance'. |
private static class |
RuleQueue.RuleMatchImportanceComparator
Compares
VolcanoRuleMatch objects according to their importance. |
| Modifier and Type | Field and Description |
|---|---|
private static Set<String> |
ALL_RULES |
(package private) Set<RelSubset> |
boostedSubsets
The set of RelSubsets whose importance is currently in an artificially
raised state.
|
private static org.slf4j.Logger |
LOGGER |
private static Comparator<VolcanoRuleMatch> |
MATCH_COMPARATOR
Sorts rule-matches into decreasing order of importance.
|
(package private) Map<VolcanoPlannerPhase,RuleQueue.PhaseMatchList> |
matchListMap
Map of
VolcanoPlannerPhase to a list of rule-matches. |
private static double |
ONE_MINUS_EPSILON
Largest value which is less than one.
|
private Map<VolcanoPlannerPhase,Set<String>> |
phaseRuleMapping
Maps a
VolcanoPlannerPhase to a set of rule names. |
private VolcanoPlanner |
planner |
private com.google.common.collect.Ordering<RelSubset> |
relImportanceOrdering
Compares relexps according to their cached 'importance'.
|
(package private) Map<RelSubset,Double> |
subsetImportances
The importance of each subset.
|
| Constructor and Description |
|---|
RuleQueue(VolcanoPlanner planner) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
addMatch(VolcanoRuleMatch match)
Adds a rule match.
|
void |
boostImportance(Collection<RelSubset> subsets,
double factor)
Artificially boosts the importance of the given
RelSubsets by a
given factor. |
private void |
checkDuplicateSubsets(Deque<RelSubset> subsets,
RelOptRuleOperand operand,
RelNode[] rels)
Recursively checks whether there are any duplicate subsets along any path
from root of the operand tree to one of the leaves.
|
void |
clear()
Clear internal data structure for this rule queue.
|
(package private) double |
computeImportance(RelSubset subset)
Computes the importance of a node.
|
private double |
computeImportanceOfChild(RelMetadataQuery mq,
RelSubset child,
RelSubset parent)
Returns the importance of a child to a parent.
|
private static double |
computeOneMinusEpsilon() |
private void |
dump() |
private void |
dump(PrintWriter pw) |
double |
getImportance(RelSet set)
Computes the importance of a set (which is that of its most important
subset).
|
(package private) double |
getImportance(RelSubset rel)
Returns the importance of an equivalence class of relational expressions.
|
void |
phaseCompleted(VolcanoPlannerPhase phase)
Removes the
rule-match list for the given planner
phase. |
(package private) VolcanoRuleMatch |
popMatch(VolcanoPlannerPhase phase)
Removes the rule match with the highest importance, and returns it.
|
void |
recompute(RelSubset subset)
Equivalent to
recompute(subset, false). |
void |
recompute(RelSubset subset,
boolean force)
Recomputes the importance of the given RelSubset.
|
private boolean |
skipMatch(VolcanoRuleMatch match)
Returns whether to skip a match.
|
private double |
toDouble(RelOptCost cost)
Converts a cost to a scalar quantity.
|
(package private) void |
updateImportance(RelSubset subset,
Double importance) |
private static final org.slf4j.Logger LOGGER
private static final double ONE_MINUS_EPSILON
final Set<RelSubset> boostedSubsets
final Map<VolcanoPlannerPhase,RuleQueue.PhaseMatchList> matchListMap
VolcanoPlannerPhase to a list of rule-matches. Initially,
there is an empty RuleQueue.PhaseMatchList for each planner phase. As the
planner invokes addMatch(VolcanoRuleMatch) the rule-match is
added to the appropriate PhaseMatchList(s). As the planner completes
phases, the matching entry is removed from this list to avoid unused
work.private static final Comparator<VolcanoRuleMatch> MATCH_COMPARATOR
private final VolcanoPlanner planner
private final com.google.common.collect.Ordering<RelSubset> relImportanceOrdering
private final Map<VolcanoPlannerPhase,Set<String>> phaseRuleMapping
VolcanoPlannerPhase to a set of rule names. Named rules
may be invoked in their corresponding phase.RuleQueue(VolcanoPlanner planner)
public void clear()
public void phaseCompleted(VolcanoPlannerPhase phase)
rule-match list for the given planner
phase.public double getImportance(RelSet set)
public void recompute(RelSubset subset, boolean force)
subset - RelSubset whose importance is to be recomputedforce - if true, forces an importance update even if the subset has
not been registeredpublic void recompute(RelSubset subset)
recompute(subset, false).public void boostImportance(Collection<RelSubset> subsets, double factor)
RelSubsets by a
given factor.
Iterates over the currently boosted RelSubsets and removes their
importance boost, forcing a recalculation of the RelSubsets' importances
(see recompute(RelSubset)).
Once RelSubsets have been restored to their normal importance, the given RelSubsets have their importances boosted. A RelSubset's boosted importance is always less than 1.0 (and never equal to 1.0).
subsets - RelSubsets to boost importance (priority)factor - the amount to boost their importances (e.g., 1.25 increases
importance by 25%)double getImportance(RelSubset rel)
If a subset in the same set but with a different calling convention is deemed to be important, then this subset has at least half of its importance. (This rule is designed to encourage conversions to take place.)
void addMatch(VolcanoRuleMatch match)
per-phase rule-match lists which allow
the rule referenced by the match.double computeImportance(RelSubset subset)
RelSubset has an importance of 1The formula for the importance I of node n is:
In = Sumparents p of n{Ip . W n, p}
where Wn, p, the weight of n within its parent p, is
Wn, p = Costn / (SelfCostp + Costn0 + ... + Costnk)
private void dump()
private void dump(PrintWriter pw)
VolcanoRuleMatch popMatch(VolcanoPlannerPhase phase)
Returns null if there are no more matches.
Note that the VolcanoPlanner may still decide to reject rule matches which have become invalid, say if one of their operands belongs to an obsolete set or has importance=0.
AssertionError - if this method is called with a phase
previously marked as completed via
phaseCompleted(VolcanoPlannerPhase).private boolean skipMatch(VolcanoRuleMatch match)
RelNodes have importance zero.private void checkDuplicateSubsets(Deque<RelSubset> subsets, RelOptRuleOperand operand, RelNode[] rels)
It is OK for a match to have duplicate subsets if they are not on the same path. For example,
Join / \ X X
is a valid match.
Util.FoundOne - on matchprivate double computeImportanceOfChild(RelMetadataQuery mq, RelSubset child, RelSubset parent)
private double toDouble(RelOptCost cost)
private static double computeOneMinusEpsilon()
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.