Class ValueComparisonRangePredicate.Sargable
- java.lang.Object
-
- com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate
-
- com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Sargable
-
- All Implemented Interfaces:
PlanHashable
,Bindable
,Correlated<QueryPredicate>
,PredicateWithValue
,QueryPredicate
- Enclosing class:
- ValueComparisonRangePredicate
public static class ValueComparisonRangePredicate.Sargable extends ValueComparisonRangePredicate
A query predicate that can be used as a (s)earch (arg)ument for an index scan.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate
ValueComparisonRangePredicate.Placeholder, ValueComparisonRangePredicate.Sargable
-
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.PlanHashable
PlanHashable.PlanHashKind
-
-
Constructor Summary
Constructors Constructor Description Sargable(Value value, ComparisonRange comparisonRange)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <M extends Message>
Booleaneval(FDBRecordStoreBase<M> store, EvaluationContext context, FDBRecord<M> record, M message)
ComparisonRange
getComparisonRange()
Optional<PredicateMultiMap.PredicateMapping>
impliesCandidatePredicate(@NonNull AliasMap aliasMap, QueryPredicate candidatePredicate)
Determines if this predicate implies some other predicate.int
planHash(PlanHashable.PlanHashKind hashKind)
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.ValueComparisonRangePredicate.Sargable
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.List<QueryPredicate>
toResiduals()
String
toString()
-
Methods inherited from class com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate
bindTo, equals, getCorrelatedTo, getValue, hashCode, placeholder, sargable
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.PlanHashable
planHash
-
Methods inherited from interface com.apple.foundationdb.record.query.predicates.QueryPredicate
findImpliedMappings, isTautology
-
-
-
-
Constructor Detail
-
Sargable
public Sargable(@Nonnull Value value, @Nonnull ComparisonRange comparisonRange)
-
-
Method Detail
-
getComparisonRange
@Nonnull public ComparisonRange getComparisonRange()
-
eval
@Nullable public <M extends Message> Boolean eval(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable FDBRecord<M> record, @Nullable M message)
-
semanticEquals
public boolean semanticEquals(@Nullable Object other, @Nonnull AliasMap aliasMap)
Description copied from interface:Correlated
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()
- Specified by:
semanticEquals
in interfaceCorrelated<QueryPredicate>
- Overrides:
semanticEquals
in classValueComparisonRangePredicate
- 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
-
rebase
@Nonnull public ValueComparisonRangePredicate.Sargable 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.- 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
-
semanticHashCode
public int semanticHashCode()
Description copied from interface:Correlated
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()
Correlated.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.- Specified by:
semanticHashCode
in interfaceCorrelated<QueryPredicate>
- Overrides:
semanticHashCode
in classValueComparisonRangePredicate
- Returns:
- the semantic hash code
-
planHash
public int planHash(@Nonnull PlanHashable.PlanHashKind hashKind)
Description copied from interface:PlanHashable
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.- Specified by:
planHash
in interfacePlanHashable
- Overrides:
planHash
in classValueComparisonRangePredicate
- Parameters:
hashKind
- the "kind" of hash to calculate. Each kind of hash has a particular logic with regards to included and excluded items.- Returns:
- a stable hash code
-
impliesCandidatePredicate
@Nonnull public Optional<PredicateMultiMap.PredicateMapping> impliesCandidatePredicate(@NonNull AliasMap aliasMap, @Nonnull QueryPredicate candidatePredicate)
Description copied from interface:QueryPredicate
Determines if this predicate implies some other predicate. Let's say thatEVAL(p)
denotes the outcome of the evaluation of a predicate. A predicatep1
implies some other predicatep2
if(EVAL(p1, recordBindings) == true) -> (EVAL(p2, recordBindings) == true)
recordBindings
possibly contained in a stream of records that are potentially being flowed at execution time. Ifp1
impliesp2
, this method returns an instance of classPredicateMultiMap.PredicateMapping
which should give the caller all necessary info to changep2
toCOMP(p2)
in a way make the opposite also true:(EVAL(p1, recordBindings) == true) <-> (EVAL(COMP(p2), recordBindings) == true)
ValueComparisonRangePredicate.Sargable
) on the query side.Examples:
Example 1
p1: x = 5 p2: true (tautology predicate) result: optional of PredicateMapping(COMP(true) => x = 5)
p1
impliesp2
but, i.e.,x = 5
impliestrue
but in order fortrue
to implyx = 5
, the compensation has to be applied such thatCOMP(p2)
becomestrue ^ x = 5
.Example 2
p1: x = 5 p2: x COMPARISONRANGE (placeholder) result: optional of PredicateMapping(COMP(x COMPARISONRANGE) => x = 5, binding b to indicate COMPARISONRANGE should be [5, 5])
p1
impliesp2
but, i.e.,x = 5
impliesx COMPARISONRANGE
but only ifCOMPARISONRANGE
is bound to[5, 5]
but in order forx COMPARISONRANGE
to implyx = 5
, the compensation has to be applied such thatCOMP(p2)
becomesx = 5
.Example 3
p1: x = 5 p2: y COMPARISONRANGE (placeholder) result: Optional.empty()
p1
does not implyp2
, i.e.,x = 5
does not implyy COMPARISONRANGE
.- Parameters:
aliasMap
- the current alias mapcandidatePredicate
- another predicate (usually in a match candidate)- Returns:
Optional(predicateMapping)
ifthis
impliescandidatePredicate
wherepredicateMapping
is an new instance ofPredicateMultiMap.PredicateMapping
that captures potential bindings and compensation forcandidatePredicate
such thatcandidatePredicate
to also implythis
,Optional.empty()
otherwise
-
toResiduals
public List<QueryPredicate> toResiduals()
-
-