I am experiencing an unclear sql server 2008 deadlock.
I have two tables:
T1: ID – bigint (PK), JOBID – bigint, X- bigint
T2: ID – bigint (PK), JOBID – bigint, X- bigint
The sql server error log describes the following:
Spid 233 is running this query:
SELECT TOP(500) FROM T1.X INNER JOIN T2 ON T1.X = T2.X WHERE T2.ID>-1 AND T2.ID<=10000
Spid 234 is running this query:
DELETE FROM T2 WHERE (X=1) OR (X=7) OR ( X=1233) OR X(=7878) OR (X=33) OR (X=776) OR (X=112)
Spid 233 is waiting for a Shared KEY lock on index t2.PK_T2. (Spid 234 holds a conflicting X lock.)
Spid 234 is waiting for an eXclusive KEY lock on index t2.PK_T2. (Spid 233 holds a conflicting S lock.)
PK_X is a Clustered ascending index on the identity column (ID which is auto increment column).
T2 also has another index which is a non clustered index on JOBID and X.
How come both processes are owners of a lock on the same object (T2.PK_T2)?
Please help,
Doron
How come both processes are owners of a lock on the same object (T2.PK_T2)?
The locks are not on the whole index. They are
keylocks and will be on different keys (rows) within the index.