fdb-record-layer icon indicating copy to clipboard operation
fdb-record-layer copied to clipboard

Unify boolean predicates and ranged predicate representation

Open hatyo opened this issue 2 years ago • 0 comments

With #1972 a new ValueWithRanges is introduced to represent a Value with a disjunction of continuous ranges to support filtered indexes and improve optimisation opportunities around them for cases where a query predicate range can be calculated at compile time and checked against a filtered index predicate range for implication (inclusion). It is also used to improve optimisation OrPredicate matching for cases where the or-legs on both sides are compile-time evaluable.

This representation, albeit being very useful, created yet another modelling of the same boolean expression (OrPredicate and ValueWithRanges, also AndPredicate and ValueWithRanges where ranges.size() == 1, i.e. a sargable). This makes it difficult to work with boolean expression optimisations as we have now to deal with two representations instead of one.

One example of this is OrToLogicalUnionRule which has now to match, in addition to OrPredicate, ValueWithRanges.

Instead of going down that route as it increases code complexity we can actually move both representation under a single interface since, both, are semantically equivalent. And when implementing an optimisation rule such as OrToLogicalUnionRule we pattern match against that common interface. In other words, we should treat both OrPredicate/ValueWithRanges as implementation details or a more abstract OrBooleanExpression interface (same applies for AndPredicate/ValueWithRanges where ranges.size() == 1.

hatyo avatar Feb 15 '23 19:02 hatyo