diff --git a/pkg/executor/adapter.go b/pkg/executor/adapter.go index a1c9261acf3c2..adafafa117013 100644 --- a/pkg/executor/adapter.go +++ b/pkg/executor/adapter.go @@ -1941,7 +1941,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) { } execDetail := stmtCtx.GetExecDetails() - copTaskInfo := stmtCtx.CopTasksDetails() + copTaskInfo := stmtCtx.CopTasksSummary() memMax := sessVars.MemTracker.MaxConsumed() diskMax := sessVars.DiskTracker.MaxConsumed() var stmtDetail execdetails.StmtExecDetails diff --git a/pkg/util/execdetails/execdetails.go b/pkg/util/execdetails/execdetails.go index 6107c089f405e..deca7eb85a46d 100644 --- a/pkg/util/execdetails/execdetails.go +++ b/pkg/util/execdetails/execdetails.go @@ -511,6 +511,25 @@ func (s *SyncExecDetails) CopTasksDetails() *CopTasksDetails { return d } +// CopTasksSummary returns some summary information of cop-tasks for statement summary. +func (s *SyncExecDetails) CopTasksSummary() *CopTasksSummary { + s.mu.Lock() + defer s.mu.Unlock() + n := s.detailsSummary.NumCopTasks + if n == 0 { + return nil + } + return &CopTasksSummary{ + NumCopTasks: n, + MaxProcessAddress: s.detailsSummary.ProcessTimePercentile.GetMax().Addr, + MaxProcessTime: s.detailsSummary.ProcessTimePercentile.GetMax().D, + TotProcessTime: s.execDetails.TimeDetail.ProcessTime, + MaxWaitAddress: s.detailsSummary.WaitTimePercentile.GetMax().Addr, + MaxWaitTime: s.detailsSummary.WaitTimePercentile.GetMax().D, + TotWaitTime: s.execDetails.TimeDetail.WaitTime, + } +} + // CopTasksDetails collects some useful information of cop-tasks during execution. type CopTasksDetails struct { NumCopTasks int @@ -535,6 +554,17 @@ type CopTasksDetails struct { TotBackoffTimes map[string]int } +// CopTasksSummary collects some summary information of cop-tasks for statement summary. +type CopTasksSummary struct { + NumCopTasks int + MaxProcessAddress string + MaxProcessTime time.Duration + TotProcessTime time.Duration + MaxWaitAddress string + MaxWaitTime time.Duration + TotWaitTime time.Duration +} + // ToZapFields wraps the CopTasksDetails as zap.Fileds. func (d *CopTasksDetails) ToZapFields() (fields []zap.Field) { if d == nil || d.NumCopTasks == 0 { diff --git a/pkg/util/stmtsummary/statement_summary.go b/pkg/util/stmtsummary/statement_summary.go index 297eefa33f345..52ad1e2845f40 100644 --- a/pkg/util/stmtsummary/statement_summary.go +++ b/pkg/util/stmtsummary/statement_summary.go @@ -250,7 +250,7 @@ type StmtExecInfo struct { ParseLatency time.Duration CompileLatency time.Duration StmtCtx *stmtctx.StatementContext - CopTasks *execdetails.CopTasksDetails + CopTasks *execdetails.CopTasksSummary ExecDetail execdetails.ExecDetails MemMax int64 DiskMax int64 diff --git a/pkg/util/stmtsummary/statement_summary_test.go b/pkg/util/stmtsummary/statement_summary_test.go index f07ce4ad86c8a..af2070633dd0d 100644 --- a/pkg/util/stmtsummary/statement_summary_test.go +++ b/pkg/util/stmtsummary/statement_summary_test.go @@ -182,15 +182,11 @@ func TestAddStatement(t *testing.T) { TotalLatency: 20000, ParseLatency: 200, CompileLatency: 2000, - CopTasks: &execdetails.CopTasksDetails{ + CopTasks: &execdetails.CopTasksSummary{ NumCopTasks: 20, - AvgProcessTime: 2000, - P90ProcessTime: 20000, MaxProcessAddress: "200", MaxProcessTime: 25000, TotProcessTime: 40000, - AvgWaitTime: 200, - P90WaitTime: 2000, MaxWaitAddress: "201", MaxWaitTime: 2500, TotWaitTime: 40000, @@ -334,15 +330,11 @@ func TestAddStatement(t *testing.T) { TotalLatency: 1000, ParseLatency: 50, CompileLatency: 500, - CopTasks: &execdetails.CopTasksDetails{ + CopTasks: &execdetails.CopTasksSummary{ NumCopTasks: 2, - AvgProcessTime: 100, - P90ProcessTime: 300, MaxProcessAddress: "300", MaxProcessTime: 350, TotProcessTime: 200, - AvgWaitTime: 20, - P90WaitTime: 200, MaxWaitAddress: "301", MaxWaitTime: 250, TotWaitTime: 40, @@ -655,15 +647,11 @@ func generateAnyExecInfo() *StmtExecInfo { TotalLatency: 10000, ParseLatency: 100, CompileLatency: 1000, - CopTasks: &execdetails.CopTasksDetails{ + CopTasks: &execdetails.CopTasksSummary{ NumCopTasks: 10, - AvgProcessTime: 1000, - P90ProcessTime: 10000, MaxProcessAddress: "127", MaxProcessTime: 15000, TotProcessTime: 10000, - AvgWaitTime: 100, - P90WaitTime: 1000, MaxWaitAddress: "128", MaxWaitTime: 1500, TotWaitTime: 1000, diff --git a/pkg/util/stmtsummary/v2/record.go b/pkg/util/stmtsummary/v2/record.go index dedcf017ff3e8..62e011874f384 100644 --- a/pkg/util/stmtsummary/v2/record.go +++ b/pkg/util/stmtsummary/v2/record.go @@ -623,14 +623,10 @@ func GenerateStmtExecInfo4Test(digest string) *stmtsummary.StmtExecInfo { TotalLatency: 10000, ParseLatency: 100, CompileLatency: 1000, - CopTasks: &execdetails.CopTasksDetails{ + CopTasks: &execdetails.CopTasksSummary{ NumCopTasks: 10, - AvgProcessTime: 1000, - P90ProcessTime: 10000, MaxProcessAddress: "127", MaxProcessTime: 15000, - AvgWaitTime: 100, - P90WaitTime: 1000, MaxWaitAddress: "128", MaxWaitTime: 1500, },