|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 6:22 AM
Points: 1,074,
Visits: 1,205
|
|
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 browsed through net, however could not got any solid explanation to justify myself on my above assumption.
Please clarify.
Thanks in advance,
-- Mahesh
MH-09-AM-8694
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:00 AM
Points: 5,609,
Visits: 10,971
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 9:57 PM
Points: 32,906,
Visits: 26,790
|
|
Mahesh Bote (10/12/2012) 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
I strongly suspect that adding an explicit transaction would change the blocking that's occurring into deadlocks and, thus, is not the answer.
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.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
Mahesh Bote (10/12/2012) one delete statement, its causing major blocking. Why ? is it deleting the high volumned data here ?
Mahesh Bote (10/12/2012) While investigation for the possible optimization, I could found only one area where I was thinking to introduce Explicit Transaction for Delete statement. certainly NOT
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 3,575,
Visits: 5,115
|
|
If the delete is CAUSING blocking (are you using sp_whoisactive to watch what is going on?), I would look at the following:
1) no index on what you are using for where clause and you are scanning instead of seeking
2) you are deleting lots of rows
3) you have a very slow tlog drive
4) you have foreign keys in play (that are quite possibly unindexed)
5) you have trigger(s) that are gumming up the works with their activity
6) you have a UDF involved
It would be MUCH easier for us to help you if we saw the table script, sproc code and actual execution plan. Statistics IO would be nice too.
Best,
Kevin G. Boles SQL Server Consultant SQL MVP 2007-2012 TheSQLGuru at GMail
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 5:48 PM
Points: 7,088,
Visits: 7,143
|
|
Jeff Moden (10/12/2012)
Mahesh Bote (10/12/2012) 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
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 Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|