You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit eb59177
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/relational-databases/performance/optimized-locking.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "Optimized locking"
3
3
description: "Learn about the optimized locking enhancement to the Database Engine."
4
4
ms.custom:
5
5
"references_regions"
6
-
ms.date: 02/01/2023
6
+
ms.date: 01/30/2023
7
7
ms.service: sql
8
8
ms.subservice: performance
9
9
ms.topic: conceptual
@@ -189,11 +189,11 @@ In addition to reduced blocking, the lock memory required will be reduced. This
189
189
190
190
### Avoid locking hints
191
191
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.
193
193
194
194
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.
195
195
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:
197
197
198
198
```sql
199
199
CREATETABLEt3
@@ -211,17 +211,21 @@ GO
211
211
UPDATE t3 SETt3.b=t4.b
212
212
FROM t3 WITH (UPDLOCK)
213
213
INNER JOIN t4 ONt3.a=t4.a;
214
+
215
+
UPDATE t3 SETt3.b=t4.b
216
+
FROM t3
217
+
INNER JOIN t4 WITH (UPDLOCK) ONt3.a=t4.a;
214
218
```
215
219
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.
217
221
218
222
```sql
219
223
UPDATE t3 SETt3.b=t4.b
220
224
FROM t3 WITH (REPEATABLEREAD)
221
225
INNER JOIN t4 ONt3.a=t4.a;
222
226
```
223
227
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.
0 commit comments