Description
There is an interesting behavior in the construction of PredicateWithValueAndRanges
that prevents simplification from working correctly.
If we have the following two predicates in a query:
P1 = PredicateWithValueAndRanges('False, [Null, Null])
P2 = PredicateWithValueAndRanges('False, ['False, 'False])
That is, the customer created a conjunction of the above predicates and passed it to the SelectExpression
. If these predicates are kept as-is, then the simplification engine will be to recognize that they are constant predicates and simplifies them correctly:
P1 ^ P2
≡ PredicateWithValueAndRanges('False, [Null, Null]) ^ PredicateWithValueAndRanges('False, ['False, 'False])
≡ ConstantPredicate.FALSE ^ PredicateWithValueAndRanges('False, ['False, 'False]) -- ConstantFoldingPredicateWithRangesRule
≡ ConstantPredicate.FALSE ^ ConstantPredicate.FALSE -- ConstantFoldingPredicateWithRangesRule
≡ ConstantPredicate.FALSE -- AnnulmentAndRule
However, in the SelectExpression
construction logic, there is handling of conjunctions that attempt to simplify predicates in a way that makes it easier to match against (filtered) indexes:
That logic creates a new PredicateWithValueAndRanges
that looks like this:
P' = PredicateWithValueAndRanges('False, [Null, Null] AND ['False, 'False])
In other words, it creates a predicate that attempts to match 'False
against a range of two singletons [Null, Null]
, and [False, False]
. Albeit being a clear contradiction, the simplification engine will fail to pattern match it, since it has two ranges not one. And therefore, will not be simplified.