1

I've got some SQL which I've run several times a day in development, generally getting execution time of 3-8 minutes.

Now I've wrapped it in a stored procedure (with no parameters), the performance is impossible. THe first "heavy" statement, which involves only c.27k rows, never finishes.

Actual execution plan is not an option, because I can't even get this statement to finish. So I have to look at estimated execution plan.

Trouble is I get a separate "sub-pane" in the Execution Plan pane for every statement. I can't comment out preceding statements as they're necessary for the problem statement to run (though I've commented out all following statements).

How can I view just the plan for the problem statement on-screen? It's obviously a huge plan. All the other statements' plans (which I'm not interested in) take up an enormous amount of screen space, so it's impossible to scroll through the important one and find the chokepoints. But there seems to be now way to "Show just the plan for this statement, and take up the full screen".

Am I missing something?

1
  • Many people (including myself) use a 3rd party tool for this purpose, mostly due to the deficiencies you've found.
    – Jacob H
    Commented Jan 22, 2020 at 17:17

2 Answers 2

2

I don't think there's a way to do that in SSMS.

You should use Sentry One Plan Explorer for this. It's a free tool that provides an alternative way of viewing SQL Server execution plans.

I've run this code on my local copy of the Stack Overflow 2010 sample database:

CREATE PROCEDURE #sp_TestQuery
AS
SELECT COUNT_BIG(*) FROM dbo.Users u WHERE u.Id > 10;
SELECT MAX(p.CommentCount) FROM dbo.Posts p WHERE p.Id > 1000;
SELECT MIN(v.BountyAmount) FROM dbo.Votes v WHERE v.Id > 100000;
GO

EXEC #sp_TestQuery;

Running the EXEC... line produces the problem you mentioned in SSMS:

screenshot of default results in SSMS

One option I have here is to at least resize the different panes, by dragging the border between them. If I wanted to mostly see the middle query:

screenshot of resizing execution plan panes in SSMS

But that's still not ideal. The default view in Plan Explorer shows me a list of statements at the top, and I can click on each statement to view the graphical plan below it. Here's the middle query in Plan Explorer:

screenshot of per-statement plan view in Plan Explorer

1
  • 1
    Thanks, I'll take a look at that. Good to know that there simply is not a way to do this in SSMS.
    – SebTHU
    Commented Jan 24, 2020 at 15:17
1

There IS a way.

  • In SSMS set Include Actual Exec Plan (Ctrl-M)
  • SET STATISTICS XML OFF; in first statement of batch
  • Wrap the statement in question like:
    SET STATISTICS XML ON;
    statement(s)
    SET STATISTICS XML OFF;

Even works within stored procs.

1
  • Can you add an example to improve the answer? Commented Apr 19 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.