Look, it’s impressive enough that sp_WhoIsActive works as well as it does. Most people who’ve been using it for a while are familiar with using @get_plans to retrieve query plans, or @get_locks to see locking information. I’m gonna spend a couple posts talking about less well known flags that I really like.
We’re gonna start off with one that can help you figure out if a particular query is misbehaving, or if things are just cruising along normally.
I’ve got a stored procedure. What it does is unimportant. What’s important is that it’s sensitive to parameter sniffing.
We may not know this walking into an emergency, but we can figure it out pretty quickly using sp_WhoIsActive.
EXEC sp_WhoIsActive @get_avg_time = 1;
This’ll give us back the usual information about how long our query has been running, but now right next to it is another column that ends in (avg).
When you use this switch, sp_WhoIsActive goes into the plan cache and looks at how long a particular query runs for on average.
If that number is much lower than how long the query has been running for, and it isn’t being blocked, you just might have a case of parameter sniffing on your hands.
Thanks for reading!
If this is the kind of SQL Server stuff you love learning about, you’ll love my training. I’m offering a 75% discount to my blog readers if you click from here. I’m also available for consulting if you just don’t have time for that and need to solve performance problems quickly.