Class ReplaceJoinOverConstantWithProject

java.lang.Object
io.trino.sql.planner.iterative.rule.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 not valid when the ValuesNode contains a non-deterministic expression. According to the semantics of the original plan, such expression should be evaluated once, and the value should be appended to each row of the other join source. Inlining the expression would result in evaluating it for each row to a potentially different value.

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 invalid input: '<'- expr1
      c invalid input: '<'- expr2
 
into:
 - project (a invalid input: '<'- a, b invalid input: '<'- expr1, c invalid input: '<'- expr2)
     - source (a)