Lock Escalation
Related to the number of locks and memory pressure, after the threshold is reached, upgrade directly to table lock without minor upgrade to page lock
There are several ways to reduce lock escalation:
- Disabling lock escalation for SQL Server instances
- Disabling lock escalation for a specific table
- Increase the valve value, reduce the possibility of lock escalation (sp_configure ' locks ', 10000; RECONFIGURE;)
- Enable row versioning
Disabling lock escalation for a DB instance
In SQL Server 2005, you can use trace flag 1211, 1224来 to disable lock escalation throughout the instance.
- Flag 1211-Lock escalation is completely forbidden, but the memory used by the lock is limited to 60% of the dynamically allocated memory, and when this value is exceeded, more locks will fail with a memory overflow error.
- Flag 1224-Lock escalation is forbidden, but memory usage exceeds 40% automatically
- If the flag 1211 and 1224 trace flags are set at the same time, only the flag 1211 will take effect.
Prohibit lock escalation for specific tables
In SQL Server 2008 and later versions, you can use the new selection to disable lock escalation for a table
ALTER TABLE SET (lock_ecalation = AUTO | TABLE | DISABLE)
- Table: Upgrade directly from row lock to table lock (this is the default value)
- AUTO: If a table partition exists, it is promoted to a partition lock, but not further upgraded.
- DISABLE: Disabling lock escalation does not mean that table locks are disabled (table locks are also required for operations such as table scans when serializing isolation levels)
About Rowlock
A lot of information on the web mentions that using Rowlock in a statement can force the use of row locks, but the actual test finds no effect.
Check data display: Use locking hints such as rowlock only change the initial lock plan. Lock hints do not prevent lock escalation.
Using a lock hint such as Rowlock only alters the initial lock plan. Lock hints do not prevent lock escalation.
Https://msdn.microsoft.com/zh-cn/library/ms184286.aspx
https://support.microsoft.com/zh-cn/kb/323630
Disabling lock escalation for SQL Server