SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Execution Time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

LopakaB
Starting Member

USA
22 Posts

Posted - 02/12/2013 :  17:35:26  Show Profile  Reply with Quote
I have a sp with many steps within it... I am baffled at the duration it takes to run for the following reason:
I run the sql from beginning to end, it takes over an hour.
I run the sql to a certain Insert Statement. Then run the insert statement by it self it runs in four minutes...
Any help would be appreciated...

Lopaka

James K
Flowing Fount of Yak Knowledge

3578 Posts

Posted - 02/12/2013 :  17:47:46  Show Profile  Reply with Quote
When you run separately, they are run in two batches. It may be that when you run them together (which is in a single batch), the query plan is different.

Examine the query plans in both cases and see if the combined plan is equivalent to the plans for the two-step execution stacked together. Also, in the single query plan, see which steps take long time. For those steps that consume long time, add a statement level recompilation hint. for example if it is an insert statement
INSERT INTO TheTable (col1, col2) values (1,2) OPTION(RECOMPILE)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000