Class RelSubset
- java.lang.Object
-
- org.apache.calcite.rel.AbstractRelNode
-
- org.apache.calcite.plan.volcano.RelSubset
-
- All Implemented Interfaces:
java.lang.Cloneable
,RelOptNode
,RelNode
public class RelSubset extends AbstractRelNode
Subset of an equivalence class where all relational expressions have the same physical properties.Physical properties are instances of the
RelTraitSet
, and consist of traits such as calling convention and collation (sort-order).For some traits, a relational expression can have more than one instance. For example, R can be sorted on both [X] and [Y, Z]. In which case, R would belong to the sub-sets for [X] and [Y, Z]; and also the leading edges [Y] and [].
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
RelSubset.CheapestPlanReplacer
Visitor which walks over a tree ofRelSet
s, replacing each node with the cheapest implementation of the expression.-
Nested classes/interfaces inherited from interface org.apache.calcite.rel.RelNode
RelNode.Context
-
-
Field Summary
Fields Modifier and Type Field Description (package private) RelNode
best
best known plan(package private) RelOptCost
bestCost
cost of best known plan (it may have improved since)(package private) boolean
boosted
Flag indicating whether this RelSubset's importance was artificially boosted.private static org.slf4j.Logger
LOGGER
(package private) RelSet
set
The set this subset belongs to.(package private) long
timestamp
Timestamp for metadata validity-
Fields inherited from class org.apache.calcite.rel.AbstractRelNode
digest, id, rowType, traitSet
-
-
Constructor Summary
Constructors Constructor Description RelSubset(RelOptCluster cluster, RelSet set, RelTraitSet traits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
add(RelNode rel)
Adds expressionrel
to this subset.(package private) RelNode
buildCheapestPlan(VolcanoPlanner planner)
Recursively builds a tree consisting of the cheapest plan at each node.void
collectVariablesSet(java.util.Set<CorrelationId> variableSet)
Collects variables set by this expression.void
collectVariablesUsed(java.util.Set<CorrelationId> variableSet)
Collects variables known to be used by this expression or its descendants.private void
computeBestCost(RelOptPlanner planner)
Computes the bestRelNode
in this subset.protected java.lang.String
computeDigest()
Computes the digest.RelOptCost
computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
Returns the cost of this plan (not including children).RelNode
copy(RelTraitSet traitSet, java.util.List<RelNode> inputs)
Creates a copy of this relational expression, perhaps changing traits and inputs.protected RelDataType
deriveRowType()
double
estimateRowCount(RelMetadataQuery mq)
Returns an estimate of the number of rows this relational expression will return.void
explain(RelWriter pw)
Describes the inputs and attributes of this relational expression.RelNode
getBest()
RelNode
getOriginal()
java.util.Collection<RelNode>
getParentRels()
Returns a list of relational expressions one of whose children is this subset.(package private) java.util.Set<RelNode>
getParents()
Returns the collection of RelNodes one of whose inputs is in this subset.(package private) java.util.Set<RelSubset>
getParentSubsets(VolcanoPlanner planner)
Returns the collection of distinct subsets that contain a RelNode one of whose inputs is in this subset.java.util.List<RelNode>
getRelList()
AsgetRels()
but returns a list.java.lang.Iterable<RelNode>
getRels()
Returns the rel nodes in this rel subset.(package private) RelSet
getSet()
private static java.util.List<RelSubset>
inputSubsets(RelNode parent)
void
propagateBoostRemoval(VolcanoPlanner planner)
(package private) void
propagateCostImprovements(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, java.util.Set<RelSubset> activeSet)
Checks whether a relexp has made its subset cheaper, and if it so, recursively checks whether that subset's parents have gotten cheaper.(package private) void
propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, java.util.Set<RelSubset> activeSet)
-
Methods inherited from class org.apache.calcite.rel.AbstractRelNode
accept, accept, childrenAccept, computeSelfCost, explainTerms, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraitSet, getVariablesSet, getVariablesStopped, isDistinct, isKey, isValid, isValid, metadata, onRegister, recomputeDigest, register, replaceInput, sole, toString
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
bestCost
RelOptCost bestCost
cost of best known plan (it may have improved since)
-
set
final RelSet set
The set this subset belongs to.
-
best
RelNode best
best known plan
-
timestamp
long timestamp
Timestamp for metadata validity
-
boosted
boolean boosted
Flag indicating whether this RelSubset's importance was artificially boosted.
-
-
Constructor Detail
-
RelSubset
RelSubset(RelOptCluster cluster, RelSet set, RelTraitSet traits)
-
-
Method Detail
-
computeBestCost
private void computeBestCost(RelOptPlanner planner)
Computes the bestRelNode
in this subset.Only necessary when a subset is created in a set that has subsets that subsume it. Rationale:
- If the are no subsuming subsets, the subset is initially empty.
- After creation,
best
andbestCost
are maintained incrementally bypropagateCostImprovements0(org.apache.calcite.plan.volcano.VolcanoPlanner, org.apache.calcite.rel.metadata.RelMetadataQuery, org.apache.calcite.rel.RelNode, java.util.Set<org.apache.calcite.plan.volcano.RelSubset>)
andRelSet.mergeWith(VolcanoPlanner, RelSet)
.
-
getBest
public RelNode getBest()
-
getOriginal
public RelNode getOriginal()
-
copy
public RelNode copy(RelTraitSet traitSet, java.util.List<RelNode> inputs)
Description copied from interface:RelNode
Creates a copy of this relational expression, perhaps changing traits and inputs.Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.
- Specified by:
copy
in interfaceRelNode
- Overrides:
copy
in classAbstractRelNode
- Parameters:
traitSet
- Trait setinputs
- Inputs- Returns:
- Copy of this relational expression, substituting traits and inputs
-
computeSelfCost
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
Description copied from interface:RelNode
Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use
RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode)
, which gives plugins a chance to override the rel's default ideas about cost.- Specified by:
computeSelfCost
in interfaceRelNode
- Overrides:
computeSelfCost
in classAbstractRelNode
- Parameters:
planner
- Planner for cost calculationmq
- Metadata query- Returns:
- Cost of this plan (not including children)
-
estimateRowCount
public double estimateRowCount(RelMetadataQuery mq)
Description copied from interface:RelNode
Returns an estimate of the number of rows this relational expression will return.NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use
RelMetadataQuery.getRowCount(org.apache.calcite.rel.RelNode)
, which gives plugins a chance to override the rel's default ideas about row count.- Specified by:
estimateRowCount
in interfaceRelNode
- Overrides:
estimateRowCount
in classAbstractRelNode
- Parameters:
mq
- Metadata query- Returns:
- Estimate of the number of rows this relational expression will return
-
explain
public void explain(RelWriter pw)
Description copied from interface:RelNode
Describes the inputs and attributes of this relational expression. Each node should callsuper.explain
, then call theRelWriterImpl.input(String, RelNode)
andRelWriterImpl.item(String, Object)
methods for each input and attribute.- Specified by:
explain
in interfaceRelNode
- Overrides:
explain
in classAbstractRelNode
- Parameters:
pw
- Plan writer
-
computeDigest
protected java.lang.String computeDigest()
Description copied from class:AbstractRelNode
Computes the digest. Does not modify this object.- Overrides:
computeDigest
in classAbstractRelNode
- Returns:
- Digest
-
deriveRowType
protected RelDataType deriveRowType()
- Overrides:
deriveRowType
in classAbstractRelNode
-
getParents
java.util.Set<RelNode> getParents()
Returns the collection of RelNodes one of whose inputs is in this subset.
-
getParentSubsets
java.util.Set<RelSubset> getParentSubsets(VolcanoPlanner planner)
Returns the collection of distinct subsets that contain a RelNode one of whose inputs is in this subset.
-
getParentRels
public java.util.Collection<RelNode> getParentRels()
Returns a list of relational expressions one of whose children is this subset. The elements of the list are distinct.
-
getSet
RelSet getSet()
-
add
void add(RelNode rel)
Adds expressionrel
to this subset.
-
buildCheapestPlan
RelNode buildCheapestPlan(VolcanoPlanner planner)
Recursively builds a tree consisting of the cheapest plan at each node.
-
propagateCostImprovements
void propagateCostImprovements(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, java.util.Set<RelSubset> activeSet)
Checks whether a relexp has made its subset cheaper, and if it so, recursively checks whether that subset's parents have gotten cheaper.- Parameters:
planner
- Plannermq
- Metadata queryrel
- Relational expression whose cost has improvedactiveSet
- Set of active subsets, for cycle detection
-
propagateCostImprovements0
void propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq, RelNode rel, java.util.Set<RelSubset> activeSet)
-
propagateBoostRemoval
public void propagateBoostRemoval(VolcanoPlanner planner)
-
collectVariablesUsed
public void collectVariablesUsed(java.util.Set<CorrelationId> variableSet)
Description copied from interface:RelNode
Collects variables known to be used by this expression or its descendants. By default, no such information is available and must be derived by analyzing sub-expressions, but some optimizer implementations may insert special expressions which remember such information.- Specified by:
collectVariablesUsed
in interfaceRelNode
- Overrides:
collectVariablesUsed
in classAbstractRelNode
- Parameters:
variableSet
- receives variables used
-
collectVariablesSet
public void collectVariablesSet(java.util.Set<CorrelationId> variableSet)
Description copied from interface:RelNode
Collects variables set by this expression. TODO: is this required?- Specified by:
collectVariablesSet
in interfaceRelNode
- Overrides:
collectVariablesSet
in classAbstractRelNode
- Parameters:
variableSet
- receives variables known to be set by
-
getRels
public java.lang.Iterable<RelNode> getRels()
Returns the rel nodes in this rel subset. All rels must have the same traits and are logically equivalent.- Returns:
- all the rels in the subset
-
-