Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SP compilation time

Author  Topic 

shaggy
Posting Yak Master

248 Posts

Posted - 2014-01-28 : 09:34:52
Hi,
SP is taking more time for compilation.SP has 30 update statement all are using indexed column in where clause.
how can i force SP to take less compilation time.

pls advice

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-01-28 : 10:20:38
One of the things that causes a recompile is when a significant change in the statistics occurs - like from updates. What I would do if you haven't already is run a profiler trace with one of the events being SP:Recompile. That way you can confirm that the procedure is being recompiled one or more times during execution. If that is the case you can use a query hint to suppress the recompiles. From books online (query hints):
quote:
KEEPFIXED PLAN

Forces the query optimizer not to recompile a query due to changes in statistics. Specifying KEEPFIXED PLAN makes sure that a query will be recompiled only if the schema of the underlying tables is changed or if sp_recompile is executed against those tables.



EDIT:
of course this are obvious repercussions with this - maybe the optimizer should change plans based on the latest statistics.

Be One with the Optimizer
TG
Go to Top of Page

shaggy
Posting Yak Master

248 Posts

Posted - 2014-01-29 : 00:29:59
Thanks TG,

But the second time my SP execution is fast due to already plan avaible in cache.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-29 : 04:06:11
quote:
Originally posted by shaggy

Thanks TG,

But the second time my SP execution is fast due to already plan avaible in cache.


yep..once plan is in cacahe sp will execute faster


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

shaggy
Posting Yak Master

248 Posts

Posted - 2014-01-29 : 04:14:42
So can I freeze plan in cache so that evertime i execute Sp it will be faster.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-01-29 : 10:07:51
It is sounding more like the data is cached for subsequent runs. Why did you believe that the time is taken for execution plan compilation? If you run the trace I suggested you will know how the time is divided between recompiles vs. statement duration.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -