Skip to content

Commit

Permalink
statistics: fix the sync load sql did'nt running internally (#40087)
Browse files Browse the repository at this point in the history
close #39511
  • Loading branch information
Yisaer authored Dec 22, 2022
1 parent aeccf77 commit 4adce4c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ func (s *session) ExecRestrictedSQL(ctx context.Context, opts []sqlexec.OptionFu
metrics.SessionRestrictedSQLCounter.Inc()
ctx = context.WithValue(ctx, execdetails.StmtExecDetailKey, &execdetails.StmtExecDetails{})
ctx = context.WithValue(ctx, tikvutil.ExecDetailsKey, &tikvutil.ExecDetails{})
rs, err := se.ExecuteStmt(ctx, stmt)
rs, err := se.ExecuteInternalStmt(ctx, stmt)
if err != nil {
se.sessionVars.StmtCtx.AppendError(err)
}
Expand All @@ -2113,6 +2113,18 @@ func (s *session) ExecRestrictedSQL(ctx context.Context, opts []sqlexec.OptionFu
})
}

// ExecuteInternalStmt execute internal stmt
func (s *session) ExecuteInternalStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlexec.RecordSet, error) {
origin := s.sessionVars.InRestrictedSQL
s.sessionVars.InRestrictedSQL = true
defer func() {
s.sessionVars.InRestrictedSQL = origin
// Restore the goroutine label by using the original ctx after execution is finished.
pprof.SetGoroutineLabels(ctx)
}()
return s.ExecuteStmt(ctx, stmtNode)
}

func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlexec.RecordSet, error) {
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span1 := span.Tracer().StartSpan("session.ExecuteStmt", opentracing.ChildOf(span.Context()))
Expand Down

0 comments on commit 4adce4c

Please sign in to comment.