Solved

SQL Execution Plan

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 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

18 Experts available now in Live!

Get 1:1 Help Now