From 8802a419186bdfdf22eba2160e9bfaa72fca6888 Mon Sep 17 00:00:00 2001 From: wangbo Date: Sun, 7 Aug 2022 20:52:52 +0800 Subject: [PATCH] fix profile may cause query slow (#11386) Co-authored-by: Wang Bo --- .../java/org/apache/doris/qe/ConnectProcessor.java | 11 +++++++++++ .../main/java/org/apache/doris/qe/StmtExecutor.java | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java index 4ca8492ed0..a9b18776e1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java @@ -20,6 +20,7 @@ package org.apache.doris.qe; import org.apache.doris.analysis.InsertStmt; import org.apache.doris.analysis.KillStmt; import org.apache.doris.analysis.Queriable; +import org.apache.doris.analysis.QueryStmt; import org.apache.doris.analysis.SqlParser; import org.apache.doris.analysis.SqlScanner; import org.apache.doris.analysis.StatementBase; @@ -45,6 +46,7 @@ import org.apache.doris.mysql.MysqlPacket; import org.apache.doris.mysql.MysqlProto; import org.apache.doris.mysql.MysqlSerializer; import org.apache.doris.mysql.MysqlServerStatusFlag; +import org.apache.doris.nereids.glue.LogicalPlanAdapter; import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.plugin.AuditEvent.EventType; import org.apache.doris.proto.Data; @@ -421,6 +423,15 @@ public class ConnectProcessor { MysqlChannel channel = ctx.getMysqlChannel(); channel.sendAndFlush(packet); + // note(wb) we should write profile after return result to mysql client + // because write profile maybe take too much time + // explain query stmt do not have profile + if (executor != null && !executor.getParsedStmt().isExplain() + && (executor.getParsedStmt() instanceof QueryStmt // currently only QueryStmt and insert need profile + || executor.getParsedStmt() instanceof LogicalPlanAdapter + || executor.getParsedStmt() instanceof InsertStmt)) { + executor.writeProfile(true); + } } public TMasterOpResult proxyExecute(TMasterOpRequest request) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index b6f1345bbc..c1edb216da 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -434,10 +434,6 @@ public class StmtExecutor implements ProfileWriter { span.setAttribute("queryId", DebugUtil.printId(newQueryId)); } handleQueryStmt(); - // explain query stmt do not have profile - if (!parsedStmt.isExplain()) { - writeProfile(true); - } break; } catch (RpcException e) { if (i == retryTime - 1) { @@ -469,7 +465,6 @@ public class StmtExecutor implements ProfileWriter { handleInsertStmt(); if (!((InsertStmt) parsedStmt).getQueryStmt().isExplain()) { queryType = "Insert"; - writeProfile(true); } } catch (Throwable t) { LOG.warn("handle insert stmt fail", t);