Re: Poor performance when executing stored procedure
From: Daniel Walzenbach (daniel.walzenbach.NOSPAM_at_freudenberg.de)
Date: 07/22/04
- Next message: Aaron [SQL Server MVP]: "Re: ASP/ADO: Return a value from a Stored Procedure"
- Previous message: Ilya Margolin: "Re: EXCEPTION_ACCESS_VIOLATION wher inserting to a Table with INSTEAD OF INSERT Trigger"
- In reply to: Gert-Jan Strik: "Re: Poor performance when executing stored procedure"
- Next in thread: Bill Cheng: "Re: Poor performance when executing stored procedure"
- Reply: Bill Cheng: "Re: Poor performance when executing stored procedure"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Jul 2004 06:03:02 -0700
Hello,
Thank you all for your help. Unfortunately I have to confess that I tried to simplify the problem and misdirected you all. As a matter of fact I have a couple of sp which are all responsible for a business object. E.g. there are sps like spCustomer, spOrders, spRequest whereas each handles everything for one business object. Those sp therefore tend to grow really big. By now I understand (or at least this is how I could explain myself this behavior) that the sql optimizer tries to optimize the whole sp instead of only the exact part of the sp I want to execute (there might be a part in the sp to create a customer while another part selects customer details or searches for orders belonging to one customer). Additionally which is even worse those sps can execute each other. I now assume that the sql optimizer tried to compile lets say spCustomer, was busy analysing a whole bunch of stuff which wasn’t necessary for the query to perform, then executed spOrders which is executed in spCustomers and then got stuc
k in a loop.
By now I assume that I have to split my sps in smaller batches of sql which only do what they are supposed to do. Whereas spOrders allowed me to create orders, update or search them I should now create a spOrderCreate, a spOrderUpdate and a spOrderSearch. Could you recommend this approach? I got used to the other since it was kind of “how it is done here” and I just accepted it without scrutinizing. What would be best practices on how to write sps more efficiently? I assume I just got one: Do only what really is necessary in one sp, am I right?
Best regards and thanks again for your help!
Daniel
"Gert-Jan Strik" wrote:
> 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
>
>
>
> Daniel Walzenbach wrote:
> >
> > 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
> >
> > Daniel
>
> --
> (Please reply only to the newsgroup)
>
- Next message: Aaron [SQL Server MVP]: "Re: ASP/ADO: Return a value from a Stored Procedure"
- Previous message: Ilya Margolin: "Re: EXCEPTION_ACCESS_VIOLATION wher inserting to a Table with INSTEAD OF INSERT Trigger"
- In reply to: Gert-Jan Strik: "Re: Poor performance when executing stored procedure"
- Next in thread: Bill Cheng: "Re: Poor performance when executing stored procedure"
- Reply: Bill Cheng: "Re: Poor performance when executing stored procedure"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|