Question

In the output of sp_WhoIsActive, are columns such as reads, writes, CPU, and wait_info cumulative for the session, or just cumulative for the batch? We have a query that is blocking a lot and showing millions of reads, but when I run the eight queries in the batch from SSMS, the reads are in the single digits, so I'm trying to understand whether something different is occurring with the way the application is running it to cause it to read so much more.

Or could it be something different? I notice that the session has 2 open transactions. Could those stats represent all of the transactions that session currently has active?

Was it helpful?

Solution

sp_WhoIsActive reports reads, writes, and CPU at the batch level as opposed to the session level. This is something that can be tested.

Session ID 57 has the following code in just a single batch:

SELECT MAX(t1.high + t2.high)
FROM master..spt_values t1
CROSS JOIN master..spt_values t2
OPTION (MAXDOP 1);

WAITFOR DELAY '00:01:00';

Session ID 56 has the same code but split into two batches:

SELECT MAX(t1.high + t2.high)
FROM master..spt_values t1
CROSS JOIN master..spt_values t2
OPTION (MAXDOP 1);

GO

WAITFOR DELAY '00:01:00';

Here's a screenshot of sp_whoisactive after both sessions have been running for a few seconds:

enter image description here

As you can see, those columns reset in session ID 56 because GO defines a new batch.

Waits aren't at the batch or the session level. It's a real time snapshot of what's happening with the query. It's not uncommon to see the wait_info column change wait types or durations while a query is executing.

Your final question is a bit too general for me to attempt an answer, but you could try reading through this resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top