Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server 2008: U and X locks - deadlock on one table without any indexes. How?
    primarykey
    data
    text
    <p>I observe really strange behavior of my DB. I have one small table (about 300 rows) where one field is continuously updated.</p> <p>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).</p> <p>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.</p> <p>So one table, no indexes and 2 sessions updating one table</p> <p><strong>Victim</strong></p> <pre><code>update dbo.MyNumber set @nextno = nextno = nextno + 1 where [type] = @type and yearid = @yearid </code></pre> <p><br/><strong>Winning query:</strong></p> <pre><code>update dbo.MyNumber set @nextno = nextno = nextno + 1 where [type] = @TYPE and yrclosedyn = 0 </code></pre> <p><strong>Rows are definitely different but the page is the same.</strong></p> <p>How Is it possible? Maybe it is connected to the lock escalation, or ...?</p> <p>I really appreciate any suggestions.</p> <p>Thanks in advance Mike</p> <p>DEADLOCK XML:</p> <pre><code>&lt;deadlock-list&gt; &lt;deadlock victim="process6c492e8"&gt; &lt;process-list&gt; &lt;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"&gt; &lt;executionStack&gt; &lt;frame procname="MYDATABASE.dbo.MyStoredProcedure" line="92" stmtstart="9062" stmtend="9388" sqlhandle="0x030005002d15a05e58b5710016a100000100000000000000"&gt; UPDATE dbo.MyNumber Set @NEXTNO = NEXTNO = NEXTNO + 1 WHERE (TYPE = @TYPE) AND (YRCLOSEDYN = 0) &lt;/frame&gt; &lt;/executionStack&gt; &lt;inputbuf&gt; Proc [Database Id = 5 Object Id = 1587549485] &lt;/inputbuf&gt; &lt;/process&gt; &lt;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"&gt; &lt;executionStack&gt; &lt;frame procname="MYDATABASE.dbo.MyStoredProcedure" line="92" stmtstart="9062" stmtend="9388" sqlhandle="0x030005002d15a05e58b5710016a100000100000000000000"&gt; UPDATE dbo.MyNumber Set @NEXTNO = NEXTNO = NEXTNO + 1 WHERE ([TYPE] = @TYPE) AND (YRCLOSEDYN = 0) &lt;/frame&gt; &lt;/executionStack&gt; &lt;inputbuf&gt; Proc [Database Id = 5 Object Id = 1587549485] &lt;/inputbuf&gt; &lt;/process&gt; &lt;/process-list&gt; &lt;resource-list&gt; &lt;ridlock fileid="1" pageid="127478" dbid="5" objectname="MYDATABASE.dbo.MyNumber" id="lock464f2640" mode="X" associatedObjectId="72057594131120128"&gt; &lt;owner-list&gt; &lt;owner id="processb6a988" mode="X"/&gt; &lt;/owner-list&gt; &lt;waiter-list&gt; &lt;waiter id="process6c492e8" mode="U" requestType="wait"/&gt; &lt;/waiter-list&gt; &lt;/ridlock&gt; &lt;ridlock fileid="1" pageid="127478" dbid="5" objectname="MYDATABASE.dbo.MyNumber" id="lockfffffffff1974980" mode="X" associatedObjectId="72057594131120128"&gt; &lt;owner-list&gt; &lt;owner id="process6c492e8" mode="X"/&gt; &lt;/owner-list&gt; &lt;waiter-list&gt; &lt;waiter id="processb6a988" mode="U" requestType="wait"/&gt; &lt;/waiter-list&gt; &lt;/ridlock&gt; &lt;/resource-list&gt; &lt;/deadlock&gt; &lt;/deadlock-list&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload