Solved

SQL Execution Plan

Posted on 2011-10-01
4
312 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 shrink a transaction log file down to a reasonable size.

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now