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


Explicit Transaction to improve performance?


Explicit Transaction to improve performance?

Author
Message
Mahesh Bote
Mahesh Bote
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5515 Visits: 1303
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
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)

Group: General Forum Members
Points: 96866 Visits: 20698
Can you post the code, Mahesh? Also, if you can, the actual execution plans?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)SSC Guru (507K reputation)

Group: General Forum Members
Points: 507799 Visits: 44277
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Bhuvnesh
Bhuvnesh
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32364 Visits: 4079
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----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
TheSQLGuru
TheSQLGuru
SSC Guru
SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)SSC Guru (76K reputation)

Group: General Forum Members
Points: 76897 Visits: 8874
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
Tom Thomson
Tom Thomson
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50700 Visits: 13159
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

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