Solved

SQL Execution Plan

Posted on 2011-10-01
4
317 Views
Last Modified: 2012-05-12
Is it possible to view the execution plan of a running stored procedure? We have an SP that used to run fairly in under 30 minutes (which was fine given the massive job it performed) but since partitioning was introduced to one of the tables last week, it takes over 6 hours to run.

I need a way to see the execution plan while the SP is running. Is this possible?

thanks,
Dean
0
Comment
Question by:dthansen
4 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36896609
If you are meaning while it is actually running, you may be talking about profiling it. However, you may be able to figure this out based on your knowledge of the system as you have a correlation with a recent change, i.e., if you introduced partitioning, I would look at what field you partitioned on in conjunction with the data you are querying. If your queries are having to ALWAYS span all the partitions, then the benefits of partitioning may be lost and actually a huge overhead as you are seeing.

This might be a good read:
http://blogs.technet.com/b/josebda/archive/2009/03/19/sql-server-2008-partitioning.aspx
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 36896613
Assuming the procedure runs periodically as a job, first disable this job.

Then open a new query in Management Studio, and on the menu select Query / Show Actual Execution Plan

Then run the procedure manually in this window:

  exec  my_spname  [params]

Then you can view the execution plan of the running procedure (or the actual plan after it runs).

Don't forget to re-enable the job after this!  :)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36896898
In the strict sense the answer to your question is no.  But it is more involved than just looking at the execution plan even if it was available while running.  If as I suspect the Stored Procedure is complex with multiple queries you need to do identify the query or queries that are taking a long time.  This can and should be done while running with something like Adam Machanic's sp_WhoIsActive script.  But in order to do this you may need a baseline of what it used be like and I am not sure if this is available to you.
0
 
LVL 18

Expert Comment

by:lludden
ID: 36899581
Your SP may be trying to use an old execution plan.  Try using /RECOMPILE on it and see if that fixes the problem.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question