Skip to content

Commit eb59177

Browse files
20230130 1042
1 parent 28a9e07 commit eb59177

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Optimized locking"
33
description: "Learn about the optimized locking enhancement to the Database Engine."
44
ms.custom:
55
"references_regions"
6-
ms.date: 02/01/2023
6+
ms.date: 01/30/2023
77
ms.service: sql
88
ms.subservice: performance
99
ms.topic: conceptual
@@ -189,11 +189,11 @@ In addition to reduced blocking, the lock memory required will be reduced. This
189189

190190
### Avoid locking hints
191191

192-
[Table and query hints](../../t-sql/queries/hints-transact-sql.md) while honored and reduce the benefit of optimized locking. Lock hints like UPDLOCK, READCOMMITTEDLOCK, XLOCK, HOLDLOCK, etc., in your queries reduce the full benefits of optimized locking. Having such lock hints in the queries forces the Database Engine to take row/page locks and hold them until the end of the transaction, to honor the intent of the lock hints. Some applications have logic where lock hints are needed, for example when reading a row with select with UPDLOCK and then updating it later. We recommend using lock hints only where needed.
192+
While [table and query hints](../../t-sql/queries/hints-transact-sql.md) are honored, they reduce the benefit of optimized locking. Lock hints like UPDLOCK, READCOMMITTEDLOCK, XLOCK, HOLDLOCK, etc., in your queries reduce the full benefits of optimized locking. Having such lock hints in the queries forces the Database Engine to take row/page locks and hold them until the end of the transaction, to honor the intent of the lock hints. Some applications have logic where lock hints are needed, for example when reading a row with select with UPDLOCK and then updating it later. We recommend using lock hints only where needed.
193193

194194
With optimized locking, there are no restrictions on existing queries and queries do not need to be rewritten. Queries that are not using hints will benefit most from optimized locking.
195195

196-
A table hint on one table in a query will not disable optimized locking for other tables in the same query. For example:
196+
A table hint on one table in a query will not disable optimized locking for other tables in the same query. Further, optimized locking only affects the locking behavior of tables being updated by an UPDATE statement. For example:
197197

198198
```sql
199199
CREATE TABLE t3
@@ -211,17 +211,21 @@ GO
211211
UPDATE t3 SET t3.b = t4.b
212212
FROM t3 WITH (UPDLOCK)
213213
INNER JOIN t4 ON t3.a = t4.a;
214+
215+
UPDATE t3 SET t3.b = t4.b
216+
FROM t3
217+
INNER JOIN t4 WITH (UPDLOCK) ON t3.a = t4.a;
214218
```
215219

216-
In the above example, only `t3` will be affected by the locking hint, while `t4` can still benefit from optimized locking.
220+
In the previous query example, only table `t4` will be affected by the locking hint, while `t3` can still benefit from optimized locking.
217221

218222
```sql
219223
UPDATE t3 SET t3.b = t4.b
220224
FROM t3 WITH (REPEATABLEREAD)
221225
INNER JOIN t4 ON t3.a = t4.a;
222226
```
223227

224-
In the above example, only `t3` will be affected by the isolation level hint. Only this query would use the repeatable read isolation level on `t3`, and will hold locks until the end of the transaction. Other queries on `t3` can still benefit from optimized locking, and `t4` can still benefit from optimized locking. The same applies to HOLDLOCK.
228+
In the previous query example, only table `t3` will use the repeatable read isolation level, and will hold locks until the end of the transaction. Other updates to `t3` can still benefit from optimized locking. The same applies to the HOLDLOCK hint.
225229

226230
## Frequently asked questions (FAQ)
227231

0 commit comments

Comments
 (0)