Picture a busy library: dozens of readers want to browse the shelves at the same time, and a librarian is quietly reorganizing books behind the scenes. A naive approach would lock the whole room every time the librarian moves a book. Real libraries do not work that way — and neither do modern databases.
Multi-Version Concurrency Control (MVCC) is the trick that makes it possible. Instead of overwriting a row when it is updated, the database keeps the old version alive. Every running transaction is given a snapshot — a consistent view of all committed data at the moment it started. Readers see the old version; writers create a new one. Nobody waits for anyone else.
The result is the "readers never block writers, writers never block readers" guarantee that is the backbone of SQL optimization and transaction scheduling. It is not a magic trick but a precise algorithm, and understanding it reveals why isolation levels, phantom reads, and deadlocks behave the way they do.
Comments
Loading comments...