Skip to content

Commit

Permalink
sessionphase: fix service latency computation in an error case
Browse files Browse the repository at this point in the history
If we encounter an error during the logical planning, then the end
execution phase is never set. Previously, we would use that unset value
in order to compute the latency of planning and execution and would get
a negative result. This is now fixed.

Release note: None
  • Loading branch information
yuzefovich committed Nov 5, 2021
1 parent ed35bbe commit 2257e81
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/sql/sessionphase/session_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ func (t *Times) GetServiceLatencyNoOverhead() time.Duration {
queryReceivedTime = t.times[SessionQueryReceived]
}
parseLatency := t.times[SessionEndParse].Sub(queryReceivedTime)
planAndExecuteLatency := t.times[PlannerEndExecStmt].Sub(t.times[PlannerStartLogicalPlan])
// If we encounter an error during the logical planning, the
// PlannerEndExecStmt phase will not be set, so we need to use the end of
// planning phase in the computation of planAndExecuteLatency.
var queryEndExecTime time.Time
if t.times[PlannerEndExecStmt].IsZero() {
queryEndExecTime = t.times[PlannerEndLogicalPlan]
} else {
queryEndExecTime = t.times[PlannerEndExecStmt]
}
planAndExecuteLatency := queryEndExecTime.Sub(t.times[PlannerStartLogicalPlan])
return parseLatency + planAndExecuteLatency
}

Expand Down

0 comments on commit 2257e81

Please sign in to comment.