Hi,
I found a deadlock situation during stress testing our ASP.Net app. The
deadlock is on a primary key index between two select statements select
against the same table where the index sits. How could deadlock happen in
Select statements is just beyond me.
One statement is
SELECT Comments, DelegatedByClientID, DelegatedByEmployeeID, NewStatus,
OldStatus, ProcessedDate, ProcessedRoleCode, ProcessedUsername,
WorkflowHistoryID, WorkflowID FROM WorkflowHistory WHERE (WorkflowID =
@WorkflowID) ORDER BY ProcessedDate
The other one is
SELECT Comments, DelegatedByClientID, DelegatedByEmployeeID, NewStatus,
OldStatus, ProcessedDate, ProcessedRoleCode, ProcessedUsername,
WorkflowHistoryID, WorkflowID FROM WorkflowHistory WHERE (WorkflowID =
@WorkflowID) AND (NewStatus = @NewStatus)
ORDER BY WorkflowHistoryID
The primary key is the WorkflowHistoryID. And there is no other index.
Any help will be appreciated very much.
Alex Kuznetsov - 23 Jul 2008 22:43 GMT
> Hi,
>
[quoted text clipped - 20 lines]
>
> Any help will be appreciated very much.
what isolation level are you using?
Harry - 23 Jul 2008 22:59 GMT
Hi Alex, it is 'read committed'.
> > Hi,
> >
[quoted text clipped - 22 lines]
>
> what isolation level are you using?
Andrew J. Kelly - 24 Jul 2008 01:10 GMT
> The primary key is the WorkflowHistoryID. And there is no other index.
Well that means you are scanning the table for sure then and that always
increases the chance of a deadlock. Why don't you have an index on
WorkFlowID? And why are you ordering by WorkFlowHistoryID? If it is jsut
an ID how can you guarantee it will be in the order you want? In any case I
am not sure why this deadlocked but you might want to do a trace so you can
see the actual Deadlock graph and then you don't have to guess. I would also
add appropriate indexes so it will scale.

Signature
Andrew J. Kelly SQL MVP
Solid Quality Mentors
> Hi,
>
[quoted text clipped - 20 lines]
>
> Any help will be appreciated very much.
Harry - 24 Jul 2008 02:44 GMT
Just in case somebody interested in this post:
It turned out that the lock is on the table not the index when sql server
tries to do a full scan of the table. Created some indexes and statistics and
the issue is resolved.
So deadlock could happen between 2 select queries.
> Hi,
>
[quoted text clipped - 20 lines]
>
> Any help will be appreciated very much.
TheSQLGuru - 24 Jul 2008 18:58 GMT
See this series for some wonderful information on deadlock investigation and
resolution:
http://blogs.msdn.com/bartd/archive/2006/09/09/Deadlock-Troubleshooting_2C00_-Pa
rt-1.aspx

Signature
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
> Just in case somebody interested in this post:
> It turned out that the lock is on the table not the index when sql server
[quoted text clipped - 27 lines]
>>
>> Any help will be appreciated very much.
JXStern - 25 Jul 2008 04:46 GMT
>Just in case somebody interested in this post:
>It turned out that the lock is on the table not the index when sql server
>tries to do a full scan of the table. Created some indexes and statistics and
>the issue is resolved.
>So deadlock could happen between 2 select queries.
Creepy. Glad you solved it.
Never seen it happen, probably because I'm pretty generous with
indexes. Unless this is a new behavior in SQL 2005?
Josh