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 2020/02/20 10:31:52 UTC

[GitHub] [incubator-doris] yangzhg opened a new pull request #2957: implement the planner for set operation

yangzhg opened a new pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957
 
 
   implemnet intersect and except planner,
   examples:
   ```
   mysql> explain select k1,k2 from t where k1='a' intersect select k1,k2 from t where k1='b' except select k1,k2 from t where k1='c' union all select k1,k2 from t where k1='d';
   +----------------------------------------------------+
   | Explain String                                     |
   +----------------------------------------------------+
   | PLAN FRAGMENT 0                                    |
   |  OUTPUT EXPRS:<slot 8> | <slot 9>                  |
   |   PARTITION: UNPARTITIONED                         |
   |                                                    |
   |   RESULT SINK                                      |
   |                                                    |
   |   19:EXCHANGE                                      |
   |      tuple ids: 4                                  |
   |                                                    |
   | PLAN FRAGMENT 1                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 19                                |
   |     UNPARTITIONED                                  |
   |                                                    |
   |   7:UNION                                          |
   |   |  07:UNION                                      |
   |   |  pass-through-operands: all                    |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   |----18:EXCHANGE                                 |
   |   |       tuple ids: 3                             |
   |   |                                                |
   |   17:EXCHANGE                                      |
   |      tuple ids: 4                                  |
   |                                                    |
   | PLAN FRAGMENT 2                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 18                                |
   |     RANDOM                                         |
   |                                                    |
   |   8:OlapScanNode                                   |
   |      TABLE: t                                      |
   |      PREAGGREGATION: OFF. Reason: No AggregateInfo |
   |      PREDICATES: `k1` = 'd'                        |
   |      partitions=1/1                                |
   |      rollup: t                                     |
   |      tabletRatio=1/10                              |
   |      tabletList=10019                              |
   |      cardinality=-1                                |
   |      avgRowSize=0.0                                |
   |      numNodes=0                                    |
   |      tuple ids: 3                                  |
   |                                                    |
   | PLAN FRAGMENT 3                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: HASH_PARTITIONED: <slot 8>, <slot 9>  |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 17                                |
   |     RANDOM                                         |
   |                                                    |
   |   16:AGGREGATE (merge finalize)                    |
   |   |  group by: <slot 8>, <slot 9>                  |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   15:EXCHANGE                                      |
   |      tuple ids: 4                                  |
   |                                                    |
   | PLAN FRAGMENT 4                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 15                                |
   |     HASH_PARTITIONED: <slot 8>, <slot 9>           |
   |                                                    |
   |   6:AGGREGATE (update serialize)                   |
   |   |  STREAMING                                     |
   |   |  group by: <slot 8>, <slot 9>                  |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   4:EXCEPT                                         |
   |   |  04:EXCEPT                                     |
   |   |  pass-through-operands: all                    |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   |----14:EXCHANGE                                 |
   |   |       tuple ids: 2                             |
   |   |                                                |
   |   13:EXCHANGE                                      |
   |      tuple ids: 4                                  |
   |                                                    |
   | PLAN FRAGMENT 5                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 14                                |
   |     RANDOM                                         |
   |                                                    |
   |   5:OlapScanNode                                   |
   |      TABLE: t                                      |
   |      PREAGGREGATION: OFF. Reason: No AggregateInfo |
   |      PREDICATES: `k1` = 'c'                        |
   |      partitions=1/1                                |
   |      rollup: t                                     |
   |      tabletRatio=1/10                              |
   |      tabletList=10017                              |
   |      cardinality=-1                                |
   |      avgRowSize=0.0                                |
   |      numNodes=0                                    |
   |      tuple ids: 2                                  |
   |                                                    |
   | PLAN FRAGMENT 6                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: HASH_PARTITIONED: <slot 8>, <slot 9>  |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 13                                |
   |     RANDOM                                         |
   |                                                    |
   |   12:AGGREGATE (merge finalize)                    |
   |   |  group by: <slot 8>, <slot 9>                  |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   11:EXCHANGE                                      |
   |      tuple ids: 4                                  |
   |                                                    |
   | PLAN FRAGMENT 7                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 11                                |
   |     HASH_PARTITIONED: <slot 8>, <slot 9>           |
   |                                                    |
   |   3:AGGREGATE (update serialize)                   |
   |   |  STREAMING                                     |
   |   |  group by: <slot 8>, <slot 9>                  |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   0:INTERSECT                                      |
   |   |  00:INTERSECT                                  |
   |   |  pass-through-operands: all                    |
   |   |  tuple ids: 4                                  |
   |   |                                                |
   |   |----10:EXCHANGE                                 |
   |   |       tuple ids: 1                             |
   |   |                                                |
   |   9:EXCHANGE                                       |
   |      tuple ids: 0                                  |
   |                                                    |
   | PLAN FRAGMENT 8                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 10                                |
   |     RANDOM                                         |
   |                                                    |
   |   2:OlapScanNode                                   |
   |      TABLE: t                                      |
   |      PREAGGREGATION: OFF. Reason: No AggregateInfo |
   |      PREDICATES: `k1` = 'b'                        |
   |      partitions=1/1                                |
   |      rollup: t                                     |
   |      tabletRatio=1/10                              |
   |      tabletList=10009                              |
   |      cardinality=-1                                |
   |      avgRowSize=0.0                                |
   |      numNodes=0                                    |
   |      tuple ids: 1                                  |
   |                                                    |
   | PLAN FRAGMENT 9                                    |
   |  OUTPUT EXPRS:                                     |
   |   PARTITION: RANDOM                                |
   |                                                    |
   |   STREAM DATA SINK                                 |
   |     EXCHANGE ID: 09                                |
   |     RANDOM                                         |
   |                                                    |
   |   1:OlapScanNode                                   |
   |      TABLE: t                                      |
   |      PREAGGREGATION: OFF. Reason: No AggregateInfo |
   |      PREDICATES: `k1` = 'a'                        |
   |      partitions=1/1                                |
   |      rollup: t                                     |
   |      tabletRatio=1/10                              |
   |      tabletList=10021                              |
   |      cardinality=-1                                |
   |      avgRowSize=0.0                                |
   |      numNodes=0                                    |
   |      tuple ids: 0                                  |
   +----------------------------------------------------+
   189 rows in set (0.04 sec)
   
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [incubator-doris] morningman commented on a change in pull request #2957: implement the planner for set operation

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957#discussion_r382892210
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/qe/Coordinator.java
 ##########
 @@ -809,6 +812,63 @@ private boolean containsUnionNode(PlanNode node) {
         return false;
     }
 
+    // estimate if this fragment contains IntersectNode
+    private boolean containsIntersectNode(PlanNode node) {
 
 Review comment:
   Looks like these 3 `containsXXXNode` does not use?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [incubator-doris] morningman commented on a change in pull request #2957: implement the planner for set operation

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957#discussion_r382893199
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
 ##########
 @@ -1590,16 +1619,46 @@ private PlanNode createSetOperationPlan(SetOperationStmt setOperationStmt, Analy
         setOperationStmt.materializeRequiredSlots(analyzer);
 
         PlanNode result = null;
-        // create DISTINCT tree
-        if (setOperationStmt.hasDistinctOps()) {
-            result = createUnionPlan(
-                    analyzer, setOperationStmt, setOperationStmt.getDistinctOperands(), null, defaultOrderByLimit);
-            result = new AggregationNode(ctx_.getNextNodeId(), result, setOperationStmt.getDistinctAggInfo());
-            result.init(analyzer);
+        SetOperationStmt.Operation operation = null;
+        SetOperationStmt.Qualifier exceptQualifier = null;
+        List<SetOperationStmt.SetOperand> partialOperands = new ArrayList<>();
+        // create plan for a union b intersect c except b to three fragments
+        // 3:[2:[1:[a union b] intersect c] except c]
+        // EXCEPT operator is NOT commutative, it IS important which query is first,
+        // which second using EXCEPT operator, so EXCEPT operator cannot merge all distinct op to one node all all
+        // op to another node
 
 Review comment:
   Could you add more comment to explain the logic here?
   And better to add Unit test to test it. You can reference to bitmap function test.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [incubator-doris] morningman commented on a change in pull request #2957: implement the planner for set operation

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957#discussion_r382893263
 
 

 ##########
 File path: be/src/exec/intersect_node.h
 ##########
 @@ -0,0 +1,100 @@
+// 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.
+
+
+#ifndef  DORIS_BE_SRC_QUERY_EXEC_INTERSECT_NODE_H
+#define  DORIS_BE_SRC_QUERY_EXEC_INTERSECT_NODE_H
+
+#include "exec/exec_node.h"
+#include "runtime/row_batch.h"
+#include "runtime/runtime_state.h"
+
+namespace doris {
+
+// Node that alulate the interscet results of its children by either materializing their
 
 Review comment:
   ```suggestion
   // Node that calculate the intersect results of its children by either materializing their
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [incubator-doris] morningman merged pull request #2957: implement the planner for set operation

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [incubator-doris] morningman commented on a change in pull request #2957: implement the planner for set operation

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #2957: implement the planner for set operation
URL: https://github.com/apache/incubator-doris/pull/2957#discussion_r382893095
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
 ##########
 @@ -1609,6 +1668,40 @@ private PlanNode createSetOperationPlan(SetOperationStmt setOperationStmt, Analy
         return result;
     }
 
+    private PlanNode createPartialSetOperationPlan(Analyzer analyzer, SetOperationStmt setOperationStmt,
 
 Review comment:
   Add comments for this method.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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