Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Troubleshooting Deadlocks in SQL Server 2000
1.
2. PASS Community Summit - Seattle November 18-22, 2002 S231/S348 - Resolving Deadlocks in SQL Server 2000 Ron Talmage - Prospice, LLC
3.
4.
5.
6. Lock-Based Deadlocking Structure GRANT T3 Request(WAIT on Tran1) T5 Blocked (blocking removed) Deadlock Victim T6 Commit T7 Request (WAIT on Tran2) T4 Blocked GRANT T2 Begin Tran Begin Tran T1 Tran 2 Tran 1 Time
14. 1. Lock Modes Used with bulk copy into a table with either TABLOCK hint or table lock option is set BU Bulk Update Have update lock with intent to acquire exclusive lock at a finer level UIX Update Intent Exclusive Have shared lock with intent to acquire exclusive lock at a finer level SIX Shared Intent Exclusive Have shared lock with intent to acquire update lock at a finer level SIU Shared Intent Update Have or intend to request exclusive lock(s) at a finer level IX Intent Exclusive Have or intend to request update lock(s) at a finer level IU Intent Update Have or intend to request shared lock(s) at a finer level IS Intent Shared Used for writing (insert, update, delete) X Exclusive Used to evaluate prior to writing (may become exclusive) U Update Used for reading (read lock) S Shared Used for DDL operations (ALTER or DROP) on a table schema Sch-M Schema Modification Used when compiling queries Sch-S Schema-Stability Description Abbreviation Lock Mode
15. Lock Compatibility Matrix (default isolation level) Lock Mode Already Granted BU Sch-M Sch-S X SIX IX U S IS Lock Mode Requested No No Yes No Yes Yes Yes Yes Yes IS No No Yes No No No Yes Yes Yes S No No Yes No No No No Yes Yes U No No Yes No No Yes No No Yes IX No No Yes No No No No No Yes SIX No No Yes No No No No No No X Yes No Yes No No No No No No BU No No No No No No No No No Sch-M Yes No Yes Yes Yes Yes Yes Yes Yes Sch-S
16.
17.
18.
19. Isolation Level and Lock Accumulation Held until end of transaction Held until end of transaction unless promoted to exclusive or released Held until data read and processed Read Un-committed Held until end of transaction Held until end of transaction unless promoted to exclusive Held until end of transaction Repeatable Read Held until end of transaction Held until end of transaction Exclusive Held until end of transaction unless promoted to exclusive Held until end of transaction unless promoted to exclusive or released Update Held until end of transaction Held until data read and processed Shared Serializable Read Committed Lock Mode
24. Single-Resource Deadlock Select * From Authors With (HOLDLOCK) Where au_id = '172-32-1176' T3 GRANT Update Authors Set contract = 1 Where au_id = '172-32-1176' T5 Blocked (blocking removed) Deadlock Victim T6 Commit T7 Update Authors Set contract = 0 Where au_id = '172-32-1176' T4 Blocked Select * From Authors With (HOLDLOCK) Where au_id = '172-32-1176' T2 GRANT Begin Tran Begin Tran T1 Tran 2 Tran 1 Time
25.
26.
27. MR Deadlock Illustrated Res 1 Thread 1 Thread 2 Res 2 Grant Wait Blocked request
28.
29. X-only MR Deadlock Update Titles Set ytd_sales = 0 Where title_id = ‘BU1032' T3 GRANT Update Authors Set contract = 0 Where au_id = '172-32-1176' T5 Blocked (blocking removed) Deadlock Victim T6 Commit T7 Update Titles Set ytd_sales = 0 Where title_id = ‘BU1032' T4 Blocked Update Authors Set contract = 0 Where au_id = '172-32-1176' T2 GRANT Begin Tran Begin Tran T1 Tran 2 Tran 1 Time
30.
31.
32. Mixed X-S MR Example #1 Update Titles Set ytd_sales = 0 Where title_id = ‘BU1032' T3 GRANT Select * From Authors Where au_id = '172-32-1176' T5 Blocked (blocking removed) Deadlock Victim T6 Commit T7 Select * From Titles Where title_id = ‘BU1032' T4 Blocked Update Authors Set contract = 0 Where au_id = '172-32-1176' T2 GRANT Begin Tran Begin Tran T1 Tran 2 Tran 1 Time
33. Mixed X-S MR Example #2 Insert Authors Values ('111-11-1112', 'test2', '', '', '', '', '', '11111', 0) T3 GRANT Select * From Authors T5 Blocked (blocking removed) Deadlock Victim T6 Commit T7 Select * From Authors T4 Blocked Insert Authors Values ('111-11-1111', 'test1', '', '', '', '', '', '11111', 0) T2 GRANT Begin Tran Begin Tran T1 Tran 2 Tran 1 Time
56. Identifying the locks KEY: 7:1977058079:1 (f600d547433a) (from trace flag 1204 output)
57.
58.
59.
60.
61.
62.
63.
64. Thank you! Thank you for attending this session and PASS Community Summit - Seattle! Please help us improve the quality of our conference by completing your session evaluation form. Completed evaluation forms may be given to the room monitor as you exit or to staff at the registration desk.