Groups | Blog | Home
all groups > sql server (alternate) > april 2004 >

sql server (alternate) : this is driving me nuts - solicit help from the gurus


praty77-google NO[at]SPAM yahoo.com
4/6/2004 4:36:37 PM
Hi -
I hope some one can help me with this.

I am using sql server 2000
[Microsoft SQL Server 2000 - 8.00.818 (Intel X86) May 31 2003
16:08:15 Copyright (c) 1988-2003 Microsoft Corporation Enterprise
Edition on Windows NT 5.0 (Build 2195: Service Pack 4)]

I have a stored procedure that is using cursors and a few joins, and
writes to a few tables. (I can post the code if that will help) The
stored procedure takes approximately 27 seconds to complete when
executed inside query analyser. However, if I run the stored procedure
source directly inside query analyser (like a long sql script), it
takes only 3 seconds!! These results are consistent and reproducible.

I would think a stored procedure stores the plan, and I would expect
better optimization. Why am I witnessing the opposite behaviour? Any
one has any experience?

The server is manned by DBAs (I work at a large corporation), so I
believe it is well configured. We have noticed similar behaviour on
data restores on a different physical server.

Thanks in advance,
Wangkhar NO[at]SPAM yahoo.com
4/7/2004 1:13:08 AM
Could be a long shot but try adding a with recompile to the stored
proc and updating the stats on the tables.


[quoted text, click to view]
sql NO[at]SPAM hayes.ch
4/7/2004 2:02:29 AM
[quoted text, click to view]

One possible explanation for this is parameter sniffing:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=uln5kiSpBHA.2088%40tkmsftngp03

praty77-google NO[at]SPAM yahoo.com
4/7/2004 9:17:36 AM
Simon -
thanks.
I do not think that explains the 10 times performance problem in my
case. I am not using any default parameters.

Any other thoughts?
praty77
[quoted text, click to view]
masri NO[at]SPAM vsnl.com
4/8/2004 11:30:05 PM
Introduce
SET NOCOUNT ON if it is not present .

If you are running SP as a query and substituting parametes of the SP
with constant values in the code , execution will be faster .

Srinivas


[quoted text, click to view]
praty77-google NO[at]SPAM yahoo.com
4/15/2004 1:07:12 PM
srini -
thanks.
The fact is ... it is 10 times slower. And sporadically the speed
problem disappears. I do not think that is an issue... it appears it
is some database internals problem (proc overhead too high). I am
hoping someone can help!

praty
[quoted text, click to view]
AddThis Social Bookmark Button