imay commented on a change in pull request #246: Colocate Join (#245)
URL: https://github.com/apache/incubator-doris/pull/246#discussion_r231440902
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/planner/DistributedPlanner.java
 ##########
 @@ -395,6 +414,81 @@ private PlanFragment createHashJoinFragment(HashJoinNode 
node, PlanFragment righ
         }
     }
 
+    private boolean canColocateJoin(HashJoinNode node, PlanFragment 
leftChildFragment, PlanFragment rightChildFragment) {
+        if (ConnectContext.get().getSessionVariable().isDisableColocateJoin()) 
{
+            return false;
+        }
+
+        PlanNode leftRoot = leftChildFragment.getPlanRoot();
+        PlanNode rightRoot = rightChildFragment.getPlanRoot();
+
+        //leftRoot could be ScanNode or HashJoinNode, rightRoot should be 
ScanNode
+        if (leftRoot instanceof OlapScanNode && rightRoot instanceof 
OlapScanNode) {
+            return canColocateJoin(node, leftRoot, rightRoot);
+        }
+
+        if (leftRoot instanceof HashJoinNode && rightRoot instanceof 
OlapScanNode) {
+            while (leftRoot instanceof HashJoinNode) {
+                if (((HashJoinNode)leftRoot).isColocate()) {
+                    leftRoot = leftRoot.getChild(0);
+                } else {
+                    return false;
+                }
+            }
 
 Review comment:
   Other node can be `HashJoinNode`'s left node, so you should check 
`leftRoot`'s type.
   
   For example: select * from (select id from t1 group id) a, (select id from 
t2 group by id) b where a.id = b.id;

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to