Commit 40c3fe49 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Fix latency calculation when there are \sleep commands in the script.

We can't use txn_scheduled to hold the sleep-until time for \sleep, because
that interferes with calculation of the latency of the transaction as whole.

Backpatch to 9.4, where this bug was introduced.

Fabien COELHO

Discussion: <alpine.DEB.2.20.1608231622170.7102@lancre>
parent 6cc54f38
...@@ -250,6 +250,7 @@ typedef struct ...@@ -250,6 +250,7 @@ typedef struct
int nvariables; /* number of variables */ int nvariables; /* number of variables */
bool vars_sorted; /* are variables sorted by name? */ bool vars_sorted; /* are variables sorted by name? */
int64 txn_scheduled; /* scheduled start time of transaction (usec) */ int64 txn_scheduled; /* scheduled start time of transaction (usec) */
int64 sleep_until; /* scheduled start time of next cmd (usec) */
instr_time txn_begin; /* used for measuring schedule lag times */ instr_time txn_begin; /* used for measuring schedule lag times */
instr_time stmt_begin; /* used for measuring statement latencies */ instr_time stmt_begin; /* used for measuring statement latencies */
int use_file; /* index in sql_scripts for this client */ int use_file; /* index in sql_scripts for this client */
...@@ -1830,6 +1831,7 @@ top: ...@@ -1830,6 +1831,7 @@ top:
} }
} }
st->sleep_until = st->txn_scheduled;
st->sleeping = true; st->sleeping = true;
st->throttling = true; st->throttling = true;
st->is_throttled = true; st->is_throttled = true;
...@@ -1842,7 +1844,7 @@ top: ...@@ -1842,7 +1844,7 @@ top:
{ /* are we sleeping? */ { /* are we sleeping? */
if (INSTR_TIME_IS_ZERO(now)) if (INSTR_TIME_IS_ZERO(now))
INSTR_TIME_SET_CURRENT(now); INSTR_TIME_SET_CURRENT(now);
if (INSTR_TIME_GET_MICROSEC(now) < st->txn_scheduled) if (INSTR_TIME_GET_MICROSEC(now) < st->sleep_until)
return true; /* Still sleeping, nothing to do here */ return true; /* Still sleeping, nothing to do here */
/* Else done sleeping, go ahead with next command */ /* Else done sleeping, go ahead with next command */
st->sleeping = false; st->sleeping = false;
...@@ -2141,7 +2143,7 @@ top: ...@@ -2141,7 +2143,7 @@ top:
usec *= 1000000; usec *= 1000000;
INSTR_TIME_SET_CURRENT(now); INSTR_TIME_SET_CURRENT(now);
st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec; st->sleep_until = INSTR_TIME_GET_MICROSEC(now) + usec;
st->sleeping = true; st->sleeping = true;
st->listen = true; st->listen = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment