|
Posted by Erland Sommarskog on 02/20/07 22:32
(teddysnips@hotmail.com) writes:
> 10/10! I dropped the SPROC, then recreated it identically and it ran
> like a greyhound. So all it needed was recompilation. I guess
> there's an art to knowing how often/in what circumstances to recompile
> SPROCs but I'm a developer, not a DBA so I don't know!
You don't even have to drop the procedure, it sufficient to say:
sp_recompile procname
to flush all plans of it out the cache.
Normally, this is not needed, but SQL Server has this feature known as
parameter sniffing. When the optimizer builds the plan on the first
invocation, it looks at the actual parameter values and takes this as
guidance. But if that first invocation is for an untypical value, that
may buy you a plan which is bad for regular input.
This is not the only reason for a this sort of behaviour. It can also
be that the statistics are such that the optimizer's estimates for
two plans are very close, although one of the plans are not good at all.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|