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
FieldsFields inherited from class org.apache.calcite.plan.AbstractRelOptPlanner
cancelFlag, context, costFactory, mapDescToRuleFields inherited from interface org.apache.calcite.plan.RelOptPlanner
LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionCreates a uninitializedVolcanoPlanner.VolcanoPlanner(@Nullable RelOptCostFactory costFactory, @Nullable Context externalContext) Creates aVolcanoPlannerwith a given cost factory.VolcanoPlanner(Context externalContext) Creates a uninitializedVolcanoPlanner. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLattice(RelOptLattice lattice) Defines a lattice.voidaddMaterialization(RelOptMaterialization materialization) Defines a pair of relational expressions that are equivalent.booleanaddRelTraitDef(RelTraitDef relTraitDef) Registers a rel trait definition.booleanaddRule(RelOptRule rule) Registers a rule.changeTraits(RelNode rel, RelTraitSet toTraits) Changes a relational expression to an equivalent one with a different set of traits.voidChecks to see whether cancellation has been requested, and if so, throws an exception.Negotiates an appropriate planner to deal with distributed queries.voidclear()Removes all internal state, including all registered rules, materialized views, and lattices.voidClear all the registered RelTraitDef.voiddump(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 RelOptCostgetCost(RelNode rel, RelMetadataQuery mq) Computes the cost of a RelNode.@Nullable RelOptLatticegetLattice(RelOptTable table) Retrieves a lattice, given its star table.protected RelOptCostgetLowerBound(RelNode rel) Gets the lower bound cost of a relational operator.Returns the materializations that have been registered with the planner.longDeprecated.Returns the list of active trait types.@Nullable RelNodegetRoot()Returns the root node of this query.@Nullable org.apache.calcite.plan.volcano.RelSetFinds an expression's equivalence set.@Nullable RelSubsetReturns the subset that a relational expression belongs to.@Nullable RelSubsetgetSubset(RelNode rel, RelTraitSet traits) getSubsetNonNull(RelNode rel) Returns the subset that a relational expression belongs to.booleanDecide whether a rule is logical or not.booleanisRegistered(RelNode rel) Determines whether a relational expression has been registered.protected booleanisSubstituteRule(VolcanoRuleCall match) Checks whether a rule match is a substitution rule match.protected booleanChecks whether a rule match is a transformation rule match.protected booleanChecks internal consistency.static @PolyNull StringnormalizePlan(@PolyNull String plan) Normalizes references to subsets within the string representation of a plan.protected voidonNewClass(RelNode node) Called when a new class ofRelNodeis seen.voidPrunes a node from the planner.Registers a relational expression in the expression bank.voidprotected voidvoidDeprecated.voidregisterSchema(RelOptSchema schema) Tells this planner that a schema exists.booleanremoveRule(RelOptRule rule) Removes a rule.voidsetLocked(boolean locked) Sets whether this planner is locked.voidsetNoneConventionHasInfiniteCost(boolean infinite) Sets whether this planner should consider rel nodes with Convention.NONE to have infinite cost or not.voidSets the root node of this query.voidsetTopDownOpt(boolean value) Enable or disable top-down optimization.toDot()protected RelOptCostupperBoundForInputs(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, getDecorrelator, getExecutor, getListener, getRuleByDescription, getRules, isRuleExcluded, notifyChosen, notifyDiscard, notifyEquivalence, notifyTransformation, onCopy, registerClass, setCancelFlag, setDecorrelator, 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 aVolcanoPlannerwith 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:RelOptPlannerDetermines whether a relational expression has been registered.- Parameters:
rel- expression to test- Returns:
- whether rel has been registered
-
setRoot
Description copied from interface:RelOptPlannerSets the root node of this query.- Parameters:
rel- Relational expression
-
getRoot
Description copied from interface:RelOptPlannerReturns the root node of this query.- Returns:
- Root node
-
getMaterializations
Description copied from interface:RelOptPlannerReturns the materializations that have been registered with the planner.- Specified by:
getMaterializationsin interfaceRelOptPlanner- Overrides:
getMaterializationsin classAbstractRelOptPlanner
-
addMaterialization
Description copied from interface:RelOptPlannerDefines a pair of relational expressions that are equivalent.Typically
tableRelis aLogicalTableScanrepresenting a table that is a materialized view andqueryRelis the SQL expression that populates that view. The intention is thattableRelis cheaper to evaluate and therefore if the query being optimized uses (or can be rewritten to use)queryRelas a sub-expression then it can be optimized by usingtableRelinstead.- Specified by:
addMaterializationin interfaceRelOptPlanner- Overrides:
addMaterializationin classAbstractRelOptPlanner
-
addLattice
Description copied from interface:RelOptPlannerDefines 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:
addLatticein interfaceRelOptPlanner- Overrides:
addLatticein classAbstractRelOptPlanner
-
getLattice
Description copied from interface:RelOptPlannerRetrieves a lattice, given its star table.- Specified by:
getLatticein interfaceRelOptPlanner- Overrides:
getLatticein 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:RelOptPlannerRegisters a rel trait definition. If theRelTraitDefhas already been registered, does nothing.- Specified by:
addRelTraitDefin interfaceRelOptPlanner- Overrides:
addRelTraitDefin classAbstractRelOptPlanner- Returns:
- whether the RelTraitDef was added, as per
Collection.add(E)
-
clearRelTraitDefs
public void clearRelTraitDefs()Description copied from interface:RelOptPlannerClear all the registered RelTraitDef.- Specified by:
clearRelTraitDefsin interfaceRelOptPlanner- Overrides:
clearRelTraitDefsin classAbstractRelOptPlanner
-
getRelTraitDefs
Description copied from interface:RelOptPlannerReturns the list of active trait types.- Specified by:
getRelTraitDefsin interfaceRelOptPlanner- Overrides:
getRelTraitDefsin classAbstractRelOptPlanner
-
emptyTraitSet
Description copied from interface:RelOptPlannerCreates 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:
emptyTraitSetin interfaceRelOptPlanner- Overrides:
emptyTraitSetin classAbstractRelOptPlanner- Returns:
- Empty trait set
-
clear
public void clear()Description copied from interface:RelOptPlannerRemoves all internal state, including all registered rules, materialized views, and lattices.- Specified by:
clearin interfaceRelOptPlanner- Overrides:
clearin classAbstractRelOptPlanner
-
addRule
Description copied from interface:RelOptPlannerRegisters a rule.If the rule has already been registered, does nothing. This method determines if the given rule is a
ConverterRuleand pass the ConverterRule to allregisteredRelTraitDef instances.- Specified by:
addRulein interfaceRelOptPlanner- Overrides:
addRulein classAbstractRelOptPlanner- Returns:
- whether the rule was added, as per
Collection.add(E)
-
removeRule
Description copied from interface:RelOptPlannerRemoves a rule.- Specified by:
removeRulein interfaceRelOptPlanner- Overrides:
removeRulein classAbstractRelOptPlanner- Returns:
- true if the rule was present, as per
Collection.remove(Object)
-
onNewClass
Description copied from class:AbstractRelOptPlannerCalled when a new class ofRelNodeis seen.- Overrides:
onNewClassin classAbstractRelOptPlanner
-
changeTraits
Description copied from interface:RelOptPlannerChanges 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:RelOptPlannerNegotiates 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:
chooseDelegatein interfaceRelOptPlanner- Overrides:
chooseDelegatein 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:AbstractRelOptPlannerChecks to see whether cancellation has been requested, and if so, throws an exception.- Overrides:
checkCancelin classAbstractRelOptPlanner
-
register
Description copied from interface:RelOptPlannerRegisters 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:RelOptPlannerRegisters a relational expression if it is not already registered.If
equivRelis specified,relis placed in the same equivalence set. It is OK ifequivRelhas different traits;relwill end up in a different subset of the same set.It is OK if
relis 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:RelOptPlannerTells 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:
registerSchemain interfaceRelOptPlanner- Overrides:
registerSchemain 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:RelOptPlannerComputes the cost of a RelNode. In most cases, this just dispatches toRelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode).- Specified by:
getCostin interfaceRelOptPlanner- Overrides:
getCostin 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:RelOptPlannerPrunes 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:
prunein interfaceRelOptPlanner- Overrides:
prunein 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:RelOptPlannerGives this planner a chance to register one or moreRelMetadataProviders 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:
registerMetadataProvidersin interfaceRelOptPlanner- Overrides:
registerMetadataProvidersin classAbstractRelOptPlanner- Parameters:
list- receives planner's custom providers, if any
-
getRelMetadataTimestamp
Deprecated.Description copied from interface:RelOptPlannerGets a timestamp for a given rel's metadata. This timestamp is used byCachingRelMetadataProviderto decide whether cached metadata has gone stale.- Specified by:
getRelMetadataTimestampin interfaceRelOptPlanner- Overrides:
getRelMetadataTimestampin 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
planis 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.
-