Groups | Blog | Home
all groups > sql server programming > july 2004 >

sql server programming : Poor performance when executing stored procedure



Daniel Walzenbach
7/21/2004 11:46:01 PM
Hi,

I have a stored procedure which simply does a

Select count(*) from sometable where ID=@SomeID

whereas @SomeID is a parameter of this sp. Since the table is tiny (5 rows) and only has a couple of columns execution should be pretty fast. Oddly though it takes the sp almost 2-3 sec. return the result. Does anybody know what could be the reason for this behaviour? It seems that query analyser waits a bit before executing the sp. I understand that the optimizer has to compile the sp first, put it into its memory and than is able to execute to sp. Is there any possibility that sql server got confused and wants to compile the sp before every execution?
Do you have any idea what else could be the reason for this strange behaviour?

Thank you! Best regards

John Bell
7/22/2004 1:00:05 AM
Hi

Posting DDL and the actual procedure would help in answering the question. You seem to think that the procedure is being recompiled. You could see this in profiler. Prefixing the stored procedure call and the tables within the stored procedure with their owner may help, using a local variable to copy your parameter may also help.
You may also want to look at the query execution plan.

It may also be a blocking problem, again profiler could help out.

John

[quoted text, click to view]
v-mingqc NO[at]SPAM online.microsoft.com (
7/22/2004 8:48:03 AM
Hi Daniel,

From your descriptions, I understood that your concerns are your simple SELECT statement
will cost 2-3 seconds. Have I understood you? If there is anything I misunderstood, please feel
free to let me know.

First of all, SQL Server is on your local server or remote server? If you link SQL Server by
means of network, it may be an network performance issue. Does that server has a heavily
workload? If so, I think bottle-neck of hardware may lead to this kind of latency.

Secondly, we could do the following trying to find more detailed information about it
1. Use Estimated Execution Plan(write the statement and then press <Ctrl> + <L>)
Detailed information about who are causing the performance is shown

2. Use Profiler, tracing whether there will be any other statements run before your simple
SELECT query

Thank you for your patience and cooperation. If you have any questions or concerns, don't
hesitate to let me know. We are here to be of assistance!


Sincerely yours,

Mingqing Cheng
Microsoft Developer Community Support
---------------------------------------------------------------
Introduction to Yukon! - http://www.microsoft.com/sql/yukon
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!

Gert-Jan Strik
7/22/2004 11:44:50 AM
If there is no blocking going on, then this query (with your
description) should return instantaneous.

1. If the query

select count(*) from sometable (NOLOCK) where id=@SomeID

returns immediately, then you might be looking at a locking problem.

2. If the query

select count(*) from sometable where id=@SomeID OPTION(MAXDOP 1)

returns immediately, you might have hit the parallelism bug

3. the last interesting one would be

select count(*) from sometable (INDEX=0) where id=@SomeID


By the way: does your table by any chance have a nonclustered index, but
no clustered index? Just checking...

Hope this helps,
Gert-Jan



[quoted text, click to view]

--
AddThis Social Bookmark Button