Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Explicit Transaction to improve performance? Expand / Collapse
Author
Message
Posted Friday, October 12, 2012 3:47 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 29, 2014 2:57 AM
Points: 1,098, Visits: 1,222
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
Post #1371984
Posted Friday, October 12, 2012 3:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, November 21, 2014 9:38 AM
Points: 6,861, Visits: 14,160
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
Post #1371986
Posted Friday, October 12, 2012 7:19 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:20 PM
Points: 35,552, Visits: 32,148
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1372107
Posted Monday, October 15, 2012 4:17 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 5:03 AM
Points: 2,840, Visits: 3,975
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
Post #1372640
Posted Tuesday, October 16, 2012 7:21 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 9:29 AM
Points: 4,436, Visits: 6,337
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
Post #1373237
Posted Tuesday, October 16, 2012 1:51 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 9:42 AM
Points: 7,851, Visits: 9,602
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
Post #1373510
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse