MVCC
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    MVCC (multi-version concurrency control): the 60-second story

    MVCC

    A 20-minute report sums every UPI wallet. Payments keep flowing.

    With locks, they’d block each other. MVCC keeps old row versions, so readers never wait for writers, or writers for readers.

    The munim never erases. He writes a new line.

    Each write adds a version stamped with its transaction. Your snapshot, a token taken at the door, picks the newest version finished before it.

    Does MVCC mean no locks?

    Bad: No locks anywhere

    So two payments to one wallet don’t wait either.

    Good: Writers still block writers

    Only one version can follow the current one. The second writer waits.

    How every MVCC engine works

    1. Stamp each version with its writer’s ID
    2. Snapshot: who had committed when you started
    3. Read the newest version your snapshot can see
    4. Remove replaced versions no live snapshot can read

    Where do the old versions live?

    PostgreSQL writes a whole new tuple into the table. InnoDB and Oracle change the row in place and copy old values to undo.

    Both designs keep history. Who pays for it?

    Who pays

    PostgreSQL charges the writer, a new tuple plus an entry in every index unless HOT. InnoDB charges old readers, who walk undo.

    36M

    old versions a 2-hour report pins

    A Flipkart-style sale makes 5,000 order-row updates a second. Over 7,200 s, clean-up can remove none of the versions they replace.

    A long query needs old versions. PostgreSQL and InnoDB keep them for it and let storage grow.

    Oracle’s choice

    Oracle may reuse that undo instead. The long query then fails with ORA-01555, snapshot too old.

    Remember

    Readers never wait for writers, or writers for readers. Keep transactions short so old versions can be cleaned up.