MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How does InnoDB handle Row-Level Locks: Shared (S), Exclusive (X), and Intention Locks (IS, IX)?
senior LevelMySQL
In Simple Words:
- Shared Lock (S): Acquired via
SELECT ... FOR SHARE. Allows concurrent reads, blocks writes. - Exclusive Lock (X): Acquired via
UPDATE,DELETE, orSELECT ... FOR UPDATE. Blocks all other reads and writes. - Intention Locks (IS, IX): Table-level locks indicating that a transaction intends to lock individual rows inside the table. Prevents another transaction from acquiring a conflicting table-level lock (like
LOCK TABLES) without inspecting every individual row!