October 1, 2013 at 3:49 am
Hi,
I'm running a server trace to determine where the procedures take more time to execute.
I'm tracking events 10, 12, 43 and 45.
My procedures call lots of other procedures but my main question is: shouldn't the sum of the time taken inside a procedure (ObjectType = 'procedure name') be the same as the time taken by it's execution (TextData LIKE 'EXEC procedure name')?
The procedure proc0 calls proc1 and the sum of proc1 takes 0,23ms (event 45 and objectype = 'proc1'). but event 43 of proc1 takes 5ms...
Is the difference from SQL "loading" and parsing proc1? proc1 is already in cache so no time to do that should be taken...
Why does this happen?
Thanks,
Pedro
October 2, 2013 at 8:57 am
I'm not sure I'm clear on this...
Proc 0 is taking less time than Proc 1, right?
Nothing else happens in Proc 0 except that EXEC statement, right?
In which case this makes total sense to me because all Proc 0 does is send the call and then end execution. Proc 0 isn't using any of its resources after it sends the call and Proc 1 requires time to execute.
But if I'm misreading your post, please let me know.
October 2, 2013 at 9:06 am
Brandie Tarvin (10/2/2013)
I'm not sure I'm clear on this...Proc 0 is taking less time than Proc 1, right?
Nothing else happens in Proc 0 except that EXEC statement, right?
In which case this makes total sense to me because all Proc 0 does is send the call and then end execution. Proc 0 isn't using any of its resources after it sends the call and Proc 1 requires time to execute.
But if I'm misreading your post, please let me know.
That's it...
The start time in proc1 statement "EXEC proc0" and proc0 1st execution aren't the same.
That difference is the time SQL takes to "load" proc0 so it can be executed?
Pedro
October 2, 2013 at 10:29 am
They are two totally different stored procedures. You shouldn't be looking at their execution times collectively. Proc 0 will always take less time than Proc 1 because the only thing it does is say "Hey, SQL Server, Run this other guy."
Which is a very weird way of doing things. Why aren't you just calling Proc 1 straight instead?
October 2, 2013 at 10:48 am
The code was written by c# programmers so it has loads of "modularity" so it can be used on several operations...
For example, proc0 is launch sales document and proc1 is validate document type that's also used when launching purchases documents...
The time "wasted" on calling other SPs from inside other SPs is huge... in the end over 50 different procs are called...
Pedro
October 2, 2013 at 11:56 am
Is it something you can start removing bit by bit as you look at this stuff?
October 2, 2013 at 1:10 pm
It's what I'm trying to do...
So far I'm removing cursors and other bad programmer's habits from sql server...
Do to the procedures design (call Sps from Sps) it has a lot of cursors.
Also some UPDATE statements do lock to themselves and other things...
Pedro
October 3, 2013 at 5:19 am
Remember, not all cursors are bad. Some of them are necessary, and some of them can be faster than regular WHILE loops or other code. It just depends on the cursor.
But definitely exam each one of them to determine just how necessary they are.
October 3, 2013 at 5:28 am
Brandie Tarvin (10/3/2013)
Remember, not all cursors are bad. Some of them are necessary, and some of them can be faster than regular WHILE loops or other code. It just depends on the cursor.
No while loops here... Just to give you an example of what I've found, there's a trigger on a table ProductStore that has for each product the quantity on a store.
The update/insert/delete triggers call a SP that updates quantity on the Products table. But does it using a cursor to go over the INSERTED and DELETED records an calls the procedure updateProductQuantity @product, @newquantity, @type (delete or add).
This can be replaced inside the trigger with
UPDATE Produts SET Qnt = Qnt + t.Qnt FROM (SELECT Product, SUM(Qnt) Qnt FROM INSERTED GROUP BY Product) t WHERE t.Product = Products.Product
and the same with DELETED...
No need to go over each record in INSERTED and DELETED and call a procedure...
Thanks,
Pedro
October 3, 2013 at 6:14 am
OUCH!
I feel for you. I really do.
October 3, 2013 at 6:35 am
Brandie Tarvin (10/3/2013)
OUCH!I feel for you. I really do.
Thanks 🙂
It fells like I just went back to preschool when I look at the code 🙂
Pedro
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply