Skip to content

Commit

Permalink
executor: record prepared stmt in handle_query_duration (#11753) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and sre-bot committed Sep 24, 2019
1 parent 655691b commit d008fd7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
maxExecutionTime := getMaxExecutionTime(sctx, a.StmtNode)
// Update processinfo, ShowProcess() will use it.
pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime)
a.Ctx.GetSessionVars().StmtCtx.StmtType = GetStmtLabel(a.StmtNode)
if a.Ctx.GetSessionVars().StmtCtx.StmtType == "" {
a.Ctx.GetSessionVars().StmtCtx.StmtType = GetStmtLabel(a.StmtNode)
}
}

isPessimistic := sctx.GetSessionVars().TxnCtx.IsPessimistic
Expand Down
1 change: 1 addition & 0 deletions executor/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (e *PrepareExec) Next(ctx context.Context, req *chunk.Chunk) error {
}
prepared := &ast.Prepared{
Stmt: stmt,
StmtType: GetStmtLabel(stmt),
Params: sorter.markers,
SchemaVersion: e.is.SchemaMetaVersion(),
}
Expand Down
2 changes: 2 additions & 0 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type Execute struct {
UsingVars []expression.Expression
ExecID uint32
Stmt ast.StmtNode
StmtType string
Plan Plan
}

Expand All @@ -192,6 +193,7 @@ func (e *Execute) OptimizePreparedPlan(ctx context.Context, sctx sessionctx.Cont
if !ok {
return errors.Trace(ErrStmtNotFound)
}
vars.StmtCtx.StmtType = prepared.StmtType

if len(prepared.Params) != len(e.UsingVars) {
return errors.Trace(ErrWrongParamCount)
Expand Down

0 comments on commit d008fd7

Please sign in to comment.