You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/08/09 12:48:48 UTC

[incubator-doris] branch master updated: [Bug][ColocateJoin] Fix bug of #4287 and #4285 of Colocatejoin (#4289)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 47fff68  [Bug][ColocateJoin] Fix bug of #4287 and #4285 of Colocatejoin (#4289)
47fff68 is described below

commit 47fff6841b9f8cd3d5af15a2ae4fad87b4f60712
Author: HappenLee <ha...@hotmail.com>
AuthorDate: Sun Aug 9 20:48:36 2020 +0800

    [Bug][ColocateJoin] Fix bug of #4287 and #4285 of Colocatejoin (#4289)
    
    1.Table join itself should have same single partition to valid colocate join.
    2.Check eqjoinConjuncts column order to valid colocate join.
---
 .../apache/doris/planner/DistributedPlanner.java   | 24 +++++++++++++++++-----
 .../org/apache/doris/planner/QueryPlanTest.java    | 15 ++++++++++++++
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
index 429076f..d886677 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/DistributedPlanner.java
@@ -45,6 +45,7 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -494,9 +495,14 @@ public class DistributedPlanner {
         OlapTable leftTable = ((OlapScanNode) leftRoot).getOlapTable();
         OlapTable rightTable = ((OlapScanNode) rightRoot).getOlapTable();
 
-        // if left table and right table is same table, they are naturally colocate relationship
-        // no need to check colocate group
-        if (leftTable.getId() != rightTable.getId()) {
+        // if left table and right table is same table and they select same single partition or no partition
+        // they are naturally colocate relationship no need to check colocate group
+        Collection<Long> leftPartitions = ((OlapScanNode)leftRoot).getSelectedPartitionIds();
+        Collection<Long> rightPartitions = ((OlapScanNode)rightRoot).getSelectedPartitionIds();
+        boolean noNeedCheckColocateGroup = (leftTable.getId() == rightTable.getId()) && (leftPartitions.equals(rightPartitions)) &&
+                (leftPartitions.size() <= 1);
+
+        if (!noNeedCheckColocateGroup) {
             ColocateTableIndex colocateIndex = Catalog.getCurrentColocateIndex();
 
             //1 the table must be colocate
@@ -533,8 +539,16 @@ public class DistributedPlanner {
                 SlotDescriptor leftSlot = lhsJoinExpr.unwrapSlotRef().getDesc();
                 SlotDescriptor rightSlot = rhsJoinExpr.unwrapSlotRef().getDesc();
 
-                leftJoinColumns.add(leftSlot.getColumn());
-                rightJoinColumns.add(rightSlot.getColumn());
+                Column leftColumn = leftSlot.getColumn();
+                Column rightColumn = rightSlot.getColumn();
+                int leftColumnIndex = leftDistributeColumns.indexOf(leftColumn);
+                int rightColumnIndex = rightDistributeColumns.indexOf(rightColumn);
+
+                // eqjoinConjuncts column should have the same order like colocate distribute column
+                if (leftColumnIndex == rightColumnIndex && leftColumnIndex != -1) {
+                    leftJoinColumns.add(leftSlot.getColumn());
+                    rightJoinColumns.add(rightSlot.getColumn());
+                }
             }
 
             //3 the join columns should contains all distribute columns to enable colocate join
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index 57ebc3c..b9eb997 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -886,10 +886,17 @@ public class QueryPlanTest {
 
     @Test
     public void testColocateJoin() throws Exception {
+        FeConstants.runningUnitTest = true;
+
         String queryStr = "explain select * from test.colocate1 t1, test.colocate2 t2 where t1.k1 = t2.k1 and t1.k2 = t2.k2 and t1.k3 = t2.k3";
         String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
         Assert.assertTrue(explainString.contains("colocate: true"));
 
+        // t1.k1 = t2.k2 not same order with distribute column
+        queryStr = "explain select * from test.colocate1 t1, test.colocate2 t2 where t1.k1 = t2.k2 and t1.k2 = t2.k1 and t1.k3 = t2.k3";
+        explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+        Assert.assertTrue(explainString.contains("colocate: false"));
+
         queryStr = "explain select * from test.colocate1 t1, test.colocate2 t2 where t1.k2 = t2.k2";
         explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
         Assert.assertTrue(explainString.contains("colocate: false"));
@@ -897,9 +904,17 @@ public class QueryPlanTest {
 
     @Test
     public void testSelfColocateJoin() throws Exception {
+        FeConstants.runningUnitTest = true;
+
+        // single partition
         String queryStr = "explain select * from test.jointest t1, test.jointest t2 where t1.k1 = t2.k1";
         String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
         Assert.assertTrue(explainString.contains("colocate: true"));
+
+        // multi partition, should not be colocate
+        queryStr = "explain select * from test.dynamic_partition t1, test.dynamic_partition t2 where t1.k1 = t2.k1";
+        explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+        Assert.assertTrue(explainString.contains("colocate: false"));
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org