Skip to content

Commit

Permalink
execstats: fix query level contention time calculation
Browse files Browse the repository at this point in the history
Previously, we were using an incorrect map to calculate the contention
time.

Release note: None
  • Loading branch information
yuzefovich committed Feb 4, 2021
1 parent 0ffebdb commit 6c8dd8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/execstats/traceanalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (a *TraceAnalyzer) ProcessStats() error {
a.queryLevelStats.NetworkMessages += networkMessages
}

for _, contentionTime := range a.nodeLevelStats.KVTimeGroupedByNode {
for _, contentionTime := range a.nodeLevelStats.ContentionTimeGroupedByNode {
a.queryLevelStats.ContentionTime += contentionTime
}
return errs
Expand Down
21 changes: 12 additions & 9 deletions pkg/sql/execstats/traceanalyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ func TestTraceAnalyzer(t *testing.T) {

func TestTraceAnalyzerProcessStats(t *testing.T) {
const (
node1Time = 3 * time.Second
node2Time = 5 * time.Second
cumulativeTime = node1Time + node2Time
node1KVTime = 1 * time.Second
node1ContentionTime = 2 * time.Second
node2KVTime = 3 * time.Second
node2ContentionTime = 4 * time.Second
cumulativeKVTime = node1KVTime + node2KVTime
cumulativeContentionTime = node1ContentionTime + node2ContentionTime
)
a := &execstats.TraceAnalyzer{FlowMetadata: &execstats.FlowMetadata{}}
a.AddComponentStats(
Expand All @@ -199,8 +202,8 @@ func TestTraceAnalyzerProcessStats(t *testing.T) {
1, /* processorID */
),
KV: execinfrapb.KVStats{
KVTime: optional.MakeTimeValue(node1Time),
ContentionTime: optional.MakeTimeValue(node1Time),
KVTime: optional.MakeTimeValue(node1KVTime),
ContentionTime: optional.MakeTimeValue(node1ContentionTime),
},
},
)
Expand All @@ -213,15 +216,15 @@ func TestTraceAnalyzerProcessStats(t *testing.T) {
2, /* processorID */
),
KV: execinfrapb.KVStats{
KVTime: optional.MakeTimeValue(node2Time),
ContentionTime: optional.MakeTimeValue(node2Time),
KVTime: optional.MakeTimeValue(node2KVTime),
ContentionTime: optional.MakeTimeValue(node2ContentionTime),
},
},
)

expected := execstats.QueryLevelStats{
KVTime: cumulativeTime,
ContentionTime: cumulativeTime,
KVTime: cumulativeKVTime,
ContentionTime: cumulativeContentionTime,
}

assert.NoError(t, a.ProcessStats())
Expand Down

0 comments on commit 6c8dd8d

Please sign in to comment.