What is MVCC (Multi-Version Concurrency Control) in MySQL?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
Answer
MVCC (Multi-Version Concurrency Control) is InnoDB's mechanism for providing consistent reads without acquiring read locks, enabling high concurrency. Instead of locking rows for reads, InnoDB maintains multiple versions of each row. When a transaction reads a row, it sees the version that was committed as of the transaction's start time — not necessarily the current version. How it works: every InnoDB row has two hidden columns: DB_TRX_ID (ID of the transaction that last modified the row) and DB_ROLL_PTR (pointer to the undo log entry). When a row is updated, the old version is moved to the undo log, and the new version is written with the current transaction ID. A reader finds the version visible to its snapshot by following the undo log chain. This means: readers don't block writers, and writers don't block readers — massive concurrency improvement. The consistent snapshot is taken at the START of a REPEATABLE READ transaction (or at the start of each statement in READ COMMITTED). Undo logs are purged by the InnoDB purge thread when no transaction needs them. Large, long-running transactions prevent purge, causing the undo log (and ibdata1) to grow unboundedly — a common production issue.
Pro Tip
This topic has MySQL / SQL-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.
Previous
What is the difference between B-tree and Hash indexes in MySQL?
Next
What is the InnoDB Buffer Pool and how does it work?
More MySQL / SQL Questions
View all →- Advanced What is the difference between B-tree and Hash indexes in MySQL?
- Advanced What is the InnoDB Buffer Pool and how does it work?
- Advanced What is deadlock in MySQL and how do you prevent it?
- Advanced What is the query execution plan and how does the MySQL optimizer work?
- Advanced What is the difference between optimistic locking with version numbers and timestamps?