You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/14 14:54:57 UTC

[GitHub] [doris] jackwener commented on a diff in pull request #14880: [fix](Nereids): Update plan when prune column in DPHyp

jackwener commented on code in PR #14880:
URL: https://github.com/apache/doris/pull/14880#discussion_r1048481376


##########
fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/JoinOrderJobTest.java:
##########
@@ -17,42 +17,122 @@
 
 package org.apache.doris.nereids.jobs.joinorder;
 
-import org.apache.doris.common.Pair;
-import org.apache.doris.nereids.trees.plans.JoinType;
-import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
-import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
-import org.apache.doris.nereids.util.LogicalPlanBuilder;
-import org.apache.doris.nereids.util.MemoTestUtils;
 import org.apache.doris.nereids.util.PlanChecker;
-import org.apache.doris.nereids.util.PlanConstructor;
+import org.apache.doris.utframe.TestWithFeService;
 
-import com.google.common.collect.Lists;
 import org.junit.jupiter.api.Test;
 
-public class JoinOrderJobTest {
-    private final LogicalOlapScan scan1 = PlanConstructor.newLogicalOlapScan(1, "t1", 0);
-    private final LogicalOlapScan scan2 = PlanConstructor.newLogicalOlapScan(2, "t2", 0);
-    private final LogicalOlapScan scan3 = PlanConstructor.newLogicalOlapScan(3, "t3", 0);
-    private final LogicalOlapScan scan4 = PlanConstructor.newLogicalOlapScan(4, "t4", 0);
-    private final LogicalOlapScan scan5 = PlanConstructor.newLogicalOlapScan(5, "t5", 0);
+public class JoinOrderJobTest extends TestWithFeService {

Review Comment:
   we can remove them into `sqltest`, and extends SqlTestBase



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/joinorder/JoinOrderJob.java:
##########
@@ -77,13 +94,36 @@ private Group optimizeJoin(Group group) {
                 throw new RuntimeException("DPHyp can not enumerate all sub graphs with limit=" + limit);
             }
         }
-
         Group optimized = planReceiver.getBestPlan(hyperGraph.getNodesMap());
-        return copyToMemo(optimized);
+
+        // Apply column pruning after optimizing

Review Comment:
   why not reuse `PruneColumn` rule



##########
fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/TPCHTest.java:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.jobs.joinorder;
+
+import org.apache.doris.nereids.util.PlanChecker;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Test;
+
+public class TPCHTest extends TestWithFeService {
+    @Override
+    protected void runBeforeAll() throws Exception {
+        createDatabase("test");
+        connectContext.setDatabase("default_cluster:test");
+        createTables("CREATE TABLE lineitem (\n"
+                        + "    l_shipdate    DATEV2 NOT NULL,\n"
+                        + "    l_orderkey    bigint NOT NULL,\n"
+                        + "    l_linenumber  int not null,\n"
+                        + "    l_partkey     int NOT NULL,\n"
+                        + "    l_suppkey     int not null,\n"
+                        + "    l_quantity    decimalv3(15, 2) NOT NULL,\n"
+                        + "    l_extendedprice  decimalv3(15, 2) NOT NULL,\n"
+                        + "    l_discount    decimalv3(15, 2) NOT NULL,\n"
+                        + "    l_tax         decimalv3(15, 2) NOT NULL,\n"
+                        + "    l_returnflag  VARCHAR(1) NOT NULL,\n"
+                        + "    l_linestatus  VARCHAR(1) NOT NULL,\n"
+                        + "    l_commitdate  DATEV2 NOT NULL,\n"
+                        + "    l_receiptdate DATEV2 NOT NULL,\n"
+                        + "    l_shipinstruct VARCHAR(25) NOT NULL,\n"
+                        + "    l_shipmode     VARCHAR(10) NOT NULL,\n"
+                        + "    l_comment      VARCHAR(44) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`l_shipdate`, `l_orderkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\",\n"
+                        + "    \"colocate_with\" = \"lineitem_orders\"\n"
+                        + ");\n",
+                        "CREATE TABLE orders  (\n"
+                        + "    o_orderkey       bigint NOT NULL,\n"
+                        + "    o_orderdate      DATEV2 NOT NULL,\n"
+                        + "    o_custkey        int NOT NULL,\n"
+                        + "    o_orderstatus    VARCHAR(1) NOT NULL,\n"
+                        + "    o_totalprice     decimalv3(15, 2) NOT NULL,\n"
+                        + "    o_orderpriority  VARCHAR(15) NOT NULL,\n"
+                        + "    o_clerk          VARCHAR(15) NOT NULL,\n"
+                        + "    o_shippriority   int NOT NULL,\n"
+                        + "    o_comment        VARCHAR(79) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`o_orderkey`, `o_orderdate`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\",\n"
+                        + "    \"colocate_with\" = \"lineitem_orders\"\n"
+                        + ");\n",
+                        "CREATE TABLE partsupp (\n"
+                        + "    ps_partkey          int NOT NULL,\n"
+                        + "    ps_suppkey     int NOT NULL,\n"
+                        + "    ps_availqty    int NOT NULL,\n"
+                        + "    ps_supplycost  decimalv3(15, 2)  NOT NULL,\n"
+                        + "    ps_comment     VARCHAR(199) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`ps_partkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`ps_partkey`) BUCKETS 24\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\",\n"
+                        + "    \"colocate_with\" = \"part_partsupp\"\n"
+                        + ");\n",
+                        "CREATE TABLE part (\n"
+                        + "    p_partkey          int NOT NULL,\n"
+                        + "    p_name        VARCHAR(55) NOT NULL,\n"
+                        + "    p_mfgr        VARCHAR(25) NOT NULL,\n"
+                        + "    p_brand       VARCHAR(10) NOT NULL,\n"
+                        + "    p_type        VARCHAR(25) NOT NULL,\n"
+                        + "    p_size        int NOT NULL,\n"
+                        + "    p_container   VARCHAR(10) NOT NULL,\n"
+                        + "    p_retailprice decimalv3(15, 2) NOT NULL,\n"
+                        + "    p_comment     VARCHAR(23) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`p_partkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`p_partkey`) BUCKETS 24\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\",\n"
+                        + "    \"colocate_with\" = \"part_partsupp\"\n"
+                        + ");\n",
+                        "CREATE TABLE customer (\n"
+                        + "    c_custkey     int NOT NULL,\n"
+                        + "    c_name        VARCHAR(25) NOT NULL,\n"
+                        + "    c_address     VARCHAR(40) NOT NULL,\n"
+                        + "    c_nationkey   int NOT NULL,\n"
+                        + "    c_phone       VARCHAR(15) NOT NULL,\n"
+                        + "    c_acctbal     decimalv3(15, 2)   NOT NULL,\n"
+                        + "    c_mktsegment  VARCHAR(10) NOT NULL,\n"
+                        + "    c_comment     VARCHAR(117) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`c_custkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 24\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\"\n"
+                        + ");\n"
+                        + "\n",
+                        "CREATE TABLE supplier (\n"
+                        + "    s_suppkey       int NOT NULL,\n"
+                        + "    s_name        VARCHAR(25) NOT NULL,\n"
+                        + "    s_address     VARCHAR(40) NOT NULL,\n"
+                        + "    s_nationkey   int NOT NULL,\n"
+                        + "    s_phone       VARCHAR(15) NOT NULL,\n"
+                        + "    s_acctbal     decimalv3(15, 2) NOT NULL,\n"
+                        + "    s_comment     VARCHAR(101) NOT NULL\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`s_suppkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`s_suppkey`) BUCKETS 12\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\"\n"
+                        + ");\n"
+                        + "\n",
+                        "CREATE TABLE `nation` (\n"
+                        + "  `n_nationkey` int(11) NOT NULL,\n"
+                        + "  `n_name`      varchar(25) NOT NULL,\n"
+                        + "  `n_regionkey` int(11) NOT NULL,\n"
+                        + "  `n_comment`   varchar(152) NULL\n"
+                        + ") ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`N_NATIONKEY`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`N_NATIONKEY`) BUCKETS 1\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\"\n"
+                        + ");\n",
+                        "CREATE TABLE region  (\n"
+                        + "    r_regionkey      int NOT NULL,\n"
+                        + "    r_name       VARCHAR(25) NOT NULL,\n"
+                        + "    r_comment    VARCHAR(152)\n"
+                        + ")ENGINE=OLAP\n"
+                        + "DUPLICATE KEY(`r_regionkey`)\n"
+                        + "COMMENT \"OLAP\"\n"
+                        + "DISTRIBUTED BY HASH(`r_regionkey`) BUCKETS 1\n"
+                        + "PROPERTIES (\n"
+                        + "    \"replication_num\" = \"1\"\n"
+                        + ");\n"
+        );
+    }
+
+    @Test
+    void testQ5() {

Review Comment:
   we can use `TPCHUtils.q5`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java:
##########
@@ -52,7 +53,7 @@ public class GroupExpression {
     private CostEstimate costEstimate = null;
     private Group ownerGroup;
     private final List<Group> children;
-    private final Plan plan;
+    private Plan plan;

Review Comment:
   we also need comment it.
   like this `// immutable except for DPHyp`



##########
fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/TPCHTest.java:
##########
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.jobs.joinorder;
+
+import org.apache.doris.nereids.util.PlanChecker;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Test;
+
+public class TPCHTest extends TestWithFeService {

Review Comment:
   why not extend `TPCHTestBase`



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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