SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Traces question


Traces question

Author
Message
PiMané
PiMané
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2936 Visits: 1351
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



If you need to work better, try working less...
Attachments
proc0_proc1_times.xlsx (13 views, 10.00 KB)
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38172 Visits: 9274
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.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
PiMané
PiMané
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2936 Visits: 1351
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



If you need to work better, try working less...
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38172 Visits: 9274
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?

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
PiMané
PiMané
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2936 Visits: 1351
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



If you need to work better, try working less...
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38172 Visits: 9274
Is it something you can start removing bit by bit as you look at this stuff?

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
PiMané
PiMané
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2936 Visits: 1351
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



If you need to work better, try working less...
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38172 Visits: 9274
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.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
PiMané
PiMané
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2936 Visits: 1351
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



If you need to work better, try working less...
Brandie Tarvin
Brandie Tarvin
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38172 Visits: 9274
OUCH!

I feel for you. I really do.

Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search