silundong commented on code in PR #4743:
URL: https://github.com/apache/calcite/pull/4743#discussion_r2686930882


##########
core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java:
##########
@@ -696,11 +698,13 @@ public RelNode unnestInternal(Join join, boolean 
allowEmptyOutputFromRewrite) {
       pushDownToLeft = true;
       leftInfo = requireNonNull(mapRelToUnnestedQuery.get(join.getLeft()));
     }
-    if (!rightHasCorrelation && !join.getJoinType().generatesNullsOnLeft()) {
+    if (!rightHasCorrelation && !join.getJoinType().generatesNullsOnLeft()
+        && pushDownToLeft) {

Review Comment:
   When `!rightHasCorrelation && !join.getJoinType().generatesNullsOnLeft()` is 
TRUE, D will necessarily be pushed down to the left, so `pushDownToLeft` must 
be TRUE. Maybe it's clearer to `assert pushDownToLeft` rather than include it 
in `if`, what do you think?



##########
core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java:
##########
@@ -680,11 +680,13 @@ public RelNode unnestInternal(Join join, boolean 
allowEmptyOutputFromRewrite) {
     UnnestedQuery rightInfo;
 
     if (!leftHasCorrelation && !join.getJoinType().generatesNullsOnRight()
-        && join.getJoinType().projectsRight()) {
+        && join.getJoinType().projectsRight()
+        && rightHasCorrelation) {
       // there is no need to push down domain D to left side when both 
following conditions

Review Comment:
   Maybe change 'both' to 'all', and the comment below as well.



##########
core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java:
##########
@@ -680,11 +680,13 @@ public RelNode unnestInternal(Join join, boolean 
allowEmptyOutputFromRewrite) {
     UnnestedQuery rightInfo;
 
     if (!leftHasCorrelation && !join.getJoinType().generatesNullsOnRight()
-        && join.getJoinType().projectsRight()) {
+        && join.getJoinType().projectsRight()
+        && rightHasCorrelation) {

Review Comment:
   Could you please add a comment in the `else` branch stating that when 
neither the left nor the right side has correlation, but the join condition has 
correlation, D is pushed down to the left by default.



-- 
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