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 2021/03/15 12:42:13 UTC

[GitHub] [incubator-doris] EmmyMiao87 commented on a change in pull request #5475: [Profile] Visualize the query plan and query profile

EmmyMiao87 commented on a change in pull request #5475:
URL: https://github.com/apache/incubator-doris/pull/5475#discussion_r594256107



##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -2653,14 +2661,14 @@ describe_stmt ::=
     {:
         RESULT = new DescribeStmt(table, true);
     :}
-    | describe_command opt_verbose:isVerbose query_stmt:query
+    | describe_command opt_explain_options:options query_stmt:query
     {:
-        query.setIsExplain(true, isVerbose);
+        query.setIsExplain(options);
         RESULT = query;
     :}   
     | describe_command insert_stmt:stmt
     {:
-        stmt.getQueryStmt().setIsExplain(true);
+        stmt.getQueryStmt().setIsExplain(new ExplainOptions(true, false));
         RESULT = stmt;
     :}
     ;

Review comment:
       Change ```KW_DESCRIBE``` to ```KW_EXPLAIN```

##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/StatementBase.java
##########
@@ -36,9 +36,7 @@
     private String clusterName;
 
     // True if this QueryStmt is the top level query from an EXPLAIN <query>

Review comment:
       Please update comment.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/profile/PlanTreeBuilder.java
##########
@@ -0,0 +1,127 @@
+// 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.common.profile;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.DataSink;
+import org.apache.doris.planner.PlanFragment;
+import org.apache.doris.planner.PlanNode;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.thrift.TExplainLevel;
+
+import com.clearspring.analytics.util.Lists;
+
+import java.util.List;
+
+public class PlanTreeBuilder {
+
+    private static final String EXCHANGE_NODE = "EXCHANGE";
+    private static final String MERGING_EXCHANGE_NODE = "MERGING-EXCHANGE";
+
+    private List<PlanFragment> fragments;
+    private PlanTreeNode treeRoot;
+    private List<PlanTreeNode> sinkNodes = Lists.newArrayList();
+    private List<PlanTreeNode> exchangeNodes = Lists.newArrayList();
+
+    public PlanTreeBuilder(List<PlanFragment> fragments) {
+        this.fragments = fragments;
+    }
+
+    public PlanTreeNode getTreeRoot() {
+        return treeRoot;
+    }
+
+    public void build() throws UserException {
+        buildFragmentPlans();
+        assembleFragmentPlans();
+    }
+
+    private void buildFragmentPlans() {
+        int i = 0;
+        for (PlanFragment fragment : fragments) {
+            DataSink sink = fragment.getSink();
+            PlanTreeNode sinkNode = null;
+            if (sink != null) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("[").append(sink.getExchNodeId().asInt()).append(": DATA SINK]");
+                sb.append("\nFragment: ").append(fragment.getId().asInt());
+                sb.append("\n").append(sink.getExplainString("", TExplainLevel.BRIEF));
+                sinkNode = new PlanTreeNode(sink.getExchNodeId(), sb.toString());
+                if (i == 0) {
+                    // sink of first fragment, set it as tree root
+                    treeRoot = sinkNode;
+                } else {
+                    sinkNodes.add(sinkNode);
+                }
+            }
+
+            PlanNode planRoot = fragment.getPlanRoot();
+            if (planRoot != null) {
+                buildForPlanNode(planRoot, sinkNode);
+            }
+            i++;
+        }
+    }
+
+    private void assembleFragmentPlans() throws UserException {
+        for (PlanTreeNode sender : sinkNodes) {
+            if (sender == treeRoot) {
+                // This is the result sink, skip it
+                continue;
+            }
+            PlanNodeId senderId = sender.getId();
+            PlanTreeNode exchangeNode = findExchangeNode(senderId);
+            if (exchangeNode == null) {
+                throw new UserException("Failed to find exchange node for sender id: " + senderId.asInt());
+            }
+
+            exchangeNode.addChild(sender);
+        }
+    }
+
+    private PlanTreeNode findExchangeNode(PlanNodeId senderId) {
+        for (PlanTreeNode exchangeNode : exchangeNodes) {
+            if (exchangeNode.getId().equals(senderId)) {
+                return exchangeNode;
+            }
+        }
+        return null;
+    }
+
+    private void buildForPlanNode(PlanNode planNode, PlanTreeNode parent) {
+        StringBuilder sb = new StringBuilder();

Review comment:
       Why not print the plan node directly?

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/profile/PlanTreeBuilder.java
##########
@@ -0,0 +1,127 @@
+// 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.common.profile;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.DataSink;
+import org.apache.doris.planner.PlanFragment;
+import org.apache.doris.planner.PlanNode;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.thrift.TExplainLevel;
+
+import com.clearspring.analytics.util.Lists;
+
+import java.util.List;
+
+public class PlanTreeBuilder {
+
+    private static final String EXCHANGE_NODE = "EXCHANGE";
+    private static final String MERGING_EXCHANGE_NODE = "MERGING-EXCHANGE";

Review comment:
       Same as above

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/profile/PlanTreeBuilder.java
##########
@@ -0,0 +1,127 @@
+// 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.common.profile;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.DataSink;
+import org.apache.doris.planner.PlanFragment;
+import org.apache.doris.planner.PlanNode;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.thrift.TExplainLevel;
+
+import com.clearspring.analytics.util.Lists;
+
+import java.util.List;
+
+public class PlanTreeBuilder {
+
+    private static final String EXCHANGE_NODE = "EXCHANGE";
+    private static final String MERGING_EXCHANGE_NODE = "MERGING-EXCHANGE";
+
+    private List<PlanFragment> fragments;
+    private PlanTreeNode treeRoot;
+    private List<PlanTreeNode> sinkNodes = Lists.newArrayList();
+    private List<PlanTreeNode> exchangeNodes = Lists.newArrayList();
+
+    public PlanTreeBuilder(List<PlanFragment> fragments) {
+        this.fragments = fragments;
+    }
+
+    public PlanTreeNode getTreeRoot() {
+        return treeRoot;
+    }
+
+    public void build() throws UserException {
+        buildFragmentPlans();
+        assembleFragmentPlans();
+    }
+
+    private void buildFragmentPlans() {
+        int i = 0;
+        for (PlanFragment fragment : fragments) {
+            DataSink sink = fragment.getSink();
+            PlanTreeNode sinkNode = null;
+            if (sink != null) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("[").append(sink.getExchNodeId().asInt()).append(": DATA SINK]");

Review comment:
       DATA SINK or Result Sink

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/profile/PlanTreeBuilder.java
##########
@@ -0,0 +1,127 @@
+// 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.common.profile;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.DataSink;
+import org.apache.doris.planner.PlanFragment;
+import org.apache.doris.planner.PlanNode;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.thrift.TExplainLevel;
+
+import com.clearspring.analytics.util.Lists;
+
+import java.util.List;
+
+public class PlanTreeBuilder {
+
+    private static final String EXCHANGE_NODE = "EXCHANGE";

Review comment:
       Use final params in Exchange Node.




----------------------------------------------------------------
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



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