Skip to content

Commit 963d78d

Browse files
20231009 ol deadlock
1 parent f612f4f commit 963d78d

3 files changed

Lines changed: 54 additions & 7 deletions

File tree

39.3 KB
Loading

docs/relational-databases/performance/optimized-locking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Learn about the optimized locking enhancement to the Database Engi
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
66
ms.reviewer: randolphwest, peskount
7-
ms.date: 10/04/2023
7+
ms.date: 10/09/2023
88
ms.service: sql
99
ms.subservice: performance
1010
ms.topic: conceptual
@@ -229,7 +229,7 @@ To support monitoring and troubleshooting of blocking and deadlocking with optim
229229
- Wait resource visibility
230230
- `XACT` wait resources. For more information, see `wait_resource` in [sys.dm_exec_requests (Transact-SQL)](../system-dynamic-management-views/sys-dm-exec-requests-transact-sql.md).
231231
- Deadlock graph
232-
- Under each resource in the deadlock report's `<resource-list>`, each `<xactlock>` element reports the underlying resources and specific information for locks of each member of a deadlock.
232+
- Under each resource in the deadlock report's `<resource-list>`, each `<xactlock>` element reports the underlying resources and specific information for locks of each member of a deadlock. For more information and an example, see [Optimized locking and deadlocks](../sql-server-deadlocks-guide.md#optimized-locking-and-deadlocks).
233233

234234
## Best practices with optimized locking
235235

docs/relational-databases/sql-server-deadlocks-guide.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Learn about deadlocks in the SQL Server database engine."
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
66
ms.reviewer: randolphwest
7-
ms.date: 03/21/2023
7+
ms.date: 10/09/2023
88
ms.service: sql
99
ms.subservice: performance
1010
ms.topic: conceptual
@@ -509,7 +509,57 @@ You can view the XML in the `Deadlock_XML` column inside SSMS, by selecting the
509509

510510
:::image type="content" source="media/sql-server-deadlocks-guide/graphical-deadlock-xdl.png" alt-text="A screenshot of a visual deadlock graph in an .xdl file in SSMS." lightbox="media/sql-server-deadlocks-guide/graphical-deadlock-xdl.png":::
511511

512-
## <a id="Additional_Reading"></a> See also
512+
## Optimized locking and deadlocks
513+
514+
**Applies to:** [!INCLUDE[ssazure-sqldb](../../includes/ssazure-sqldb.md)]
515+
516+
[Optimized locking](performance/optimized-locking.md) introduced a different method for locking mechanics that changes how deadlocks involving exclusive TID locks may be reported. Under each resource in the deadlock report's `<resource-list>`, each `<xactlock>` element reports the underlying resources and specific information for locks of each member of a deadlock.
517+
518+
Consider the following example where optimized locking is enabled:
519+
520+
```sql
521+
CREATE TABLE t2
522+
(a int PRIMARY KEY not null
523+
,b int null);
524+
525+
INSERT INTO t2 VALUES (1,10),(2,20),(3,30)
526+
GO
527+
```
528+
529+
The following TSQL commands in two sessions will create a deadlock on table `t2`:
530+
531+
In session 1:
532+
533+
```sql
534+
--session 1
535+
begin tran foo;
536+
update t2 set b = b+ 10 where a = 1;
537+
```
538+
539+
In session 2:
540+
```sql
541+
--session 2:
542+
begin tran bar
543+
update t2 set b = b+ 10 where a = 2;
544+
```
545+
546+
In session 1:
547+
```sql
548+
--session 1:
549+
update t2 set b = b + 100 where a = 2;
550+
```
551+
552+
In session 2:
553+
```sql
554+
--session 2:
555+
update t2 set b = b + 20 where a = 1;
556+
```
557+
558+
This results in a deadlock. In this case, a keylock resource, where each session holds an X lock on its own TID and is waiting on the S lock on the other TID, resulting in a deadlock. The following XML, captured as the deadlock report, contains elements and attributes specific to optimized locking:
559+
560+
:::image type="content" source="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png" alt-text="A screenshot of the XML of a deadlock report showing the UnderlyingResource nodes and keylock nodes specific to optimized locking." lightbox="media/sql-server-deadlocks-guide/optimized-locking-tid-lock-deadlock-xml.png":::
561+
562+
## <a id="Additional_Reading"></a> Related content
513563

514564
- [Extended Events](../relational-databases/extended-events/extended-events.md)
515565
- [sys.dm_tran_locks (Transact-SQL)](../relational-databases/system-dynamic-management-views/sys-dm-tran-locks-transact-sql.md)
@@ -518,8 +568,5 @@ You can view the XML in the `Deadlock_XML` column inside SSMS, by selecting the
518568
- [Lock:Deadlock Chain Event Class](event-classes/lock-deadlock-chain-event-class.md)
519569
- [Lock:Deadlock Event Class](event-classes/lock-deadlock-event-class.md)
520570
- [SET DEADLOCK_PRIORITY (Transact-SQL)](../t-sql/statements/set-deadlock-priority-transact-sql.md)
521-
522-
## Next steps
523-
524571
- [Analyze and prevent deadlocks in Azure SQL Database](/azure/azure-sql/database/analyze-prevent-deadlocks)
525572
- [Open, view, and print a deadlock file in SQL Server Management Studio (SSMS)](performance/open-view-and-print-a-deadlock-file-sql-server-management-studio.md)

0 commit comments

Comments
 (0)