fix profile may cause query slow (#11386)

Co-authored-by: Wang Bo <wangbo36@meituan.com>
This commit is contained in:
wangbo
2022-08-07 20:52:52 +08:00
committed by GitHub
parent 8b9d299472
commit 8802a41918
2 changed files with 11 additions and 5 deletions

View File

@ -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) {

View File

@ -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);