diff --git a/executor/adapter.go b/executor/adapter.go index c313999e1c402..fa43702946a9d 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -41,6 +41,7 @@ import ( "golang.org/x/net/context" ) +// processinfoSetter is the interface use to set current running process info. type processinfoSetter interface { SetProcessInfo(string) } @@ -230,6 +231,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (sqlexec.RecordSet, error) { } // Update processinfo, ShowProcess() will use it. pi.SetProcessInfo(sql) + a.Ctx.GetSessionVars().StmtCtx.StmtType = GetStmtLabel(a.StmtNode) } // If the executor doesn't return any result to the client, we execute it without delay. if e.Schema().Len() == 0 { diff --git a/server/conn.go b/server/conn.go index c6bdf41c8f3bc..e2a45b5b225c5 100644 --- a/server/conn.go +++ b/server/conn.go @@ -580,7 +580,12 @@ func (cc *clientConn) addMetrics(cmd byte, startTime time.Time, err error) { } else { metrics.QueryTotalCounter.WithLabelValues(label, "OK").Inc() } - metrics.QueryDurationHistogram.WithLabelValues(metrics.LblGeneral).Observe(time.Since(startTime).Seconds()) + stmtType := cc.ctx.GetSessionVars().StmtCtx.StmtType + sqlType := metrics.LblGeneral + if stmtType != "" { + sqlType = stmtType + } + metrics.QueryDurationHistogram.WithLabelValues(sqlType).Observe(time.Since(startTime).Seconds()) } // dispatch handles client request based on command which is the first byte of the data. diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index 1817f24396faf..eecb56d1ac05c 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -88,6 +88,7 @@ type StatementContext struct { RuntimeStatsColl *execdetails.RuntimeStatsColl TableIDs []int64 IndexIDs []int64 + StmtType string } // AddAffectedRows adds affected rows.