Class InlineProjectIntoFilter

  • All Implemented Interfaces:
    Rule<FilterNode>

    public class InlineProjectIntoFilter
    extends Object
    implements Rule<FilterNode>
    Replace filter predicate conjuncts with underlying project expressions.

    Transforms:

     - Filter (a AND b > c)
         - Project
           a <- d IS NULL
           b <- b
           c <- c
             - source (b, c, d)
     
    into:
     - Project
       a <- TRUE
       b <- b
       c <- c
         - Filter (d IS NULL AND b > c)
             - Project
               b <- b
               c <- c
               d <- d
             - source (b, c, d)
     
    In the preceding example, filter predicate conjunct `a` is replaced with project expression `d IS NULL`. Additionally: - an identity assignment `d <- d` is added to the underlying projection in order to expose the symbol `d` used by the rewritten filter predicate, - the inlined assignment `a <- d IS NULL` is removed from the underlying projection. - another projection is added above the rewritten FilterNode, assigning TRUE_LITERAL to the replaced symbol `a`. It is needed to restore the original output of the FilterNode. If the symbol `a` is not referenced in the upstream plan, the projection should be subsequently removed by other rules.

    Note: project expressions are inlined only in case when the resulting symbols are referenced exactly once in the filter predicate. Otherwise, the resulting plan could be less efficient due to duplicated computation. Also, inlining the expression multiple times is not correct in case of non-deterministic expressions.