Class ReplaceJoinOverConstantWithProject

  • All Implemented Interfaces:
    Rule<JoinNode>

    public class ReplaceJoinOverConstantWithProject
    extends Object
    implements Rule<JoinNode>
    This rule transforms plans with join where one of the sources is a single-row ValuesNode, and the join condition is `on true`. The JoinNode is replaced with the other join source and a projection which appends constant values from the ValuesNode. This rule is similar to ReplaceRedundantJoinWithSource.

    Note 1: When transforming an outer join (LEFT, RIGHT or FULL), and an outer source is a single row ValuesNode, it is checked that the other source is not empty. If it is possibly empty, the transformation cannot be done, because the result of the transformation would be possibly empty, while the single constant row should be preserved on output.

    Note 2: The transformation is valid when the ValuesNode contains non-deterministic expressions. This is because any expression from the ValuesNode can only be used once. Assignments.Builder deduplicates them in case when the JoinNode produces any of the input symbols more than once.

    Note 3: The transformation is valid when the ValuesNode contains expressions using correlation symbols. They are constant from the perspective of the transformed plan.

    Transforms:

     - join (on true), layout: (a, b, c)
        - source (a)
        - values
          b <- expr1
          c <- expr2
     
    into:
     - project (a <- a, b <- expr1, c <- expr2)
         - source (a)