Hi,
Very anoying scenario... We have large partitioned table and we use staging table loads, and partitions sliding in and out of this table (part of the process is also rebuilding indexes on the staging table that is being slid into large partitioned table). Recently (it doesn't mean it wasn't happening before, it is just that we turned on TF 1222), we noticed deadlocks of partition management process (explained before), and regular reports that run against table that is being altered (either main partitioned table or staging table). Sometimes it is even more ridicilous: we noticed some sql server management studio intellisense feature (!!probably because it is reading metadata) connections getting deadlocked with the process managing partitions.
After analyzing sql error log, we found that it is always Sch-M lock (partitioning management, which is normal becuase of ALTER or CREATE INDEX statements) deadlocking with different SELECT processes (Sch-S), and that it is always (luckily) Sch-S process that gets chosen as a victim. Why would they get deadlocked (unless it is some meta data contention)? Why wouldn't Sch-M wait for Sch-S to complete,or the oposite? Is there any way around this?
We are using sql server 2008r2 with 16 cpus (I read article that there is a bug related to systems with 16+ CPUs and lock partitioning, but I don't think that is the case here). Here is basic info from the log about typical deadlock we are facing... 1st process is ALTER TABLE (switch partition in), 2nd process is select from the main table...
process that survived deadlock: process id=process9ab51ebc8 taskpriority=0 logused=172 waitresource=OBJECT: 7:52351401:12 waittime=7437 ownerId=141346191 transactionname=user_transaction lasttranstarted=2013-02-27T20:02:25.523 XDES=0xbd476b950 lockMode=Sch-M schedulerid=1 kpid=8296 status=suspended spid=143 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2013-02-27T20:01:40.387 lastbatchcompleted=2013-02-27T20:01:40.387 clientapp=prod.cstatSvcDataSetProcessor hostname=SRV001 hostpid=10556 loginname=MAD\uprd isolationlevel=read committed (2) xactid=141346191 currentdb=7 lockTimeout=4294967295 clientoption1=673185824 clientoption2=128056 Victim: process id=process42c212bc8 taskpriority=0 logused=0 waitresource=OBJECT: 7:52351401:5 waittime=4570 ownerId=141346297 transactionname=Lookup lasttranstarted=2013-02-27T20:02:28.410 XDES=0x800dae50 lockMode=Sch-S schedulerid=13 kpid=8164 status=suspended spid=145 sbid=0 ecid=0 priority=0 trancount=0 lastbatchstarted=2013-02-27T20:02:22.447 lastbatchcompleted=2013-02-27T20:02:22.440 clientapp=IBM Cognos 8 hostname=CGNS001 hostpid=6736 loginname=BI isolationlevel=read committed (2) xactid=141345879 currentdb=6 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
thanks
Pedja