public class HepPlanner extends AbstractRelOptPlanner
RelOptPlanner
interface.RelOptPlanner.CannotPlanException, RelOptPlanner.Executor
Modifier and Type | Field and Description |
---|---|
private java.util.Set<RelOptRule> |
allRules |
private HepProgram |
currentProgram |
private DirectedGraph<HepRelVertex,DefaultEdge> |
graph
Query graph, with edges directed from parent to child.
|
private int |
graphSizeLastGC |
private HepProgram |
mainProgram |
private java.util.Map<Pair<java.lang.String,RelDataType>,HepRelVertex> |
mapDigestToVertex |
private java.util.List<RelOptMaterialization> |
materializations |
private boolean |
noDag |
private int |
nTransformations |
private int |
nTransformationsLastGC |
private Function2<RelNode,RelNode,java.lang.Void> |
onCopyHook |
private RelTraitSet |
requestedRootTraits |
private HepRelVertex |
root |
context, costFactory
LOGGER
Constructor and Description |
---|
HepPlanner(HepProgram program)
Creates a new HepPlanner that allows DAG.
|
HepPlanner(HepProgram program,
Context context)
Creates a new HepPlanner that allows DAG.
|
HepPlanner(HepProgram program,
Context context,
boolean noDag,
Function2<RelNode,RelNode,java.lang.Void> onCopyHook,
RelOptCostFactory costFactory)
Creates a new HepPlanner with the option to keep the graph a
tree (noDag = true) or allow DAG (noDag = false).
|
Modifier and Type | Method and Description |
---|---|
void |
addMaterialization(RelOptMaterialization materialization)
Defines a pair of relational expressions that are equivalent.
|
private HepRelVertex |
addRelToGraph(RelNode rel) |
boolean |
addRule(RelOptRule rule)
Registers a rule.
|
private HepRelVertex |
applyRule(RelOptRule rule,
HepRelVertex vertex,
boolean forceConversions) |
private void |
applyRules(java.util.Collection<RelOptRule> rules,
boolean forceConversions) |
private HepRelVertex |
applyTransformationResults(HepRelVertex vertex,
HepRuleCall call,
RelTrait parentTrait) |
private void |
assertNoCycles() |
private boolean |
belongsToDag(HepRelVertex vertex)
Returns whether the vertex is valid.
|
private RelNode |
buildFinalPlan(HepRelVertex vertex) |
RelNode |
changeTraits(RelNode rel,
RelTraitSet toTraits)
Changes a relational expression to an equivalent one with a different set
of traits.
|
void |
clear()
Removes all internal state, including all registered rules,
materialized views, and lattices.
|
private void |
collectGarbage() |
private void |
contractVertices(HepRelVertex preservedVertex,
HepRelVertex discardedVertex,
java.util.List<HepRelVertex> parents) |
private int |
depthFirstApply(java.util.Iterator<HepRelVertex> iter,
java.util.Collection<RelOptRule> rules,
boolean forceConversions,
int nMatches) |
private boolean |
doesConverterApply(ConverterRule converterRule,
HepRelVertex vertex) |
private void |
dumpGraph() |
RelNode |
ensureRegistered(RelNode rel,
RelNode equivRel)
Registers a relational expression if it is not already registered.
|
(package private) void |
executeInstruction(HepInstruction.BeginGroup instruction) |
(package private) void |
executeInstruction(HepInstruction.CommonRelSubExprRules instruction) |
(package private) void |
executeInstruction(HepInstruction.ConverterRules instruction) |
(package private) void |
executeInstruction(HepInstruction.EndGroup instruction) |
(package private) void |
executeInstruction(HepInstruction.MatchLimit instruction) |
(package private) void |
executeInstruction(HepInstruction.MatchOrder instruction) |
(package private) void |
executeInstruction(HepInstruction.RuleClass<?> instruction) |
(package private) void |
executeInstruction(HepInstruction.RuleCollection instruction) |
(package private) void |
executeInstruction(HepInstruction.RuleInstance instruction) |
(package private) void |
executeInstruction(HepInstruction.Subprogram instruction) |
private void |
executeProgram(HepProgram program) |
RelNode |
findBestExp()
Finds the most efficient expression to implement this query.
|
private java.util.Iterator<HepRelVertex> |
getGraphIterator(HepRelVertex start) |
com.google.common.collect.ImmutableList<RelOptMaterialization> |
getMaterializations()
Returns the materializations that have been registered with the planner.
|
long |
getRelMetadataTimestamp(RelNode rel)
Gets a timestamp for a given rel's metadata.
|
RelNode |
getRoot()
Returns the root node of this query.
|
java.util.List<RelOptRule> |
getRules()
Returns the list of all registered rules.
|
private java.util.List<HepRelVertex> |
getVertexParents(HepRelVertex vertex)
Retrieves the parent vertices of a vertex.
|
boolean |
isRegistered(RelNode rel)
Determines whether a relational expression has been registered.
|
private static Pair<java.lang.String,RelDataType> |
key(RelNode rel) |
private boolean |
matchOperands(RelOptRuleOperand operand,
RelNode rel,
java.util.List<RelNode> bindings,
java.util.Map<RelNode,java.util.List<RelNode>> nodeChildren) |
void |
onCopy(RelNode rel,
RelNode newRel)
Called when a relational expression is copied to a similar expression.
|
RelNode |
register(RelNode rel,
RelNode equivRel)
Registers a relational expression in the expression bank.
|
void |
registerMetadataProviders(java.util.List<RelMetadataProvider> list)
Gives this planner a chance to register one or more
RelMetadataProvider s in the chain which will be used to answer
metadata queries. |
boolean |
removeRule(RelOptRule rule)
Removes a rule.
|
void |
setRoot(RelNode rel)
Sets the root node of this query.
|
private boolean |
skippingGroup() |
private void |
updateVertex(HepRelVertex vertex,
RelNode rel) |
addLattice, addListener, addRelTraitDef, checkCancel, chooseDelegate, clearRelTraitDefs, emptyTraitSet, fireRule, getContext, getCost, getCost, getCostFactory, getExecutor, getLattice, getListener, getRelTraitDefs, getRuleByDescription, isRuleExcluded, mapRuleDescription, notifyChosen, notifyDiscard, notifyEquivalence, notifyTransformation, onNewClass, registerClass, registerSchema, setCancelFlag, setExecutor, setImportance, setRuleDescExclusionFilter, subClasses, unmapRuleDescription
private final HepProgram mainProgram
private HepProgram currentProgram
private HepRelVertex root
private RelTraitSet requestedRootTraits
private final java.util.Map<Pair<java.lang.String,RelDataType>,HepRelVertex> mapDigestToVertex
private final java.util.Set<RelOptRule> allRules
private int nTransformations
private int graphSizeLastGC
private int nTransformationsLastGC
private final boolean noDag
private final DirectedGraph<HepRelVertex,DefaultEdge> graph
private final java.util.List<RelOptMaterialization> materializations
public HepPlanner(HepProgram program)
program
- program controlling rule applicationpublic HepPlanner(HepProgram program, Context context)
program
- program controlling rule applicationcontext
- to carry while planningpublic HepPlanner(HepProgram program, Context context, boolean noDag, Function2<RelNode,RelNode,java.lang.Void> onCopyHook, RelOptCostFactory costFactory)
noDag
- If false, create shared nodes if expressions are
identicalprogram
- Program controlling rule applicationonCopyHook
- Function to call when a node is copiedpublic void setRoot(RelNode rel)
RelOptPlanner
rel
- Relational expressionpublic RelNode getRoot()
RelOptPlanner
public java.util.List<RelOptRule> getRules()
RelOptPlanner
public boolean addRule(RelOptRule rule)
RelOptPlanner
If the rule has already been registered, does nothing.
This method determines if the given rule is a
ConverterRule
and pass the
ConverterRule to all
registered
RelTraitDef
instances.
Collection.add(E)
public void clear()
RelOptPlanner
clear
in interface RelOptPlanner
clear
in class AbstractRelOptPlanner
public boolean removeRule(RelOptRule rule)
RelOptPlanner
Collection.remove(Object)
public RelNode changeTraits(RelNode rel, RelTraitSet toTraits)
RelOptPlanner
rel
- Relational expression (may or may not have been registered; must
not have the desired traits)toTraits
- Trait set to convert the relational expression topublic RelNode findBestExp()
RelOptPlanner
private void executeProgram(HepProgram program)
void executeInstruction(HepInstruction.MatchLimit instruction)
void executeInstruction(HepInstruction.MatchOrder instruction)
void executeInstruction(HepInstruction.RuleInstance instruction)
void executeInstruction(HepInstruction.RuleClass<?> instruction)
void executeInstruction(HepInstruction.RuleCollection instruction)
private boolean skippingGroup()
void executeInstruction(HepInstruction.ConverterRules instruction)
void executeInstruction(HepInstruction.CommonRelSubExprRules instruction)
void executeInstruction(HepInstruction.Subprogram instruction)
void executeInstruction(HepInstruction.BeginGroup instruction)
void executeInstruction(HepInstruction.EndGroup instruction)
private int depthFirstApply(java.util.Iterator<HepRelVertex> iter, java.util.Collection<RelOptRule> rules, boolean forceConversions, int nMatches)
private void applyRules(java.util.Collection<RelOptRule> rules, boolean forceConversions)
private java.util.Iterator<HepRelVertex> getGraphIterator(HepRelVertex start)
private boolean belongsToDag(HepRelVertex vertex)
private HepRelVertex applyRule(RelOptRule rule, HepRelVertex vertex, boolean forceConversions)
private boolean doesConverterApply(ConverterRule converterRule, HepRelVertex vertex)
private java.util.List<HepRelVertex> getVertexParents(HepRelVertex vertex)
vertex
- the vertexprivate boolean matchOperands(RelOptRuleOperand operand, RelNode rel, java.util.List<RelNode> bindings, java.util.Map<RelNode,java.util.List<RelNode>> nodeChildren)
private HepRelVertex applyTransformationResults(HepRelVertex vertex, HepRuleCall call, RelTrait parentTrait)
public RelNode register(RelNode rel, RelNode equivRel)
RelOptPlanner
After it has been registered, you may not modify it.
The expression must not already have been registered. If you are not
sure whether it has been registered, call
RelOptPlanner.ensureRegistered(RelNode, RelNode)
.
rel
- Relational expression to register (must not already be
registered)equivRel
- Relational expression it is equivalent to (may be null)public void onCopy(RelNode rel, RelNode newRel)
RelOptPlanner
onCopy
in interface RelOptPlanner
onCopy
in class AbstractRelOptPlanner
public RelNode ensureRegistered(RelNode rel, RelNode equivRel)
RelOptPlanner
If equivRel
is specified, rel
is placed in the same
equivalence set. It is OK if equivRel
has different traits;
rel
will end up in a different subset of the same set.
It is OK if rel
is a subset.
rel
- Relational expression to registerequivRel
- Relational expression it is equivalent to (may be null)public boolean isRegistered(RelNode rel)
RelOptPlanner
rel
- expression to testprivate HepRelVertex addRelToGraph(RelNode rel)
private void contractVertices(HepRelVertex preservedVertex, HepRelVertex discardedVertex, java.util.List<HepRelVertex> parents)
private void updateVertex(HepRelVertex vertex, RelNode rel)
private static Pair<java.lang.String,RelDataType> key(RelNode rel)
private RelNode buildFinalPlan(HepRelVertex vertex)
private void collectGarbage()
private void assertNoCycles()
private void dumpGraph()
public void registerMetadataProviders(java.util.List<RelMetadataProvider> list)
RelOptPlanner
RelMetadataProvider
s in the chain which will be used to answer
metadata queries.
Planners which use their own relational expressions internally to represent concepts such as equivalence classes will generally need to supply corresponding metadata providers.
registerMetadataProviders
in interface RelOptPlanner
registerMetadataProviders
in class AbstractRelOptPlanner
list
- receives planner's custom providers, if anypublic long getRelMetadataTimestamp(RelNode rel)
RelOptPlanner
CachingRelMetadataProvider
to decide whether cached metadata has
gone stale.getRelMetadataTimestamp
in interface RelOptPlanner
getRelMetadataTimestamp
in class AbstractRelOptPlanner
rel
- rel of interestpublic com.google.common.collect.ImmutableList<RelOptMaterialization> getMaterializations()
RelOptPlanner
getMaterializations
in interface RelOptPlanner
getMaterializations
in class AbstractRelOptPlanner
public void addMaterialization(RelOptMaterialization materialization)
RelOptPlanner
Typically tableRel
is a
LogicalTableScan
representing a
table that is a materialized view and queryRel
is the SQL
expression that populates that view. The intention is that
tableRel
is cheaper to evaluate and therefore if the query being
optimized uses (or can be rewritten to use) queryRel
as a
sub-expression then it can be optimized by using tableRel
instead.
addMaterialization
in interface RelOptPlanner
addMaterialization
in class AbstractRelOptPlanner
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.