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:
WAITFOR DELAY '10:10:10'
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:
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:
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:
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...
@get_plans = 2