• Jeff Moden (10/12/2012)


    Mahesh Bote (10/12/2012)


    [font="Verdana"]Hi All,

    I have one Stored Procedure which frequently gets executed. Though it is a straight forward Stored Procedure with one select statement and one delete statement, its causing major blocking. While investigation for the possible optimization, I could found only one area where I was thinking to introduce Explicit Transaction for Delete statement.

    Can anybody explain, introducing Explicit Transaction will be beneficial in terms of performance improvement. I browse through net, however could not get any solid explanation to justify myself on my above assumption.

    Please clarify.

    Thanks in advance,

    -- Mahesh

    [/font]

    I strongly suspect that adding an explicit transaction would change the blocking that's occurring into deadlocks and, thus, is not the answer.

    Actually that depends on how the stored procedure is being called. It's quite possible (even quite likely) that the whole proc is running as a single transaction imposed by the calling mechanism (ADO used to do that, for example) and that may be far too coarse a grain transaction. In such a case it may make sense to commit the externally imposed transaction right at the start of the proc, use explicit transactions inside it to get the right granularity, and leave a transaction open on exit so that the calling mechanism doesn't throw uop its hands in horror because the @@trancount has changed. Of course it makes absolutely no sense to do this unless you know exactly what is calling the proc and know that committing at the beginning of the transaction is not screweing up concurrency control (ie know that your idea of the required garnularity is correct in terms of the whole app, not just the proc).

    The only way to fix this type of thing is to make the query and the delete run fast and use as few resources as possible. The only way for us to help you do that is to read the article at the second link in my signature line and provide the things requested in that article about this problem.

    That's certainly the first thing to do - make it all run fast and the problem will probably go away.

    Tom