Interface RelOptPlanner
- All Known Implementing Classes:
AbstractRelOptPlanner,HepPlanner,MockRelOptPlanner,VolcanoPlanner
RelOptPlanner is a query optimizer: it transforms a relational
expression into a semantically equivalent relational expression, according to
a given set of rules and a cost model.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classThrown byfindBestExp().static interfaceDeprecated. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLattice(RelOptLattice lattice) Defines a lattice.voidaddListener(RelOptListener newListener) Adds a listener to this planner.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.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.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 this query.Provides the Context created when this planner was constructed.@Nullable RelOptCostDeprecated.UsegetCost(RelNode, RelMetadataQuery)or, better, callRelMetadataQuery.getCumulativeCost(RelNode).@Nullable RelOptCostgetCost(RelNode rel, RelMetadataQuery mq) Computes the cost of a RelNode.Returns the factory that createsRelOptCosts.Returns the decorrelator used to decorrelate expressions.@Nullable RexExecutorReturns the executor used to evaluate constant expressions.@Nullable RelOptLatticegetLattice(RelOptTable table) Retrieves a lattice, given its star table.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.getRules()Returns the list of all registered rules.booleanisRegistered(RelNode rel) Determines whether a relational expression has been registered.voidCalled when a relational expression is copied to a similar expression.voidPrunes a node from the planner.Registers a relational expression in the expression bank.voidregisterClass(RelNode node) Registers a class of RelNode.voidDeprecated.voidregisterSchema(RelOptSchema schema) Tells this planner that a schema exists.booleanremoveRule(RelOptRule rule) Removes a rule.voidsetCancelFlag(CancelFlag cancelFlag) Deprecated.Previously, this method installed the cancellation-checking flag for this planner, but is now deprecated.voidsetDecorrelator(@Nullable RelDecorrelator decorrelator) Sets the decorrelator.voidsetExecutor(@Nullable RexExecutor executor) Sets the object that can execute scalar expressions.voidSets the root node of this query.voidsetRuleDescExclusionFilter(@Nullable Pattern exclusionFilter) Sets the exclusion filter to use for this planner.
-
Field Details
-
LOGGER
static final org.slf4j.Logger LOGGER
-
-
Method Details
-
setRoot
Sets the root node of this query.- Parameters:
rel- Relational expression
-
getRoot
@Nullable RelNode getRoot()Returns the root node of this query.- Returns:
- Root node
-
addRelTraitDef
Registers a rel trait definition. If theRelTraitDefhas already been registered, does nothing.- Returns:
- whether the RelTraitDef was added, as per
Collection.add(E)
-
clearRelTraitDefs
void clearRelTraitDefs()Clear all the registered RelTraitDef. -
getRelTraitDefs
List<RelTraitDef> getRelTraitDefs()Returns the list of active trait types. -
clear
void clear()Removes all internal state, including all registered rules, materialized views, and lattices. -
getRules
List<RelOptRule> getRules()Returns the list of all registered rules. -
addRule
Registers 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.- Returns:
- whether the rule was added, as per
Collection.add(E)
-
removeRule
Removes a rule.- Returns:
- true if the rule was present, as per
Collection.remove(Object)
-
getContext
Context getContext()Provides the Context created when this planner was constructed.- Returns:
- Never null; either an externally defined context, or a dummy context that returns null for each requested interface
-
setRuleDescExclusionFilter
Sets the exclusion filter to use for this planner. Rules which match the given pattern will not be fired regardless of whether or when they are added to the planner.- Parameters:
exclusionFilter- pattern to match for exclusion; null to disable filtering
-
setCancelFlag
Deprecated.Previously, this method installed the cancellation-checking flag for this planner, but is now deprecated. Now, you should add aCancelFlagto theContextpassed to the constructor.Does nothing.- Parameters:
cancelFlag- flag which the planner should periodically check
-
changeTraits
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
RelOptPlanner chooseDelegate()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. -
addMaterialization
Defines 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. -
getMaterializations
List<RelOptMaterialization> getMaterializations()Returns the materializations that have been registered with the planner. -
addLattice
Defines a lattice.The lattice may have materializations; it is not necessary to call
addMaterialization(org.apache.calcite.plan.RelOptMaterialization)for these; they are registered implicitly. -
getLattice
Retrieves a lattice, given its star table. -
findBestExp
RelNode findBestExp()Finds the most efficient expression to implement this query.- Throws:
RelOptPlanner.CannotPlanException- if cannot find a plan
-
getCostFactory
RelOptCostFactory getCostFactory()Returns the factory that createsRelOptCosts. -
getCost
Computes the cost of a RelNode. In most cases, this just dispatches toRelMetadataQuery.getCumulativeCost(org.apache.calcite.rel.RelNode).- Parameters:
rel- Relational expression of interestmq- Metadata query- Returns:
- estimated cost
-
getCost
Deprecated.UsegetCost(RelNode, RelMetadataQuery)or, better, callRelMetadataQuery.getCumulativeCost(RelNode). -
register
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
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
Registers 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
-
isRegistered
Determines whether a relational expression has been registered.- Parameters:
rel- expression to test- Returns:
- whether rel has been registered
-
registerSchema
Tells this planner that a schema exists. This is the schema's chance to tell the planner about all of the special transformation rules. -
addListener
Adds a listener to this planner.- Parameters:
newListener- new listener to be notified of events
-
registerMetadataProviders
Deprecated.Gives 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.
- Parameters:
list- receives planner's custom providers, if any
-
getRelMetadataTimestamp
Deprecated.Gets a timestamp for a given rel's metadata. This timestamp is used byCachingRelMetadataProviderto decide whether cached metadata has gone stale.- Parameters:
rel- rel of interest- Returns:
- timestamp of last change which might affect metadata derivation
-
prune
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.
- Parameters:
rel- the node to prune.
-
registerClass
Registers a class of RelNode. If this class of RelNode has been seen before, does nothing.- Parameters:
node- Relational expression
-
emptyTraitSet
RelTraitSet emptyTraitSet()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.
- Returns:
- Empty trait set
-
setExecutor
Sets the object that can execute scalar expressions. -
getExecutor
@Nullable RexExecutor getExecutor()Returns the executor used to evaluate constant expressions. -
setDecorrelator
Sets the decorrelator. -
getDecorrelator
RelDecorrelator getDecorrelator()Returns the decorrelator used to decorrelate expressions.- Throws:
IllegalStateException- if the decorrelator has not been set
-
onCopy
Called when a relational expression is copied to a similar expression.
-
RexExecutor