Skip to main content

Transactions and Concurrency

Locking Mechanisms

0:00
LearnStep 1/2

Locking

Locking Mechanisms

Lock Types

LockAlso CalledPurposeCompatibility
Shared (S)Read lockReading dataCompatible with S
Exclusive (X)Write lockWriting dataNot compatible with any

Lock Compatibility Matrix

Two-Phase Locking (2PL)

Ensures serializability:

Strict 2PL

Hold all exclusive locks until commit/abort:

  • Prevents cascading rollbacks
  • Most common in practice

Lock Granularity

  • Row-level: Most concurrent, highest overhead
  • Page-level: Balance
  • Table-level: Least concurrent, lowest overhead