Interface Correlated<S extends Correlated<S>>
-
- Type Parameters:
S
- self type of this. Needed for rebasing to a proper constrained at-least type
- All Known Subinterfaces:
ExpressionRef<T>
,PredicateWithValue
,QueryPlan<T>
,QueryPredicate
,RecordQueryPlan
,RecordQueryPlanWithChild
,RecordQueryPlanWithChildren
,RecordQueryPlanWithComparisons
,RecordQueryPlanWithIndex
,RecordQueryPlanWithNoChildren
,RecordQueryPlanWithRequiredFields
,RelationalExpression
,RelationalExpressionWithChildren
,RelationalExpressionWithPredicate
,TypeFilterExpression
,Value
- All Known Implementing Classes:
AndOrPredicate
,AndPredicate
,BaseValue
,ComposedBitmapIndexQueryPlan
,ConstantPredicate
,ExistsPredicate
,ExplodeExpression
,FieldValue
,FullUnorderedScanExpression
,GroupExpressionRef
,IndexScanExpression
,LiteralValue
,LogicalDistinctExpression
,LogicalFilterExpression
,LogicalIntersectionExpression
,LogicalSortExpression
,LogicalTypeFilterExpression
,LogicalUnorderedUnionExpression
,MatchableSortExpression
,NotPredicate
,OrPredicate
,PrimaryScanExpression
,QuantifiedColumnValue
,QuantifiedObjectValue
,Quantifier
,Quantifier.Existential
,Quantifier.ForEach
,Quantifier.Physical
,QueryComponentPredicate
,RecordQueryCoveringIndexPlan
,RecordQueryFetchFromPartialRecordPlan
,RecordQueryFilterPlan
,RecordQueryIndexPlan
,RecordQueryInJoinPlan
,RecordQueryInParameterJoinPlan
,RecordQueryIntersectionPlan
,RecordQueryInValuesJoinPlan
,RecordQueryLoadByKeysPlan
,RecordQueryPredicateFilterPlan
,RecordQueryScanPlan
,RecordQueryScoreForRankPlan
,RecordQueryTextIndexPlan
,RecordQueryTypeFilterPlan
,RecordQueryUnionPlan
,RecordQueryUnionPlanBase
,RecordQueryUnorderedDistinctPlan
,RecordQueryUnorderedPrimaryKeyDistinctPlan
,RecordQueryUnorderedUnionPlan
,RecordTypeValue
,SelectExpression
,ValueComparisonRangePredicate
,ValueComparisonRangePredicate.Placeholder
,ValueComparisonRangePredicate.Sargable
,ValuePredicate
,VersionValue
@API(EXPERIMENTAL) public interface Correlated<S extends Correlated<S>>
A correlated entity is one which can only be evaluated as a function of some input (usually aQuantifier
from its relational parent). Since a correlated entity can have multiple correlations to similar quantifiers, a correlation is disambiguated by aCorrelationIdentifier
. Correlated entities are said to be correlated to a quantifierq
if the identifiers returned bygetCorrelatedTo()
set contain the correlation identifier thatq
uses. Distinguishing the correlation identifier from the identity of the quantifier object simplifies modifications of the graph, for example while applying transformations during query planning. An correlated object can be rebased usingrebase(com.apple.foundationdb.record.query.plan.temp.AliasMap)
and a map of translations from one correlation identifier to another, resulting in a new object of typeS
that is identical tothis
except that all correlated references in the subtree rooted at this entity (i.e., this object's relational children, predicates, etc.) are replaced with their corresponding identifiers per the map. Since translations are associative we allow to rebase many identifiers in the samerebase(com.apple.foundationdb.record.query.plan.temp.AliasMap)
invocation. As the planner DAG objects are immutable, a rebase operation can be expensive as objects have to be recreated as needed. We follow the ideas of other persistent data structures as we do not require a copy to be made. It is perfectly acceptable to returnthis
ifthis
is not correlated to any identifier participating in the translation. This interface defines asemanticEquals(java.lang.Object, com.apple.foundationdb.record.query.plan.temp.AliasMap)
method that also takes an equivalence map, and determines equality up to the equivalences defined therein. Two correlated entities are equivalent even if they use different names, as long as un-bound correlations can be aligned. For example, in:SELECT * FROM T1 a, T2 b WHERE a.x = b.y UNION (SELECT * FROM T1 c, T2 d WHERE c.x = d.y)
semanticEquals(java.lang.Object, com.apple.foundationdb.record.query.plan.temp.AliasMap)
introduced here considers these blocks equal using a bi-map that allows for the definition of equivalences among correlation identifiers. In this case(SELECT * FROM T1 a, T2 b WHERE a.x = b.y).equals(SELECT * FROM T1 c, T2 d WHERE c.x = d.y, ImmutableBiMap.of())
(WHERE a.x = b.y).equals(WHERE c.x = d.y, ImmutableBiMap.of(a -> b, c -> d))
true
asa
is considered to be equal toc
andb
is considered to be equal tod
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Correlated.BoundEquivalence
Helper class to wrap extenders ofCorrelated
to provide standard equivalence and hash code functionality under a givenAliasMap
.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Set<CorrelationIdentifier>
getCorrelatedTo()
Returns the set ofCorrelationIdentifier
s this entity is correlated to.S
rebase(AliasMap translationMap)
Rebases this and all other objects this objects is composed of using a given translation map.boolean
semanticEquals(Object other, AliasMap aliasMap)
Determine equality with respect to an equivalence map betweenCorrelationIdentifier
s based on semantic equality: equality of the plan fragments implementing under the given correlation bindings.int
semanticHashCode()
Return a semantic hash code for this object.
-
-
-
Method Detail
-
getCorrelatedTo
@Nonnull Set<CorrelationIdentifier> getCorrelatedTo()
Returns the set ofCorrelationIdentifier
s this entity is correlated to. This means that without a process that binds these correlations to values, theRelationalExpression
(or others that implement this interface) cannot even in principle produce a meaningful result. As often times entities that implement this interface use composition and effectively describe trees or DAGs, this method should be the set union of theCorrelationIdentifier
s this object is correlated to as well as all children, constituent parts, etc.- Returns:
- the set of
CorrelationIdentifier
s this entity is correlated to
-
rebase
@Nonnull S rebase(@Nonnull AliasMap translationMap)
Rebases this and all other objects this objects is composed of using a given translation map.- 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
-
semanticEquals
boolean semanticEquals(@Nullable Object other, @Nonnull AliasMap aliasMap)
Determine equality with respect to an equivalence map betweenCorrelationIdentifier
s based on semantic equality: equality of the plan fragments implementing under the given correlation bindings. The contract of this variant ofequals()
differs from its regular Java counterpart. A correlation is mostly just one part inside of composition of objects that expresses a more complicated (correlated) structure such as a filter. For instanceq1.x = 5
uses a correlation toq1
. That entity representing the filter is said to be correlated toq1
. Similarly,q1.x = 6
is a different filter and is not equal under any correlation mapping. In contrast, consider a predicate where everything except the correlation is the same, such asq2.x = 5
. Without a binding, these two filters are not the same. However, the filters may be a part of some other entity that can express correlations:SELECT * FROM T as q1 WHERE q1.x = 5
is equal toSELECT * FROM T as q2 WHERE q2.x = 5
. It does not matter thatq1
andq2
are named differently. It is important, however, that their semantic meaning is the same. In the example bothq1
andq2
refer to a record typeT
which presumably is the same record type. Therefore, these two query blocks are the same, even though they are labelled differently. In the context of this method, we can establish equality betweenq1.x = 5
andq2.x = 5
if we know thatq1
andq2
refer to the same underlying entity. The equivalence map passed in encodes that equality betweenCorrelationIdentifier
s. Note: This method has the same interaction withObject.hashCode()
as the regularequals()
method. As we can only ever establish true equality using equivalence maps,hashCode()
implementations in implementors of this interface must not be dependent on any correlation identifiers used in the structure of the entity. Doing so might violate the fundamental property of hash codes:e1.equals(e2, ...) => e1.hashCode() == e2.hashCode()
- Parameters:
other
- the other object to establish equality withaliasMap
- a map ofCorrelationIdentifier
sids
toids'
. A correlation identifierid
used inthis
should be considered equal to another correlation identifierid'
used inother
if either they are the same byObject.equals(java.lang.Object)
of if there is a mapping fromid
toid'
.- Returns:
true
if both entities are considered equal using the equivalences passed in,false
otherwise
-
semanticHashCode
int semanticHashCode()
Return a semantic hash code for this object. The hash code must obey the convention that for any two objectso1
ando2
and for everyAliasMap
aliasMap
:o1.semanticEquals(o1, aliasMap)
followso1.semanticHash() == o2.semanticHash()
semanticEquals(java.lang.Object, com.apple.foundationdb.record.query.plan.temp.AliasMap)
returnstrue
for these two objects the plan fragments are considered to produce the same result under the given correlations bindings. The left sideo1.semanticEquals(o1, aliasMap)
depends on anAliasMap
whileo1.semanticHash() == o2.semanticHash()
does not. Hence, the hash that is computed is identical regardless of possible bindings.- Returns:
- the semantic hash code
-
-