October 12, 2012 at 3:47 am
[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 browsed through net, however could not got any solid explanation to justify myself on my above assumption.
Please clarify.
Thanks in advance,
-- Mahesh
[/font]
MH-09-AM-8694
October 12, 2012 at 3:50 am
Can you post the code, Mahesh? Also, if you can, the actual execution plans?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 12, 2012 at 7:19 am
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.
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
Change is inevitable... Change for the better is not.
October 15, 2012 at 4:17 am
Mahesh Bote (10/12/2012)
[font="Verdana"]one delete statement, its causing major blocking.[/font]
Why ? is it deleting the high volumned data here ?
Mahesh Bote (10/12/2012)
[font="Verdana"]While investigation for the possible optimization, I could found only one area where I was thinking to introduce Explicit Transaction for Delete statement.[/font]
certainly NOT
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
October 16, 2012 at 7:21 am
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 on googles mail service
October 16, 2012 at 1:51 pm
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
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply