I am trying to identify the reason of deadlock using SQL Server Profiler.
Here's the deadlock graph:
Both statements are inserts followed by
select scope_identity();
Actually a have 2 concurrent processes that repeatedly do insert-select_identity in a cycle.
What would i expect is that insert takes exclusive lock over the clustered index and select takes a shared lock of the non-clustered index, and then they wait for each other to release their respective indeces.
What i see is that both processes wait for the same resource to be released - the clustered index. How can this be? The particular recourse should belong either to one process or to another. What do i miss here? thanks to all in advance.
Edited: yes, isolation level is Serializible.
PS: probably, my assumption about the shared lock on non-clustered index was wrong as far as my select does not contain a where
statement
Edit2: here is the part of xml:
<resource-list>
<keylock hobtid="72057594148028416" dbid="29" objectname="<confidential>" indexname="PK_WP_Inbound_StockTransactionLine" id="lock9641700" mode="RangeS-S" associatedObjectId="72057594148028416">
<owner-list>
<owner id="process8e09288" mode="RangeS-S"/>
</owner-list>
<waiter-list>
<waiter id="process991ce08" mode="RangeI-N" requestType="convert"/>
</waiter-list>
</keylock>
<keylock hobtid="72057594148028416" dbid="29" objectname="<confidential>" indexname="PK_WP_Inbound_StockTransactionLine" id="lock9641700" mode="RangeS-S" associatedObjectId="72057594148028416">
<owner-list>
<owner id="process991ce08" mode="RangeS-S"/>
</owner-list>
<waiter-list>
<waiter id="process8e09288" mode="RangeI-N" requestType="convert"/>
</waiter-list>
</keylock>
</resource-list>
According to this, i thinks that it is Range scans caused by SERIALIZABLE isolation (googled that). But still, i don't understand how does this happen and what is the recommended remedy.