xuzifu666 commented on code in PR #5392:
URL: https://github.com/apache/calcite/pull/5392#discussion_r4492397794


##########
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##########
@@ -1757,21 +1757,26 @@ private Frame createFrameWithValueGenerator(RelNode 
rel, Frame frame,
    * ensuring that we only map the correlation variable to a local field or
    * expression from the current relational expression (e.g., a {@link 
RexInputRef}),
    * rather than to another correlation variable.
+   *
+   * <p>{@code IS NOT DISTINCT FROM} establishes the same equivalence as
+   * {@code =} (it compares values null-safely), so it is also recognized.
    */
   private static void findCorrelationEquivalent(CorRef correlation, RexNode e)
       throws Util.FoundOne {
     switch (e.getKind()) {
     case EQUALS:
+    case IS_NOT_DISTINCT_FROM:
       final RexCall call = (RexCall) e;
       final List<RexNode> operands = call.getOperands();
-      if (!RexUtil.containsFieldAccess(operands.get(1))
-          && references(operands.get(0), correlation)) {
-        throw new Util.FoundOne(operands.get(1));
-      }
-      if (!RexUtil.containsFieldAccess(operands.get(0))
-          && references(operands.get(1), correlation)) {
-        throw new Util.FoundOne(operands.get(0));
-      }
+      // For IS NOT DISTINCT FROM, binding is only sound when the local
+      // operand is NOT NULL: the residual filter
+      // {@code IS NOT DISTINCT FROM(x, x)} is then always true, and the join

Review Comment:
   Agreed, "residual filter" was undefined. What I meant: after decorrelation, 
the original Filter stays on the inner side of the join with $cor0 substituted 
by its binding, leaving condition IS NOT DISTINCT FROM(x, x) (see the 
LogicalFilter in the test's planAfter). That residual condition is always true, 
so it's harmless; the null-safe semantics are carried by the join condition 
instead which is exactly why the local operand must be NOT NULL, otherwise = 
would drop rows the original condition accepted. I've reworded the comment to 
spell this out.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to