[CALCITE-7711] Add a rule to convert LEFT or RIGHT OUTER JOIN with IS NULL to ANTI JOIN - #5175
[CALCITE-7711] Add a rule to convert LEFT or RIGHT OUTER JOIN with IS NULL to ANTI JOIN#5175zzwqqq wants to merge 2 commits into
Conversation
… NULL to ANTI JOIN
| * | ||
| * <p>is equivalent to | ||
| * | ||
| * <pre>{@code |
There was a problem hiding this comment.
I think having a plan before and after is more useful than having this equivalent SQL.
You can keep the SQL for the original query, though.
There was a problem hiding this comment.
Thanks for reviewing. I've added a plan example.
| } | ||
|
|
||
| /** Returns an {@code IS NULL} condition that identifies a null-generated | ||
| * outer-join row, or null if there is no such condition. */ |
There was a problem hiding this comment.
The condition must be over an input field which is not nullable in the input.
That is implied by the JavaDoc, but is subtle, it deserves to be in the JavaDoc.
You can say rightField IS NULL where rightField is a non-nullable column from the right input (for a left join).
There was a problem hiding this comment.
Thanks. I've updated the Javadoc to describe the requirement.
xiedeyantu
left a comment
There was a problem hiding this comment.
Since Mihai has already reviewed it, I only raised a few minor issues.
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Tests for {@link OuterJoinToAntiJoinRule}. */ | ||
| class OuterJoinToAntiJoinRuleTest { |
There was a problem hiding this comment.
We can add JIRA title in the java doc.
There was a problem hiding this comment.
Thanks. I've added the title.
| !ok | ||
| !set planner-rules original | ||
|
|
||
| # OuterJoinToAntiJoinRule converts the null-generating side's IS NULL filter. |
There was a problem hiding this comment.
JIRA title also should be added here.
There was a problem hiding this comment.
Thanks. I've added the title here too.
| join.getCluster().getRexBuilder()); | ||
| final RelTraitSet traitSet = join.getTraitSet(); | ||
| final Join antiJoin = | ||
| join.copy(traitSet, condition, newLeft, newRight, |
There was a problem hiding this comment.
Would it be better to switch to RelBuilder.join?
There was a problem hiding this comment.
Thanks. Changed the rule to use RelBuilder.join and retain the original join hints. Correlated RIGHT joins are left unchanged because swapping the inputs would require remapping correlation references.
|
|
@xiedeyantu please approve if you are happy |
|
next step: squashing |



Jira Link
CALCITE-7711
Changes Proposed
Add an optional rule for LEFT and RIGHT joins. The rule should match a top-level IS NULL conjunct on the null-generating input. The conversion is safe when the underlying input field is non-nullable, or when the join condition cannot be TRUE while that field is nullable. Other filter conjuncts and the original row type should be preserved.
Representing the operation as an ANTI join allows subsequent rules to produce physical anti joins and the planner to cost those alternatives.