Class VolcanoPlanner
- All Implemented Interfaces:
RelOptPlanner
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.calcite.plan.RelOptPlanner
RelOptPlanner.CannotPlanException, RelOptPlanner.Executor
-
Field Summary
Fields inherited from class org.apache.calcite.plan.AbstractRelOptPlanner
cancelFlag, context, costFactory, mapDescToRule
Fields inherited from interface org.apache.calcite.plan.RelOptPlanner
LOGGER
-
Constructor Summary
ConstructorDescriptionCreates a uninitializedVolcanoPlanner
.VolcanoPlanner
(@Nullable RelOptCostFactory costFactory, @Nullable Context externalContext) Creates aVolcanoPlanner
with a given cost factory.VolcanoPlanner
(Context externalContext) Creates a uninitializedVolcanoPlanner
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.changeTraits
(RelNode rel, RelTraitSet toTraits) Changes a relational expression to an equivalent one with a different set of traits.void
Checks to see whether cancellation has been requested, and if so, throws an exception.Negotiates an appropriate planner to deal with distributed queries.void
clear()
Removes all internal state, including all registered rules, materialized views, and lattices.void
Clear all the registered RelTraitDef.void
dump
(PrintWriter pw) Dumps the internal state of this VolcanoPlanner to a writer.Creates an empty trait set.ensureRegistered
(RelNode rel, @Nullable RelNode equivRel) Registers a relational expression if it is not already registered.Finds the most efficient expression to implement the query given viaRelOptPlanner.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.Returns the materializations that have been registered with the planner.long
Deprecated.Returns the list of active trait types.@Nullable RelNode
getRoot()
Returns the root node of this query.@Nullable org.apache.calcite.plan.volcano.RelSet
Finds an expression's equivalence set.@Nullable RelSubset
Returns the subset that a relational expression belongs to.@Nullable RelSubset
getSubset
(RelNode rel, RelTraitSet traits) getSubsetNonNull
(RelNode rel) Returns the subset that a relational expression belongs to.boolean
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
Checks whether a rule match is a transformation rule match.protected boolean
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 ofRelNode
is seen.void
Prunes a node from the planner.Registers a relational expression in the expression bank.void
protected void
void
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
Sets the root node of this query.void
setTopDownOpt
(boolean value) Enable or disable top-down optimization.toDot()
protected RelOptCost
upperBoundForInputs
(RelNode mExpr, RelOptCost upperBound) Gets the upper bound of its inputs.Methods inherited from class org.apache.calcite.plan.AbstractRelOptPlanner
addListener, dumpRuleAttemptsInfo, fireRule, getContext, getCost, getCostFactory, getExecutor, getListener, getRuleByDescription, getRules, isRuleExcluded, notifyChosen, notifyDiscard, notifyEquivalence, notifyTransformation, onCopy, registerClass, setCancelFlag, setExecutor, setRuleDescExclusionFilter, subClasses
-
Field Details
-
root
-
-
Constructor Details
-
VolcanoPlanner
public VolcanoPlanner()Creates a uninitializedVolcanoPlanner
. To fully initialize it, the caller must register the desired set of relations, rules, and calling conventions. -
VolcanoPlanner
Creates a uninitializedVolcanoPlanner
. To fully initialize it, the caller must register the desired set of relations, rules, and calling conventions. -
VolcanoPlanner
Creates aVolcanoPlanner
with a given cost factory.
-
-
Method Details
-
setTopDownOpt
public void setTopDownOpt(boolean value) Enable or disable top-down optimization.Note: Enabling top-down optimization will automatically enable top-down trait propagation.
-
isRegistered
Description copied from interface:RelOptPlanner
Determines whether a relational expression has been registered.- Parameters:
rel
- expression to test- Returns:
- whether rel has been registered
-
setRoot
Description copied from interface:RelOptPlanner
Sets the root node of this query.- Parameters:
rel
- Relational expression
-
getRoot
Description copied from interface:RelOptPlanner
Returns the root node of this query.- Returns:
- Root node
-
getMaterializations
Description copied from interface:RelOptPlanner
Returns the materializations that have been registered with the planner.- Specified by:
getMaterializations
in interfaceRelOptPlanner
- Overrides:
getMaterializations
in classAbstractRelOptPlanner
-
addMaterialization
Description copied from interface:RelOptPlanner
Defines a pair of relational expressions that are equivalent.Typically
tableRel
is aLogicalTableScan
representing a table that is a materialized view andqueryRel
is the SQL expression that populates that view. The intention is thattableRel
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 usingtableRel
instead.- Specified by:
addMaterialization
in interfaceRelOptPlanner
- Overrides:
addMaterialization
in classAbstractRelOptPlanner
-
addLattice
Description copied from interface:RelOptPlanner
Defines a lattice.The lattice may have materializations; it is not necessary to call
RelOptPlanner.addMaterialization(org.apache.calcite.plan.RelOptMaterialization)
for these; they are registered implicitly.- Specified by:
addLattice
in interfaceRelOptPlanner
- Overrides:
addLattice
in classAbstractRelOptPlanner
-
getLattice
Description copied from interface:RelOptPlanner
Retrieves a lattice, given its star table.- Specified by:
getLattice
in interfaceRelOptPlanner
- Overrides:
getLattice
in classAbstractRelOptPlanner
-
registerMaterializations
protected void registerMaterializations() -
getSet
Finds an expression's equivalence set. If the expression is not registered, returns null.- Parameters:
rel
- Relational expression- Returns:
- Equivalence set that expression belongs to, or null if it is not registered
-
addRelTraitDef
Description copied from interface:RelOptPlanner
Registers a rel trait definition. If theRelTraitDef
has already been registered, does nothing.- Specified by:
addRelTraitDef
in interfaceRelOptPlanner
- Overrides:
addRelTraitDef
in classAbstractRelOptPlanner
- Returns:
- whether the RelTraitDef was added, as per
Collection.add(E)
-
clearRelTraitDefs
public void clearRelTraitDefs()Description copied from interface:RelOptPlanner
Clear all the registered RelTraitDef.- Specified by:
clearRelTraitDefs
in interfaceRelOptPlanner
- Overrides:
clearRelTraitDefs
in classAbstractRelOptPlanner
-
getRelTraitDefs
Description copied from interface:RelOptPlanner
Returns the list of active trait types.- Specified by:
getRelTraitDefs
in interfaceRelOptPlanner
- Overrides:
getRelTraitDefs
in classAbstractRelOptPlanner
-
emptyTraitSet
Description copied from interface:RelOptPlanner
Creates an empty trait set. It contains all registered traits, and the default values of any traits that have them.The empty trait set acts as the prototype (a kind of factory) for all subsequently created trait sets.
- Specified by:
emptyTraitSet
in interfaceRelOptPlanner
- Overrides:
emptyTraitSet
in classAbstractRelOptPlanner
- Returns:
- Empty trait set
-
clear
public void clear()Description copied from interface:RelOptPlanner
Removes all internal state, including all registered rules, materialized views, and lattices.- Specified by:
clear
in interfaceRelOptPlanner
- Overrides:
clear
in classAbstractRelOptPlanner
-
addRule
Description copied from interface:RelOptPlanner
Registers a rule.If the rule has already been registered, does nothing. This method determines if the given rule is a
ConverterRule
and pass the ConverterRule to allregistered
RelTraitDef instances.- Specified by:
addRule
in interfaceRelOptPlanner
- Overrides:
addRule
in classAbstractRelOptPlanner
- Returns:
- whether the rule was added, as per
Collection.add(E)
-
removeRule
Description copied from interface:RelOptPlanner
Removes a rule.- Specified by:
removeRule
in interfaceRelOptPlanner
- Overrides:
removeRule
in classAbstractRelOptPlanner
- Returns:
- true if the rule was present, as per
Collection.remove(Object)
-
onNewClass
Description copied from class:AbstractRelOptPlanner
Called when a new class ofRelNode
is seen.- Overrides:
onNewClass
in classAbstractRelOptPlanner
-
changeTraits
Description copied from interface:RelOptPlanner
Changes a relational expression to an equivalent one with a different set of traits.- Parameters:
rel
- Relational expression (may or may not have been registered; must not have the desired traits)toTraits
- Trait set to convert the relational expression to- Returns:
- Relational expression with desired traits. Never null, but may be abstract
-
chooseDelegate
Description copied from interface:RelOptPlanner
Negotiates an appropriate planner to deal with distributed queries. The idea is that the schemas decide among themselves which has the most knowledge. Right now, the local planner retains control.- Specified by:
chooseDelegate
in interfaceRelOptPlanner
- Overrides:
chooseDelegate
in classAbstractRelOptPlanner
-
findBestExp
Finds the most efficient expression to implement the query given viaRelOptPlanner.setRoot(org.apache.calcite.rel.RelNode)
.- Returns:
- the most efficient RelNode tree found for implementing the given query
-
checkCancel
public void checkCancel()Description copied from class:AbstractRelOptPlanner
Checks to see whether cancellation has been requested, and if so, throws an exception.- Overrides:
checkCancel
in classAbstractRelOptPlanner
-
register
Description copied from interface:RelOptPlanner
Registers a relational expression in the expression bank.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)
.- Parameters:
rel
- Relational expression to register (must not already be registered)equivRel
- Relational expression it is equivalent to (may be null)- Returns:
- the same expression, or an equivalent existing expression
-
ensureRegistered
Description copied from interface:RelOptPlanner
Registers a relational expression if it is not already registered.If
equivRel
is specified,rel
is placed in the same equivalence set. It is OK ifequivRel
has different traits;rel
will end up in a different subset of the same set.It is OK if
rel
is a subset.- Parameters:
rel
- Relational expression to registerequivRel
- Relational expression it is equivalent to (may be null)- Returns:
- Registered relational expression
-
isValid
Checks internal consistency. -
registerAbstractRelationalRules
public void registerAbstractRelationalRules() -
registerSchema
Description copied from interface:RelOptPlanner
Tells this planner that a schema exists. This is the schema's chance to tell the planner about all of the special transformation rules.- Specified by:
registerSchema
in interfaceRelOptPlanner
- Overrides:
registerSchema
in classAbstractRelOptPlanner
-
setNoneConventionHasInfiniteCost
public void setNoneConventionHasInfiniteCost(boolean infinite) Sets whether this planner should consider rel nodes with Convention.NONE to have infinite cost or not.- Parameters:
infinite
- Whether to make none convention rel nodes infinite cost
-
getCost
Description copied from interface:RelOptPlanner
Computes the cost of a RelNode. In most cases, this just dispatches toRelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode)
.- Specified by:
getCost
in interfaceRelOptPlanner
- Overrides:
getCost
in classAbstractRelOptPlanner
- Parameters:
rel
- Relational expression of interestmq
- Metadata query- Returns:
- estimated cost
-
getSubset
Returns the subset that a relational expression belongs to.- Parameters:
rel
- Relational expression- Returns:
- Subset it belongs to, or null if it is not registered
-
getSubsetNonNull
Returns the subset that a relational expression belongs to.- Parameters:
rel
- Relational expression- Returns:
- Subset it belongs to, or null if it is not registered
- Throws:
AssertionError
- in case subset is not found
-
getSubset
-
prune
Description copied from interface:RelOptPlanner
Prunes a node from the planner.When 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.
- Specified by:
prune
in interfaceRelOptPlanner
- Overrides:
prune
in classAbstractRelOptPlanner
- Parameters:
rel
- the node to prune.
-
dump
Dumps the internal state of this VolcanoPlanner to a writer.- Parameters:
pw
- Print writer- See Also:
-
toDot
-
registerMetadataProviders
Deprecated.Description copied from interface:RelOptPlanner
Gives this planner a chance to register one or moreRelMetadataProvider
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.
- Specified by:
registerMetadataProviders
in interfaceRelOptPlanner
- Overrides:
registerMetadataProviders
in classAbstractRelOptPlanner
- Parameters:
list
- receives planner's custom providers, if any
-
getRelMetadataTimestamp
Deprecated.Description copied from interface:RelOptPlanner
Gets a timestamp for a given rel's metadata. This timestamp is used byCachingRelMetadataProvider
to decide whether cached metadata has gone stale.- Specified by:
getRelMetadataTimestamp
in interfaceRelOptPlanner
- Overrides:
getRelMetadataTimestamp
in classAbstractRelOptPlanner
- Parameters:
rel
- rel of interest- Returns:
- timestamp of last change which might affect metadata derivation
-
normalizePlan
Normalizes references to subsets within the string representation of a 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.- Parameters:
plan
- Plan- Returns:
- Normalized plan
-
setLocked
public void setLocked(boolean locked) Sets whether this planner is locked. A locked planner does not accept new rules.addRule(org.apache.calcite.plan.RelOptRule)
will do nothing and return false.- Parameters:
locked
- Whether planner is locked
-
isLogical
Decide whether a rule is logical or not.- Parameters:
rel
- The specific rel node- Returns:
- True if the relnode is a logical node
-
isSubstituteRule
Checks whether a rule match is a substitution rule match.- Parameters:
match
- The rule match to check- Returns:
- True if the rule match is a substitution rule match
-
isTransformationRule
@API(since="1.24", status=EXPERIMENTAL) protected boolean isTransformationRule(VolcanoRuleCall match) Checks whether a rule match is a transformation rule match.- Parameters:
match
- The rule match to check- Returns:
- True if the rule match is a transformation rule match
-
getLowerBound
Gets the lower bound cost of a relational operator.- Parameters:
rel
- The rel node- Returns:
- The lower bound cost of the given rel. The value is ensured NOT NULL.
-
upperBoundForInputs
@API(since="1.24", status=EXPERIMENTAL) protected RelOptCost upperBoundForInputs(RelNode mExpr, RelOptCost upperBound) Gets the upper bound of its inputs. Allow users to overwrite this method as some implementations may have different cost model on some RelNodes, like Spool.
-