liveBook · Manning

Lock contention

As explained in 100 SQL Server Mistakes and How to Avoid Them

Lock contention is competition among concurrent database operations for incompatible locks on the same resources.

Mistake: choosing a stronger transaction isolation level simply to prevent every possible anomaly. Stronger levels protect against more anomalies, but they can make concurrent operations wait for incompatible locks, reducing performance and potentially causing deadlocks. section 10.11

The reporting transaction that blocks work

A reporting user begins a transaction and runs a query against ImpressionsArchive. While that transaction remains active, a data steward updates or deletes rows in the same table. Under a strong isolation level, the operations can wait on each other; in a deadlock, SQL Server rolls back the transaction it considers least expensive. section 10.11

Use these rules when lock contention affects performance:

  • Use Read Committed unless a legitimate requirement, such as preventing phantom reads during an actuarial calculation, demands stronger isolation. section 10.11
  • Consider Read Committed Snapshot or Snapshot when contention causes performance problems, provided TempDB has sufficient free space and is not I/O bound. section 10.14
  • Diagnose the root cause before adding hardware, and avoid treating extra capacity as a substitute for correcting the workload or isolation choice. section 10.14

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains waiting, deadlocks, rollback consequences, and isolation-level alternatives, but stops short of lock-monitoring procedures.
Examples
Uses reporting, updating, and deleting transactions against ImpressionsArchive to demonstrate competing work.
What it assumes
Assumes familiarity with transactions and isolation levels while explaining phantom reads and deadlocks in context.
What you can do after
Diagnose contention by reconsidering isolation requirements and evaluating optimistic isolation under suitable TempDB conditions.
How it connects
Connects lock contention with transaction isolation levels, phantom reads, deadlocks, optimistic isolation, and TempDB.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.