Solved

SQL Execution Plan

Posted on 2011-10-01
4
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 60

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

617 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