Unix Technical Forum

this is driving me nuts - solicit help from the gurus

This is a discussion on this is driving me nuts - solicit help from the gurus within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi - I hope some one can help me with this. I am using sql server 2000 [Microsoft SQL ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:23 AM
Praty77
 
Posts: n/a
Default this is driving me nuts - solicit help from the gurus

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,
-praty77
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 02:23 AM
WangKhar
 
Posts: n/a
Default Re: this is driving me nuts - solicit help from the gurus

Could be a long shot but try adding a with recompile to the stored
proc and updating the stats on the tables.


praty77-google@yahoo.com (Praty77) wrote in message news:<6c19a8f5.0404061536.74ad2c16@posting.google. com>...
> 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,
> -praty77

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 02:24 AM
Simon Hayes
 
Posts: n/a
Default Re: this is driving me nuts - solicit help from the gurus

praty77-google@yahoo.com (Praty77) wrote in message news:<6c19a8f5.0404061536.74ad2c16@posting.google. com>...
> 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,
> -praty77


One possible explanation for this is parameter sniffing:

http://groups.google.com/groups?hl=e...%40tkmsftngp03

Simon
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 02:24 AM
Praty77
 
Posts: n/a
Default Re: this is driving me nuts - solicit help from the gurus

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
sql@hayes.ch (Simon Hayes) wrote in message news:<60cd0137.0404070102.7c6fb9a4@posting.google. com>...
> praty77-google@yahoo.com (Praty77) wrote in message news:<6c19a8f5.0404061536.74ad2c16@posting.google. com>...
> > 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,
> > -praty77

>
> One possible explanation for this is parameter sniffing:
>
> http://groups.google.com/groups?hl=e...%40tkmsftngp03
>
> Simon

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 02:25 AM
M A Srinivas
 
Posts: n/a
Default Re: this is driving me nuts - solicit help from the gurus

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


praty77-google@yahoo.com (Praty77) wrote in message news:<6c19a8f5.0404061536.74ad2c16@posting.google. com>...
> 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,
> -praty77

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 02:30 AM
Praty77
 
Posts: n/a
Default Re: this is driving me nuts - solicit help from the gurus

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
masri@vsnl.com (M A Srinivas) wrote in message news:<f7e90f78.0404082230.7d613bc6@posting.google. com>...
> 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
>
>
> praty77-google@yahoo.com (Praty77) wrote in message news:<6c19a8f5.0404061536.74ad2c16@posting.google. com>...
> > 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,
> > -praty77

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:17 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com