patternsqlModerate
Deadlock Graph and Interpretation, solution to avoid
Viewed 0 times
graphdeadlockavoidandsolutioninterpretation
Problem
I am supporting vendor based application, which is filled with blocks and deadlocks. Deadlocks occur mostly involving two or three processes however I noticed yesterday, it was having 9 SPIDs involved.
Can somebody please help me in understanding this deadlock graph and solution on how to avoid this.
Isolation level is set as Read Committed Snapshot at database level.
When I opened this deadlock graph in Sentry One plan Explorer, it was scary.
Version: Microsoft SQL Server 2014 (SP3) (KB4022619) - 12.0.6024.0 (X64) Sep 7 2018 01:37:51 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.3 (Build 14393: ) (Hypervisor)
Can somebody please help me in understanding this deadlock graph and solution on how to avoid this.
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1
unknown
(@P0 bigint,@P1 bigint)update Table_Name set STATUS_ID= @P0 where id= @P1 Isolation level is set as Read Committed Snapshot at database level.
When I opened this deadlock graph in Sentry One plan Explorer, it was scary.
Version: Microsoft SQL Server 2014 (SP3) (KB4022619) - 12.0.6024.0 (X64) Sep 7 2018 01:37:51 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.3 (Build 14393: ) (Hypervisor)
Solution
This definitely seems to be a bad combination of isolation level, lock escalation, and many sessions each issuing multiple queries inside the same transaction.
Using Plan Explorer to open the deadlock file, if you expand the waiter/owner list, you see they are all trying to access the same resource (presumably the entire table):
Also a slightly less scary way to see this is to optimize layout and use force directed:
If you replay the deadlock (I wrote about this functionality here, back when I was a Technical PM), you will see all of these different sessions holding their transactions open for relatively long periods of time (5+ minutes, which is crazy, though the animation really hides that), and issuing multiple queries intermittently. You need to drastically reduce the amount of time you spend inside those transactions (or get rid of them altogether), collapse multiple queries for different parameter values into a single, point-in-time query, build better indexes so that escalation doesn't happen, stop forcing repeatable read, created a clustered index (if I'm reading the resource descriptor right, that's a heap!?), or all of the above.
Using Plan Explorer to open the deadlock file, if you expand the waiter/owner list, you see they are all trying to access the same resource (presumably the entire table):
Also a slightly less scary way to see this is to optimize layout and use force directed:
If you replay the deadlock (I wrote about this functionality here, back when I was a Technical PM), you will see all of these different sessions holding their transactions open for relatively long periods of time (5+ minutes, which is crazy, though the animation really hides that), and issuing multiple queries intermittently. You need to drastically reduce the amount of time you spend inside those transactions (or get rid of them altogether), collapse multiple queries for different parameter values into a single, point-in-time query, build better indexes so that escalation doesn't happen, stop forcing repeatable read, created a clustered index (if I'm reading the resource descriptor right, that's a heap!?), or all of the above.
Context
StackExchange Database Administrators Q#234303, answer score: 12
Revisions (0)
No revisions yet.