public class VolcanoPlanner extends AbstractRelOptPlanner
RelOptPlanner.CannotPlanException, RelOptPlanner.Executor| Modifier and Type | Field and Description |
|---|---|
protected @MonotonicNonNull RelSubset |
root |
cancelFlag, context, costFactory, mapDescToRuleLOGGER| Constructor and Description |
|---|
VolcanoPlanner()
Creates a uninitialized
VolcanoPlanner. |
VolcanoPlanner(Context externalContext)
Creates a uninitialized
VolcanoPlanner. |
VolcanoPlanner(@Nullable RelOptCostFactory costFactory,
@Nullable Context externalContext)
Creates a
VolcanoPlanner with a given cost factory. |
| Modifier and Type | Method and Description |
|---|---|
void |
addLattice(RelOptLattice lattice)
Defines a lattice.
|
void |
addMaterialization(RelOptMaterialization materialization)
Defines a pair of relational expressions that are equivalent.
|
boolean |
addRelTraitDef(RelTraitDef relTraitDef)
Registers a rel trait definition.
|
boolean |
addRule(RelOptRule rule)
Registers a rule.
|
RelNode |
changeTraits(RelNode rel,
RelTraitSet toTraits)
Changes a relational expression to an equivalent one with a different set
of traits.
|
void |
checkCancel()
Checks to see whether cancellation has been requested, and if so, throws
an exception.
|
RelOptPlanner |
chooseDelegate()
Negotiates an appropriate planner to deal with distributed queries.
|
void |
clear()
Removes all internal state, including all registered rules,
materialized views, and lattices.
|
void |
clearRelTraitDefs()
Clear all the registered RelTraitDef.
|
void |
dump(PrintWriter pw)
Dumps the internal state of this VolcanoPlanner to a writer.
|
RelTraitSet |
emptyTraitSet()
Creates an empty trait set.
|
RelSubset |
ensureRegistered(RelNode rel,
@Nullable RelNode equivRel)
Registers a relational expression if it is not already registered.
|
RelNode |
findBestExp()
Finds the most efficient expression to implement the query given via
RelOptPlanner.setRoot(org.apache.calcite.rel.RelNode). |
@Nullable RelOptCost |
getCost(RelNode rel,
RelMetadataQuery mq)
Computes the cost of a RelNode.
|
@Nullable RelOptLattice |
getLattice(RelOptTable table)
Retrieves a lattice, given its star table.
|
protected RelOptCost |
getLowerBound(RelNode rel)
Gets the lower bound cost of a relational operator.
|
List<RelOptMaterialization> |
getMaterializations()
Returns the materializations that have been registered with the planner.
|
long |
getRelMetadataTimestamp(RelNode rel)
Deprecated.
|
List<RelTraitDef> |
getRelTraitDefs()
Returns the list of active trait types.
|
@Nullable RelNode |
getRoot()
Returns the root node of this query.
|
@Nullable org.apache.calcite.plan.volcano.RelSet |
getSet(RelNode rel)
Finds an expression's equivalence set.
|
@Nullable RelSubset |
getSubset(RelNode rel)
Returns the subset that a relational expression belongs to.
|
@Nullable RelSubset |
getSubset(RelNode rel,
RelTraitSet traits) |
RelSubset |
getSubsetNonNull(RelNode rel)
Returns the subset that a relational expression belongs to.
|
boolean |
isLogical(RelNode rel)
Decide whether a rule is logical or not.
|
boolean |
isRegistered(RelNode rel)
Determines whether a relational expression has been registered.
|
protected boolean |
isSubstituteRule(VolcanoRuleCall match)
Checks whether a rule match is a substitution rule match.
|
protected boolean |
isTransformationRule(VolcanoRuleCall match)
Checks whether a rule match is a transformation rule match.
|
protected boolean |
isValid(Litmus litmus)
Checks internal consistency.
|
static @PolyNull String |
normalizePlan(@PolyNull String plan)
Normalizes references to subsets within the string representation of a
plan.
|
protected void |
onNewClass(RelNode node)
Called when a new class of
RelNode is seen. |
void |
prune(RelNode rel)
Prunes a node from the planner.
|
RelSubset |
register(RelNode rel,
@Nullable RelNode equivRel)
Registers a relational expression in the expression bank.
|
void |
registerAbstractRelationalRules() |
protected void |
registerMaterializations() |
void |
registerMetadataProviders(List<RelMetadataProvider> list)
Deprecated.
|
void |
registerSchema(RelOptSchema schema)
Tells this planner that a schema exists.
|
boolean |
removeRule(RelOptRule rule)
Removes a rule.
|
void |
setLocked(boolean locked)
Sets whether this planner is locked.
|
void |
setNoneConventionHasInfiniteCost(boolean infinite)
Sets whether this planner should consider rel nodes with Convention.NONE
to have infinite cost or not.
|
void |
setRoot(RelNode rel)
Sets the root node of this query.
|
void |
setTopDownOpt(boolean value)
Enable or disable top-down optimization.
|
String |
toDot() |
protected RelOptCost |
upperBoundForInputs(RelNode mExpr,
RelOptCost upperBound)
Gets the upper bound of its inputs.
|
addListener, dumpRuleAttemptsInfo, fireRule, getContext, getCost, getCostFactory, getExecutor, getListener, getRuleByDescription, getRules, isRuleExcluded, notifyChosen, notifyDiscard, notifyEquivalence, notifyTransformation, onCopy, registerClass, setCancelFlag, setExecutor, setRuleDescExclusionFilter, subClassesprotected @MonotonicNonNull RelSubset root
public VolcanoPlanner()
VolcanoPlanner. To fully initialize
it, the caller must register the desired set of relations, rules, and
calling conventions.public VolcanoPlanner(Context externalContext)
VolcanoPlanner. To fully initialize
it, the caller must register the desired set of relations, rules, and
calling conventions.public VolcanoPlanner(@Nullable RelOptCostFactory costFactory, @Nullable Context externalContext)
VolcanoPlanner with a given cost factory.public void setTopDownOpt(boolean value)
Note: Enabling top-down optimization will automatically enable top-down trait propagation.
public boolean isRegistered(RelNode rel)
RelOptPlannerrel - expression to testpublic void setRoot(RelNode rel)
RelOptPlannerrel - Relational expression@Pure public @Nullable RelNode getRoot()
RelOptPlannerpublic List<RelOptMaterialization> getMaterializations()
RelOptPlannergetMaterializations in interface RelOptPlannergetMaterializations in class AbstractRelOptPlannerpublic void addMaterialization(RelOptMaterialization materialization)
RelOptPlannerTypically 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 RelOptPlanneraddMaterialization in class AbstractRelOptPlannerpublic void addLattice(RelOptLattice lattice)
RelOptPlannerThe lattice may have materializations; it is not necessary to call
RelOptPlanner.addMaterialization(org.apache.calcite.plan.RelOptMaterialization) for these; they are registered implicitly.
addLattice in interface RelOptPlanneraddLattice in class AbstractRelOptPlannerpublic @Nullable RelOptLattice getLattice(RelOptTable table)
RelOptPlannergetLattice in interface RelOptPlannergetLattice in class AbstractRelOptPlannerprotected void registerMaterializations()
public @Nullable org.apache.calcite.plan.volcano.RelSet getSet(RelNode rel)
rel - Relational expressionpublic boolean addRelTraitDef(RelTraitDef relTraitDef)
RelOptPlannerRelTraitDef has already
been registered, does nothing.addRelTraitDef in interface RelOptPlanneraddRelTraitDef in class AbstractRelOptPlannerCollection.add(E)public void clearRelTraitDefs()
RelOptPlannerclearRelTraitDefs in interface RelOptPlannerclearRelTraitDefs in class AbstractRelOptPlannerpublic List<RelTraitDef> getRelTraitDefs()
RelOptPlannergetRelTraitDefs in interface RelOptPlannergetRelTraitDefs in class AbstractRelOptPlannerpublic RelTraitSet emptyTraitSet()
RelOptPlannerThe empty trait set acts as the prototype (a kind of factory) for all subsequently created trait sets.
emptyTraitSet in interface RelOptPlanneremptyTraitSet in class AbstractRelOptPlannerpublic void clear()
RelOptPlannerclear in interface RelOptPlannerclear in class AbstractRelOptPlannerpublic boolean addRule(RelOptRule rule)
RelOptPlannerIf 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.
addRule in interface RelOptPlanneraddRule in class AbstractRelOptPlannerCollection.add(E)public boolean removeRule(RelOptRule rule)
RelOptPlannerremoveRule in interface RelOptPlannerremoveRule in class AbstractRelOptPlannerCollection.remove(Object)protected void onNewClass(RelNode node)
AbstractRelOptPlannerRelNode is seen.onNewClass in class AbstractRelOptPlannerpublic RelNode changeTraits(RelNode rel, RelTraitSet toTraits)
RelOptPlannerrel - Relational expression (may or may not have been registered; must
not have the desired traits)toTraits - Trait set to convert the relational expression topublic RelOptPlanner chooseDelegate()
RelOptPlannerchooseDelegate in interface RelOptPlannerchooseDelegate in class AbstractRelOptPlannerpublic RelNode findBestExp()
RelOptPlanner.setRoot(org.apache.calcite.rel.RelNode).public void checkCancel()
AbstractRelOptPlannercheckCancel in class AbstractRelOptPlannerpublic RelSubset register(RelNode rel, @Nullable RelNode equivRel)
RelOptPlannerAfter 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 RelSubset ensureRegistered(RelNode rel, @Nullable RelNode equivRel)
RelOptPlannerIf 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)protected boolean isValid(Litmus litmus)
public void registerAbstractRelationalRules()
public void registerSchema(RelOptSchema schema)
RelOptPlannerregisterSchema in interface RelOptPlannerregisterSchema in class AbstractRelOptPlannerpublic void setNoneConventionHasInfiniteCost(boolean infinite)
infinite - Whether to make none convention rel nodes infinite costpublic @Nullable RelOptCost getCost(RelNode rel, RelMetadataQuery mq)
RelOptPlannerRelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode).getCost in interface RelOptPlannergetCost in class AbstractRelOptPlannerrel - Relational expression of interestmq - Metadata querypublic @Nullable RelSubset getSubset(RelNode rel)
rel - Relational expression@API(since="1.26",
status=EXPERIMENTAL)
public RelSubset getSubsetNonNull(RelNode rel)
rel - Relational expressionAssertionError - in case subset is not foundpublic @Nullable RelSubset getSubset(RelNode rel, RelTraitSet traits)
public void prune(RelNode rel)
RelOptPlannerWhen a node is pruned, the related pending rule calls are cancelled, and future rules will not fire. This can be used to reduce the search space.
prune in interface RelOptPlannerprune in class AbstractRelOptPlannerrel - the node to prune.public void dump(PrintWriter pw)
pw - Print writernormalizePlan(String)public String toDot()
@Deprecated public void registerMetadataProviders(List<RelMetadataProvider> list)
RelOptPlannerRelMetadataProviders 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 RelOptPlannerregisterMetadataProviders in class AbstractRelOptPlannerlist - receives planner's custom providers, if any@Deprecated public long getRelMetadataTimestamp(RelNode rel)
RelOptPlannerCachingRelMetadataProvider to decide whether cached metadata has
gone stale.getRelMetadataTimestamp in interface RelOptPlannergetRelMetadataTimestamp in class AbstractRelOptPlannerrel - rel of interestpublic static @PolyNull String normalizePlan(@PolyNull String plan)
This is useful when writing tests: it helps to ensure that tests don't break when an extra rule is introduced that generates a new subset and causes subsequent subset numbers to be off by one.
For example,
FennelAggRel.FENNEL_EXEC(child=Subset#17.FENNEL_EXEC,groupCount=1, EXPR$1=COUNT())
FennelSortRel.FENNEL_EXEC(child=Subset#2.FENNEL_EXEC, key=[0], discardDuplicates=false)
FennelCalcRel.FENNEL_EXEC( child=Subset#4.FENNEL_EXEC, expr#0..8={inputs}, expr#9=3456, DEPTNO=$t7, $f0=$t9)
MockTableImplRel.FENNEL_EXEC( table=[CATALOG, SALES, EMP])
becomes
FennelAggRel.FENNEL_EXEC(child=Subset#{0}.FENNEL_EXEC, groupCount=1, EXPR$1=COUNT())
FennelSortRel.FENNEL_EXEC(child=Subset#{1}.FENNEL_EXEC, key=[0], discardDuplicates=false)
FennelCalcRel.FENNEL_EXEC( child=Subset#{2}.FENNEL_EXEC,expr#0..8={inputs},expr#9=3456,DEPTNO=$t7, $f0=$t9)
MockTableImplRel.FENNEL_EXEC( table=[CATALOG, SALES, EMP])
Returns null if and only if plan is null.
plan - Planpublic void setLocked(boolean locked)
addRule(org.apache.calcite.plan.RelOptRule) will do
nothing and return false.locked - Whether planner is locked@API(since="1.24",
status=EXPERIMENTAL)
public boolean isLogical(RelNode rel)
rel - The specific rel node@API(since="1.24",
status=EXPERIMENTAL)
protected boolean isSubstituteRule(VolcanoRuleCall match)
match - The rule match to check@API(since="1.24",
status=EXPERIMENTAL)
protected boolean isTransformationRule(VolcanoRuleCall match)
match - The rule match to check@API(since="1.24",
status=EXPERIMENTAL)
protected RelOptCost getLowerBound(RelNode rel)
rel - The rel node@API(since="1.24",
status=EXPERIMENTAL)
protected RelOptCost upperBoundForInputs(RelNode mExpr,
RelOptCost upperBound)
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.