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

Deadlock on the same resource with incompatible locks Expand / Collapse
Author
Message
Posted Thursday, October 25, 2012 2:37 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 1:21 AM
Points: 295, Visits: 392
Hi,

I have a table named ClientContext that has only the clustered index.
I have a procedure sp1 that call other two procedures: sp2 and then sp3.
The procedure sp2 inserts some data in the table and sp3 update data in the table.

CREATE PROCEDURE sp1
AS
BEGIN
EXEC sp2;
EXEC sp3
END

CREATE PROCEDURE sp2
AS
BEGIN
INSERT INTO ClientContext.....
END

CREATE PROCEDURE sp3
AS
BEGIN
UPDATE ClientContext....
END

The procedure sp1 is called from application. I have an deadlock on UPDATE in sp3 procedure.
I get the graph of deadlock with SQL Profiler (see the attachement Deadlock.png image file).
I get the locks after deadlock ocured from sys.dm_tran_locks system view (see attachement dm_tran_lock.png)

It seems from the graph that process 55 has Update (U) lock on the index and process 64 has exclusive lock (X) on the same index.
But U and X locks are incompatible locks.
How can two processes put incompatible locks on the same resource?
Could anybody explain me this?






  Post Attachments 
Deadlock.PNG (6 views, 77.76 KB)
dm_tran_locks.PNG (10 views, 30.28 KB)
Post #1376838
Posted Thursday, October 25, 2012 3:14 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:40 AM
Points: 41,572, Visits: 34,499
The X and U locks are key locks, not object locks. Each one is locking a different row in the index.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1376855
Posted Friday, October 26, 2012 6:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 1:21 AM
Points: 295, Visits: 392
Thanks
Post #1377547
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse