Hi,
I am getting a deadlock in SQL Server. I have attached the deadlock report from the SQL Server error log below:
deadlock-list deadlock victim=process3a9c990c8 process-list process id=process3a9c990c8 taskpriority=5 logused=7082044 waitresource=OBJECT: 9:331148225:14 waittime=1896 ownerId=8978198 transactionname=user_transaction lasttranstarted=2013-02-18T10:14:37.033 XDES=0x3b09cc3a8 lockMode=IX schedulerid=15 kpid=6912 status=suspended spid=53 sbid=0 ecid=0 priority=-5 trancount=2 lastbatchstarted=2013-02-18T10:14:37.033 lastbatchcompleted=2013-02-18T10:14:37.033 lastattention=1900-01-01T00:00:00.033 clientapp=.Net SqlClient Data Provider hostname=H185A011 hostpid=7584 loginname=S-1-9-3-2495688551-1145502858-1314026380-839257801 isolationlevel=snapshot (5) xactid=8978198 currentdb=9 lockTimeout=4294967295 clientoption1=673185824 clientoption2=128056 executionStack frame procname=PPGallium_Metadata_New.dbo.spPurge line=110 stmtstart=7988 stmtend=8326 sqlhandle=0x03000900a3f062067dadd7005fa1000001000000000000000000000000000000000000000000000000000000 delete from tblPPObject from tblPPObject as po join #ObjectInfos as os on os.InsertionID = po.InsertionID -- Keep the objects removed on this pass inputbuf Proc [Database Id = 9 Object Id = 107147427] process id=process3b0126558 taskpriority=0 logused=4510076 waitresource=OBJECT: 9:2137058649:6 waittime=1377 ownerId=8976241 transactionname=user_transaction lasttranstarted=2013-02-18T10:14:36.487 XDES=0x3ff49c3a8 lockMode=IX schedulerid=2 kpid=2920 status=suspended spid=54 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2013-02-18T10:14:38.100 lastbatchcompleted=2013-02-18T10:14:37.830 lastattention=1900-01-01T00:00:00.830 clientapp=.Net SqlClient Data Provider hostname=H185A011 hostpid=7584 loginname=S-1-9-3-2495688551-1145502858-1314026380-839257801 isolationlevel=read committed (2) xactid=8976241 currentdb=9 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056 executionStack frame procname=PPGallium_Metadata_New.dbo.spMergePPObjectProperty line=11 stmtstart=262 stmtend=1798 sqlhandle=0x03000900203bb566ff21f9005ba1000001000000000000000000000000000000000000000000000000000000 merge tblPPObjectProperty as t using (select * from @Values) as s on t.InsertionId = s.InsertionId and t.PropertyMapNameId = s.PropertyMapNameID when matched then update set UpdateTime = GETUTCDATE(), BitValue = s.BitValue, UIDValue = s.UIDValue, FloatValue = s.FloatValue, IntValue = s.IntValue, NVarCharValue = s.NVarCharValue, BigIntValue = s.BigIntValue, UpdateId = s.UpdateId when not matched then insert (InsertionId, PropertyMapNameId, UpdateID, UpdateTime, BitValue, UIDValue, FloatValue, IntValue, NVarCharValue, BigIntValue, TypeIndex) values (s.InsertionId, s.PropertyMapNameId, s.UpdateId, GETUTCDATE(), s.BitValue, s.UidValue, s.floatValue, s.IntValue, s.NVarCharValue, s.BigIntValue, s.TypeIndex) option (loop join); inputbuf Proc [Database Id = 9 Object Id = 1723153184] resource-list objectlock lockPartition=14 objid=331148225 subresource=FULL dbid=9 objectname=PPGallium_Metadata_New.dbo.tblPPObject id=lock3d4122300 mode=X associatedObjectId=331148225 owner-list owner id=process3b0126558 mode=X waiter-list
The problem is really strange. It seems as if there is a deadlock on the tblPPObjectProperty table.
As you can see from the log, rows are being removed from the tblPPObject table. There is a FK relationship on the field InsertionID between tblPPObject and tblPPObjectProperty. There is a non-clustered index on the field InsertionID in the table tblPPObjectProperty. There is a clustered index on the field InsertionID in the table tblPPObject.
The execution plan when deleting rows from the tblPPObject table implies that a non-clustered index seek is being made on the tblPPObjectProperty table. Please note that before I delete the required rows from the tblPPObject table I have deleted the matching rows from the tblPPObjectProperty table.
So my question is why does removing rows from the tblPPObject property table require a lock on the tblPPObjectProperty table? It should have no need to do this but this is clearly the problem.
Any help or advice would be appreciated.
Thanks
Ian