I observe really strange behavior of my DB. I have one small table (about 300 rows) where one field is continuously updated.
And I was getting a lot of deadlocks there - update of the table was deadlocking the similar update of the same table (U lock vs X lock).
So I decided to remove the clustered index (so table doesn't have any indexes now) to fix the deadlocks. But it didn't help and now I'm getting the deadlock between the U and X lock modes.
So one table, no indexes and 2 sessions updating one table
Victim
update dbo.MyNumber set
@nextno = nextno = nextno + 1
where [type] = @type
and yearid = @yearid
Winning query:
update dbo.MyNumber set
@nextno = nextno = nextno + 1
where [type] = @TYPE
and yrclosedyn = 0
Rows are definitely different but the page is the same.
How Is it possible? Maybe it is connected to the lock escalation, or ...?
I really appreciate any suggestions.
Thanks in advance Mike
DEADLOCK XML:
<deadlock-list>
<deadlock victim="process6c492e8">
<process-list>
<process id="processb6a988" taskpriority="0" logused="1848" waitresource="RID: 5:1:127478:16" waittime="3478" ownerId="17153439" transactionname="user_transaction" lasttranstarted="2012-12-18T12:31:40.147" XDES="0xffffffff89482258" lockMode="U" schedulerid="7" kpid="4248" status="suspended" spid="98" sbid="0" ecid="0" priority="0" transcount="2" lastbatchstarted="2012-12-18T12:31:49.913" lastbatchcompleted="2012-12-18T12:31:49.913" clientapp="PenAIR" hostname="S16047425" hostpid="9300" loginname="sa" isolationlevel="read committed (2)" xactid="17153439" currentdb="5" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="MYDATABASE.dbo.MyStoredProcedure" line="92" stmtstart="9062" stmtend="9388" sqlhandle="0x030005002d15a05e58b5710016a100000100000000000000">
UPDATE dbo.MyNumber Set
@NEXTNO = NEXTNO = NEXTNO + 1
WHERE (TYPE = @TYPE) AND (YRCLOSEDYN = 0) </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 5 Object Id = 1587549485] </inputbuf>
</process>
<process id="process6c492e8" taskpriority="0" logused="192" waitresource="RID: 5:1:127478:20" waittime="8252" ownerId="17153562" transactionname="user_transaction" lasttranstarted="2012-12-18T12:31:45.140" XDES="0x6583b1e0" lockMode="U" schedulerid="13" kpid="19824" status="suspended" spid="143" sbid="0" ecid="0" priority="0" transcount="2" lastbatchstarted="2012-12-18T12:31:45.140" lastbatchcompleted="2012-12-18T12:31:45.140" clientapp="PenAIR" hostname="S16047425" hostpid="4760" loginname="sa" isolationlevel="read committed (2)" xactid="17153562" currentdb="5" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056">
<executionStack>
<frame procname="MYDATABASE.dbo.MyStoredProcedure" line="92" stmtstart="9062" stmtend="9388" sqlhandle="0x030005002d15a05e58b5710016a100000100000000000000">
UPDATE dbo.MyNumber Set
@NEXTNO = NEXTNO = NEXTNO + 1
WHERE ([TYPE] = @TYPE) AND (YRCLOSEDYN = 0) </frame>
</executionStack>
<inputbuf>
Proc [Database Id = 5 Object Id = 1587549485] </inputbuf>
</process>
</process-list>
<resource-list>
<ridlock fileid="1" pageid="127478" dbid="5" objectname="MYDATABASE.dbo.MyNumber" id="lock464f2640" mode="X" associatedObjectId="72057594131120128">
<owner-list>
<owner id="processb6a988" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="process6c492e8" mode="U" requestType="wait"/>
</waiter-list>
</ridlock>
<ridlock fileid="1" pageid="127478" dbid="5" objectname="MYDATABASE.dbo.MyNumber" id="lockfffffffff1974980" mode="X" associatedObjectId="72057594131120128">
<owner-list>
<owner id="process6c492e8" mode="X"/>
</owner-list>
<waiter-list>
<waiter id="processb6a988" mode="U" requestType="wait"/>
</waiter-list>
</ridlock>
</resource-list>
</deadlock>
</deadlock-list>