Class SelectExpression
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression
-
- All Implemented Interfaces:
Bindable
,Correlated<RelationalExpression>
,InternalPlannerGraphRewritable
,RelationalExpressionWithChildren
,RelationalExpression
,RelationalExpressionWithPredicate
@API(EXPERIMENTAL) public class SelectExpression extends Object implements RelationalExpressionWithChildren, RelationalExpressionWithPredicate, InternalPlannerGraphRewritable
A select expression.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.query.plan.temp.Correlated
Correlated.BoundEquivalence
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.query.plan.temp.RelationalExpression
RelationalExpression.CombineFunction<R,S>, RelationalExpression.CombinePredicate
-
-
Constructor Summary
Constructors Constructor Description SelectExpression(List<? extends Value> resultValues, List<? extends Quantifier> children, List<QueryPredicate> predicates)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canCorrelate()
Returns if this expression can be the anchor of a correlation.Compensation
compensate(PartialMatch partialMatch, Map<CorrelationIdentifier,ComparisonRange> boundParameterPrefixMap)
boolean
equals(Object other)
boolean
equalsWithoutChildren(RelationalExpression otherExpression, AliasMap equivalencesMap)
Set<CorrelationIdentifier>
getCorrelatedToWithoutChildren()
QueryPredicate
getPredicate()
List<QueryPredicate>
getPredicates()
List<? extends Quantifier>
getQuantifiers()
Return an iterator of references to the children of this planner expression.int
getRelationalChildCount()
Optional<List<? extends Value>>
getResultValues()
int
hashCode()
int
hashCodeWithoutChildren()
SelectExpression
rebase(AliasMap translationMap)
Rebases this and all other objects this objects is composed of using a given translation map.SelectExpression
rebaseWithRebasedQuantifiers(AliasMap translationMap, List<Quantifier> rebasedQuantifiers)
PlannerGraph
rewriteInternalPlannerGraph(List<? extends PlannerGraph> childGraphs)
Method to rewrite the planner graph.Iterable<MatchInfo>
subsumedBy(RelationalExpression candidateExpression, AliasMap aliasMap, IdentityBiMap<Quantifier,PartialMatch> partialMatchMap)
Try to establish ifotherExpression
subsumes this one.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.query.plan.temp.RelationalExpression
acceptPropertyVisitor, adjustMatch, bindIdentities, bindTo, enumerateUnboundCorrelatedTo, exactlySubsumedBy, findMatches, hasIncompatibleBoundQuantifiers, hasUnboundQuantifiers, match, match, semanticEquals, semanticEquals, semanticHashCode, show
-
Methods inherited from interface com.apple.foundationdb.record.query.plan.temp.expressions.RelationalExpressionWithChildren
getCorrelatedTo
-
-
-
-
Constructor Detail
-
SelectExpression
public SelectExpression(@Nonnull List<? extends Value> resultValues, @Nonnull List<? extends Quantifier> children, @Nonnull List<QueryPredicate> predicates)
-
-
Method Detail
-
getResultValues
@Nonnull public Optional<List<? extends Value>> getResultValues()
- Specified by:
getResultValues
in interfaceRelationalExpression
-
getQuantifiers
@Nonnull public List<? extends Quantifier> getQuantifiers()
Description copied from interface:RelationalExpression
Return an iterator of references to the children of this planner expression. The iterators returned by different calls are guaranteed to be independent (i.e., advancing one will not advance another). However, they might point to the same object, as whenCollections.emptyIterator()
is returned. The returned iterator should be treated as an immutable object and may throw an exception ifIterator.remove()
is called. The iterator must return its elements in a consistent order.- Specified by:
getQuantifiers
in interfaceRelationalExpression
- Returns:
- an iterator of references to the children of this planner expression
-
getRelationalChildCount
public int getRelationalChildCount()
- Specified by:
getRelationalChildCount
in interfaceRelationalExpressionWithChildren
-
getPredicate
@Nonnull public QueryPredicate getPredicate()
- Specified by:
getPredicate
in interfaceRelationalExpressionWithPredicate
-
getPredicates
@Nonnull public List<QueryPredicate> getPredicates()
-
canCorrelate
public boolean canCorrelate()
Description copied from interface:RelationalExpression
Returns if this expression can be the anchor of a correlation. A correlation is always formed between three entities:- the
Quantifier
that flows data - 2. the anchor (which is a
RelationalExpression
) that ranges directly over the source - 3. the consumers (or dependents) of the correlation which must be a descendant of the anchor.
LogicalUnorderedUnionExpression
cannot correlate (this method returnsfalse
) because it is not meaningful to bind a record from one child of the union while providing bound values to another. In another example, a logical select expression can correlate which means that one child of the SELECT expression can be evaluated and the resulting records can bound individually one after another. For each bound record flowing along that quantifier the other children of the SELECT expression can be evaluated, potentially causing more correlation values to be bound, etc. These concepts follow closely to the mechanics of what SQL calls a query block. The existence of a correlation between source, anchor, and dependents may adversely affect planning because a correlation always imposes order between the evaluated of children of an expression. This may or may not tie the hands of the planner to produce an optimal plan. In certain cases, queries written in a correlated way can be de-correlated to allow for better optimization techniques.- Specified by:
canCorrelate
in interfaceRelationalExpression
- Returns:
true
if this expression can be the anchor of a correlation,false
otherwise.
- the
-
getCorrelatedToWithoutChildren
@Nonnull public Set<CorrelationIdentifier> getCorrelatedToWithoutChildren()
- Specified by:
getCorrelatedToWithoutChildren
in interfaceRelationalExpressionWithChildren
-
rebase
@Nonnull public SelectExpression rebase(@Nonnull AliasMap translationMap)
Description copied from interface:Correlated
Rebases this and all other objects this objects is composed of using a given translation map.- Specified by:
rebase
in interfaceCorrelated<RelationalExpression>
- Specified by:
rebase
in interfaceRelationalExpressionWithChildren
- Parameters:
translationMap
- a map defining a translation fromCorrelationIdentifier
sids
toCorrelationIdentifier
sids'
. After the rebase, every correlation to anid
containedids
that is contained or referred to directly or indirectly bythis
must have been transformed to use the mapped counterpart ofid
id'
inids'
. IDs not contained in the translation map must remain unmodified by the rebase operation.- Returns:
- a new entity that has been rebased
-
rebaseWithRebasedQuantifiers
@Nonnull public SelectExpression rebaseWithRebasedQuantifiers(@Nonnull AliasMap translationMap, @Nonnull List<Quantifier> rebasedQuantifiers)
- Specified by:
rebaseWithRebasedQuantifiers
in interfaceRelationalExpressionWithChildren
- Specified by:
rebaseWithRebasedQuantifiers
in interfaceRelationalExpressionWithPredicate
-
equalsWithoutChildren
public boolean equalsWithoutChildren(@Nonnull RelationalExpression otherExpression, @Nonnull AliasMap equivalencesMap)
- Specified by:
equalsWithoutChildren
in interfaceRelationalExpression
-
hashCodeWithoutChildren
public int hashCodeWithoutChildren()
- Specified by:
hashCodeWithoutChildren
in interfaceRelationalExpression
-
subsumedBy
@Nonnull public Iterable<MatchInfo> subsumedBy(@Nonnull RelationalExpression candidateExpression, @Nonnull AliasMap aliasMap, @Nonnull IdentityBiMap<Quantifier,PartialMatch> partialMatchMap)
Description copied from interface:RelationalExpression
Try to establish ifotherExpression
subsumes this one. If two expression are semantically equal (e.g. in structure or by other means of reasoning) they should exactly return the same records. There are use cases where semantic equality is too strict and not that useful. During index matching we don't necessarily need to know if two expressions produce the same result, we just need to know that the candidate scan produces a (non-proper) super multiset of records (the candidate therefore includes all records warranted by the query) and we can match query against that candidate. The difference between result set produced by the candidate and the query then must be corrected by applying compensation. The following tautologies apply:- If query and candidate are semantically equivalent, the query side should match to the candidate side without any compensation. In other words the query expression can simply be replaced by the candidate expression.
- If the candidate is matched and we decide to rewrite this query expression with the appropriate top expression on the candidate side then it holds that the query expression is equivalent to the computed compensation of the match over the candidate scan.
- A query cannot match to a candidate if it cannot be proven that the candidate cannot at least produce all the records that the query may produce.
- Specified by:
subsumedBy
in interfaceRelationalExpression
- Parameters:
candidateExpression
- the candidate expressionaliasMap
- a map of alias defining the equivalence between aliases and therefore quantifierspartialMatchMap
- a map from quantifier to aPartialMatch
that pulled up along that quantifier from one of the expressions below that quantifier- Returns:
- an iterable of
MatchInfo
s if subsumption between this expression and the candidate expression can be established
-
rewriteInternalPlannerGraph
@Nonnull public PlannerGraph rewriteInternalPlannerGraph(@Nonnull List<? extends PlannerGraph> childGraphs)
Description copied from interface:InternalPlannerGraphRewritable
Method to rewrite the planner graph.- Specified by:
rewriteInternalPlannerGraph
in interfaceInternalPlannerGraphRewritable
- Parameters:
childGraphs
- planner graphs of children expression that already have been computed- Returns:
- a new planner graph that can combine the
childGraph
s in a meaningful way. Note that there is no obligation to use thechildGraph
s at all, this method can create a new independent planner graph completely from scratch.
-
compensate
public Compensation compensate(@Nonnull PartialMatch partialMatch, @Nonnull Map<CorrelationIdentifier,ComparisonRange> boundParameterPrefixMap)
- Specified by:
compensate
in interfaceRelationalExpression
-
-