Class ValueComparisonRangePredicate.Sargable

    • Method Detail

      • semanticEquals

        public boolean semanticEquals​(@Nullable
                                      Object other,
                                      @Nonnull
                                      AliasMap aliasMap)
        Description copied from interface: Correlated
        Determine equality with respect to an equivalence map between CorrelationIdentifiers based on semantic equality: equality of the plan fragments implementing under the given correlation bindings. The contract of this variant of equals() 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 instance q1.x = 5 uses a correlation to q1. That entity representing the filter is said to be correlated to q1. 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 as q2.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 to SELECT * FROM T as q2 WHERE q2.x = 5. It does not matter that q1 and q2 are named differently. It is important, however, that their semantic meaning is the same. In the example both q1 and q2 refer to a record type T 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 between q1.x = 5 and q2.x = 5 if we know that q1 and q2 refer to the same underlying entity. The equivalence map passed in encodes that equality between CorrelationIdentifiers. Note: This method has the same interaction with Object.hashCode() as the regular equals() 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 interface Correlated<QueryPredicate>
        Overrides:
        semanticEquals in class ValueComparisonRangePredicate
        Parameters:
        other - the other object to establish equality with
        aliasMap - a map of CorrelationIdentifiers ids to ids'. A correlation identifier id used in this should be considered equal to another correlation identifier id' used in other if either they are the same by Object.equals(java.lang.Object) of if there is a mapping from id to id'.
        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 from CorrelationIdentifiers ids to CorrelationIdentifiers ids'. After the rebase, every correlation to an id contained ids that is contained or referred to directly or indirectly by this must have been transformed to use the mapped counterpart of id id' in ids'. IDs not contained in the translation map must remain unmodified by the rebase operation.
        Returns:
        a new entity that has been rebased
      • planHash

        public int planHash​(@Nonnull
                            PlanHashable.PlanHashKind hashKind)
        Description copied from interface: PlanHashable
        Return a hash similar to hashCode, but with the additional guarantee that is is stable across JVMs.
        Specified by:
        planHash in interface PlanHashable
        Overrides:
        planHash in class ValueComparisonRangePredicate
        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 that EVAL(p) denotes the outcome of the evaluation of a predicate. A predicate p1 implies some other predicate p2 if
             
             (EVAL(p1, recordBindings) == true) -> (EVAL(p2, recordBindings) == true)
             
         
        for all recordBindings possibly contained in a stream of records that are potentially being flowed at execution time. If p1 implies p2, this method returns an instance of class PredicateMultiMap.PredicateMapping which should give the caller all necessary info to change p2 to COMP(p2) in a way make the opposite also true:
             
             (EVAL(p1, recordBindings) == true) <-> (EVAL(COMP(p2), recordBindings) == true)
             
         
        Note that this method takes special care when placeholders are involved as this method is called during index matching with candidates graphs. A placeholder by itself cannot be executed. In order for the place holder to match it has to partake in a relationship with a query predicate that tells the placeholder the specific comparison and bounds it operates over. In some sends this expresses a kind of polymorphism of the placeholder that is bound to a specific predicate only in the presence of a sargable predicate (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 implies p2 but, i.e., x = 5 implies true but in order for true to
             imply x = 5, the compensation has to be applied such that COMP(p2) becomes true ^ 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 implies p2 but, i.e., x = 5 implies x COMPARISONRANGE but only if
             COMPARISONRANGE is bound to [5, 5] but in order for x COMPARISONRANGE to
             imply x = 5, the compensation has to be applied such that COMP(p2) becomes x = 5.
         

        Example 3

             
             p1: x = 5
             p2: y COMPARISONRANGE (placeholder)
        
             result: Optional.empty()
             
             p1 does not imply p2, i.e., x = 5 does not imply y COMPARISONRANGE.
         
        Note: This method is expected to return a meaningful non-empty result if called with a candidate predicate that also represents a tautology.
        Parameters:
        aliasMap - the current alias map
        candidatePredicate - another predicate (usually in a match candidate)
        Returns:
        Optional(predicateMapping) if this implies candidatePredicate where predicateMapping is an new instance of PredicateMultiMap.PredicateMapping that captures potential bindings and compensation for candidatePredicate such that candidatePredicate to also imply this, Optional.empty() otherwise