Traces question

  • 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...

  • 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/[/url]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.

  • 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...

  • 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/[/url]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.

  • 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...

  • 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/[/url]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.

  • 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...

  • 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/[/url]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.

  • 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...

  • OUCH!

    I feel for you. I really do.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]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.

  • 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



    If you need to work better, try working less...

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply