I have been working on improving the installation speed of our database (with thousands of objects) by multi threading the creation of the objects. This has caused the unfortunate behavior of causing deadlocks on the DROP PROCEDURE
statements.
Single threaded the deployment was taking a very long time (Since we are talking about a lot of database objects. Turning around the schema is not something to do lightly as the schema is installed at a few hundred clients.). The slow deployment is holding back our development/release cycle.
The scripts contain the following code
IF OBJECT_ID(N'myProc') IS NOT NULL
BEGIN
DROP PROCEDURE myProc
END
GO
CREATE PROC....
And the second script contains
IF OBJECT_ID(N'myProc2') IS NOT NULL
BEGIN
DROP PROCEDURE myProc2
END
GO
CREATE PROC....
These procedures are completely unrelated. No dependencies what so every.
The deadlock graph can be seen below:
<deadlock-list>
<deadlock victim="process6c3dc8">
<process-list>
<process id="process6c3dc8" taskpriority="0" logused="884" waitresource="OBJECT: 25:1949249999:0 " waittime="3834" ownerId="3008593" transactionname="DROPOBJ" lasttranstarted="2011-04-28T16:34:31.503" XDES="0xa882b950" lockMode="Sch-S" schedulerid="3" kpid="2588" status="suspended" spid="59" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2011-04-28T16:34:31.503" lastbatchcompleted="2011-04-28T16:34:31.503" clientapp=".Net SqlClient Data Provider" hostname="myPc" hostpid="7296" loginname="myLogin" isolationlevel="read committed (2)" xactid="3008593" currentdb="25" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="adhoc" line="4" stmtstart="264" stmtend="352" sqlhandle="0x0200000092ebe0126e0f90268e2a5bf1eaba70a098515cd9">
DROP PROCEDURE myProc2 </frame>
</executionStack>
<inputbuf>
IF object_id(N'myProc2') is not null
BEGIN
PRINT N'Dropping procedure myProc2 ...'
DROP PROCEDURE myProc2
END </inputbuf>
</process>
<process id="processaa4242c8" taskpriority="0" logused="5800" waitresource="OBJECT: 25:1965250056:0 " waittime="3834" ownerId="3008596" transactionname="DROPOBJ" lasttranstarted="2011-04-28T16:34:31.503" XDES="0xab493950" lockMode="Sch-S" schedulerid="2" kpid="5768" status="suspended" spid="60" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2011-04-28T16:34:31.503" lastbatchcompleted="2011-04-28T16:34:31.503" clientapp=".Net SqlClient Data Provider" hostname="myPC" hostpid="8296" loginname="myLogin" isolationlevel="read committed (2)" xactid="3008596" currentdb="25" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame procname="adhoc" line="4" stmtstart="276" stmtend="370" sqlhandle="0x02000000f019293427b8052cc3d5d18be886f958c4b750a1">
DROP PROCEDURE myProc </frame>
</executionStack>
<inputbuf>
IF object_id(N'myProc') is not null
BEGIN
PRINT N'Dropping procedure myProc ...'
DROP PROCEDURE myProc
END </inputbuf>
</process>
</process-list>
<resource-list>
<objectlock lockPartition="0" objid="1949249999" subresource="FULL" dbid="25" objectname="1949249999" id="lock87308e00" mode="Sch-M" associatedObjectId="1949249999">
<owner-list>
<owner id="processaa4242c8" mode="Sch-M"/>
</owner-list>
<waiter-list>
<waiter id="process6c3dc8" mode="Sch-S" requestType="wait"/>
</waiter-list>
</objectlock>
<objectlock lockPartition="0" objid="1965250056" subresource="FULL" dbid="25" objectname="myDatabase.dbo.myProc2" id="lock878d9e80" mode="Sch-M" associatedObjectId="1965250056">
<owner-list>
<owner id="process6c3dc8" mode="Sch-M"/>
</owner-list>
<waiter-list>
<waiter id="processaa4242c8" mode="Sch-S" requestType="wait"/>
</waiter-list>
</objectlock>
</resource-list>
</deadlock>
</deadlock-list>