sp_whoisactive: "Planning" for Success

Home ... Documentation ... Downloads
Prior: Commands, Batches, and the Mysteries of Text .... Next: The Almighty Transaction

Viewing the text of the currently running statement is a big part of the debugging battle. Another part is being able to quickly see the associated query plan.

Due to performance concerns Who is Active does not show the query plan by default; plans for big queries can sometimes span several megabytes of XML, so accessing the plan can be expensive. Enabling plan retrieval is simple: Use the @get_plans option.

@get_plans has two modes:

These settings align, more or less, with the default statement text retrieval mode and the @get_full_inner_text option.

Consider the following batch:

SELECT
    *
FROM sys.databases

WAITFOR DELAY '10:10:10'

SELECT
    *
FROM sys.tables
GO

Running this, then running Who is Active with @get_plans set to 1, results in the addition of the [query_plan] column to the output:

F11_01_xml_plan

The query plan is an XML showplan, and the next step for seeing the graphical version of the plan is to click on the XML instance. This will bring up a new tab in Management Studio, but what happens next depends on which version of SSMS you’re running. If you’re still using the SQL Server 2005 version, you’ll be greeted with a screen full of XML:

F11_02_xml

To see the plan rendered in a nice graphical format, save the XML to a file with the .SQLPLAN extension, close the file in Management Studio, then re-open it. Or, if you’re using the SQL Server 2008 version of Management Studio, forget all of the XML file stuff and just click. Either way you’ll be greeted with:

F11_02_graphic

The other option is to see the plan for the entire batch. Or, phrased another way, all of the plans for each of the statements in the batch. It’s as easy as...

EXEC sp_WhoIsActive
     @get_plans = 2

F11_02_full

Notes


Prior: Commands, Batches, and the Mysteries of Text .... Next: The Almighty Transaction
(C) 2017 Adam Machanic