You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2020/07/31 07:18:11 UTC

[incubator-doris] branch master updated: [Bug][ColocateJoin] Make a wrong choice of colocate join (#4216)

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

lichaoyong 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 f412f99  [Bug][ColocateJoin] Make a wrong choice of colocate join (#4216)
f412f99 is described below

commit f412f99511df2e889879f8228ad4ba3e359023b1
Author: HappenLee <ha...@hotmail.com>
AuthorDate: Fri Jul 31 15:18:00 2020 +0800

    [Bug][ColocateJoin] Make a wrong choice of colocate join (#4216)
    
    If table1 and table2 are colocated using column k1, k2.
    Query should contains all of the k1, k2 to apply colocation algorithm.
    Query like select * from table1 inner join table2 where t1.k1 = t2.k1 can not be used as colocation.
    We add the rule to avoid the problem.
---
 .../apache/doris/planner/DistributedPlanner.java    | 17 +++++++++++------
 .../org/apache/doris/planner/QueryPlanTest.java     | 21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 6 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 88775e1..351a7cf 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
@@ -513,9 +513,11 @@ public class DistributedPlanner {
         DistributionInfo rightDistribution = rightTable.getDefaultDistributionInfo();
 
         if (leftDistribution instanceof HashDistributionInfo && rightDistribution instanceof HashDistributionInfo) {
-            List<Column> leftColumns = ((HashDistributionInfo) leftDistribution).getDistributionColumns();
-            List<Column> rightColumns = ((HashDistributionInfo) rightDistribution).getDistributionColumns();
+            List<Column> leftDistributeColumns = ((HashDistributionInfo) leftDistribution).getDistributionColumns();
+            List<Column> rightDistributeColumns = ((HashDistributionInfo) rightDistribution).getDistributionColumns();
 
+            List<Column> leftJoinColumns = new ArrayList<>();
+            List<Column> rightJoinColumns = new ArrayList<>();
             List<BinaryPredicate> eqJoinConjuncts = node.getEqJoinConjuncts();
             for (BinaryPredicate eqJoinPredicate : eqJoinConjuncts) {
                 Expr lhsJoinExpr = eqJoinPredicate.getChild(0);
@@ -527,10 +529,13 @@ public class DistributedPlanner {
                 SlotDescriptor leftSlot = lhsJoinExpr.unwrapSlotRef().getDesc();
                 SlotDescriptor rightSlot = rhsJoinExpr.unwrapSlotRef().getDesc();
 
-                //3 the eqJoinConjuncts must contain the distributionColumns
-                if (leftColumns.contains(leftSlot.getColumn()) && rightColumns.contains(rightSlot.getColumn())) {
-                    return true;
-                }
+                leftJoinColumns.add(leftSlot.getColumn());
+                rightJoinColumns.add(rightSlot.getColumn());
+            }
+
+            //3 the join columns should contains all distribute columns to enable colocate join
+            if (leftJoinColumns.containsAll(leftDistributeColumns) && rightJoinColumns.containsAll(rightDistributeColumns)) {
+                return true;
             }
         }
 
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 433671e..0134de9 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
@@ -282,6 +282,16 @@ public class QueryPlanTest {
                 "(k1 int, k2 int) distributed by hash(k1) buckets 1\n" +
                 "properties(\"replication_num\" = \"1\");");
 
+        createTable("create table test.colocate1\n" +
+                "(k1 int, k2 int, k3 int) distributed by hash(k1, k2) buckets 1\n" +
+                "properties(\"replication_num\" = \"1\"," +
+                "\"colocate_with\" = \"group1\");");
+
+        createTable("create table test.colocate2\n" +
+                "(k1 int, k2 int, k3 int) distributed by hash(k1, k2) buckets 1\n" +
+                "properties(\"replication_num\" = \"1\"," +
+                "\"colocate_with\" = \"group1\");");
+
         createTable("create external table test.mysql_table\n" +
                 "(k1 int, k2 int)\n" +
                 "ENGINE=MYSQL\n" +
@@ -875,6 +885,17 @@ public class QueryPlanTest {
     }
 
     @Test
+    public void testColocateJoin() throws Exception {
+        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"));
+
+        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"));
+    }
+
+    @Test
     public void testJoinWithMysqlTable() throws Exception {
         connectContext.setDatabase("default_cluster:test");
 


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