diff --git a/pkg/executor/adapter.go b/pkg/executor/adapter.go index 28864542ded64..d620075ddbf8d 100644 --- a/pkg/executor/adapter.go +++ b/pkg/executor/adapter.go @@ -1637,7 +1637,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { TimeOptimize: sessVars.DurationOptimization, TimeWaitTS: sessVars.DurationWaitTS, IndexNames: indexNames, - CopTasks: copTaskInfo, + CopTasks: &copTaskInfo, ExecDetail: execDetail, MemMax: memMax, DiskMax: diskMax, @@ -1989,7 +1989,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) { ParseLatency: sessVars.DurationParse, CompileLatency: sessVars.DurationCompile, StmtCtx: stmtCtx, - CopTasks: copTaskInfo, + CopTasks: &copTaskInfo, ExecDetail: &execDetail, MemMax: memMax, DiskMax: diskMax, diff --git a/pkg/util/execdetails/execdetails.go b/pkg/util/execdetails/execdetails.go index a813fbd6aa3e5..2de39a86ce620 100644 --- a/pkg/util/execdetails/execdetails.go +++ b/pkg/util/execdetails/execdetails.go @@ -464,19 +464,11 @@ func (s *SyncExecDetails) GetExecDetails() ExecDetails { } // CopTasksDetails returns some useful information of cop-tasks during execution. -func (s *SyncExecDetails) CopTasksDetails() *CopTasksDetails { +func (s *SyncExecDetails) CopTasksDetails() CopTasksDetails { s.mu.Lock() defer s.mu.Unlock() n := s.detailsSummary.NumCopTasks - d := &CopTasksDetails{ - NumCopTasks: n, - MaxBackoffTime: make(map[string]time.Duration), - AvgBackoffTime: make(map[string]time.Duration), - P90BackoffTime: make(map[string]time.Duration), - TotBackoffTime: make(map[string]time.Duration), - TotBackoffTimes: make(map[string]int), - MaxBackoffAddress: make(map[string]string), - } + d := CopTasksDetails{NumCopTasks: n} if n == 0 { return d } @@ -491,6 +483,14 @@ func (s *SyncExecDetails) CopTasksDetails() *CopTasksDetails { d.MaxWaitTime = s.detailsSummary.WaitTimePercentile.GetMax().D d.MaxWaitAddress = s.detailsSummary.WaitTimePercentile.GetMax().Addr + if len(s.detailsSummary.BackoffInfo) > 0 { + d.MaxBackoffTime = make(map[string]time.Duration) + d.AvgBackoffTime = make(map[string]time.Duration) + d.P90BackoffTime = make(map[string]time.Duration) + d.TotBackoffTime = make(map[string]time.Duration) + d.TotBackoffTimes = make(map[string]int) + d.MaxBackoffAddress = make(map[string]string) + } for backoff, items := range s.detailsSummary.BackoffInfo { if items == nil { continue diff --git a/pkg/util/stmtsummary/statement_summary.go b/pkg/util/stmtsummary/statement_summary.go index eb852f8d58420..7bae9223d990b 100644 --- a/pkg/util/stmtsummary/statement_summary.go +++ b/pkg/util/stmtsummary/statement_summary.go @@ -48,10 +48,10 @@ type stmtSummaryByDigestKey struct { prevDigest string // The digest of the plan of this SQL. planDigest string - // `hash` is the hash value of this object. - hash []byte // `resourceGroupName` is the resource group's name of this statement is bind to. resourceGroupName string + // `hash` is the hash value of this object. + hash []byte } // Hash implements SimpleLRUCache.Key. @@ -59,7 +59,7 @@ type stmtSummaryByDigestKey struct { // `prevSQL` is included in the key To distinguish different transactions. func (key *stmtSummaryByDigestKey) Hash() []byte { if len(key.hash) == 0 { - key.hash = make([]byte, 0, len(key.schemaName)+len(key.digest)+len(key.prevDigest)+len(key.planDigest)) + key.hash = make([]byte, 0, len(key.schemaName)+len(key.digest)+len(key.prevDigest)+len(key.planDigest)+len(key.resourceGroupName)) key.hash = append(key.hash, hack.Slice(key.digest)...) key.hash = append(key.hash, hack.Slice(key.schemaName)...) key.hash = append(key.hash, hack.Slice(key.prevDigest)...) diff --git a/pkg/util/stmtsummary/v2/stmtsummary.go b/pkg/util/stmtsummary/v2/stmtsummary.go index b827fd2a6970a..0c8e99dfce45f 100644 --- a/pkg/util/stmtsummary/v2/stmtsummary.go +++ b/pkg/util/stmtsummary/v2/stmtsummary.go @@ -467,7 +467,7 @@ type stmtKey struct { // `prevSQL` is included in the key To distinguish different transactions. func (k *stmtKey) Hash() []byte { if len(k.hash) == 0 { - k.hash = make([]byte, 0, len(k.schemaName)+len(k.digest)+len(k.prevDigest)+len(k.planDigest)) + k.hash = make([]byte, 0, len(k.schemaName)+len(k.digest)+len(k.prevDigest)+len(k.planDigest)+len(k.resourceGroupName)) k.hash = append(k.hash, hack.Slice(k.digest)...) k.hash = append(k.hash, hack.Slice(k.schemaName)...) k.hash = append(k.hash, hack.Slice(k.prevDigest)...) diff --git a/pkg/util/util.go b/pkg/util/util.go index 8d3bbf50117e3..fc0e17f4d7ad0 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -121,9 +121,8 @@ func GenLogFields(costTime time.Duration, info *ProcessInfo, needTruncateSQL boo logFields = append(logFields, zap.String("cost_time", strconv.FormatFloat(costTime.Seconds(), 'f', -1, 64)+"s")) execDetail := info.StmtCtx.GetExecDetails() logFields = append(logFields, execDetail.ToZapFields()...) - if copTaskInfo := info.StmtCtx.CopTasksDetails(); copTaskInfo != nil { - logFields = append(logFields, copTaskInfo.ToZapFields()...) - } + copTaskInfo := info.StmtCtx.CopTasksDetails() + logFields = append(logFields, copTaskInfo.ToZapFields()...) if statsInfo := info.StatsInfo(info.Plan); len(statsInfo) > 0 { var buf strings.Builder firstComma := false