Databases 12 min read

InnoDB MVCC: Concepts, Implementation, and Visibility Rules

This article explains InnoDB's Multi-Version Concurrency Control (MVCC) mechanism, detailing undo log, readview, hidden columns, visibility algorithms for RR and RC isolation levels, and includes source code snippets illustrating read view assignment and visibility checks.

政采云技术
政采云技术
政采云技术
InnoDB MVCC: Concepts, Implementation, and Visibility Rules

This article provides an in-depth explanation of InnoDB's Multi-Version Concurrency Control (MVCC) mechanism, which enables high-concurrency reads and writes by maintaining multiple versions of data rows.

It describes the core components: the undo log that stores old versions of rows, the readview structure used for visibility checks, and the three hidden columns (DB_TRX_ID, DB_ROLL_PTR, DB_ROW_ID) added to each row.

The visibility algorithm for READ COMMITTED and REPEATABLE READ isolation levels is detailed, showing how a row's transaction ID is compared against the readview's up_limit_id, low_limit_id, and the list of active transaction IDs to determine visibility.

Implementation steps for INSERT, UPDATE on clustered and secondary indexes are illustrated with code examples, such as:

INSERT INTO `user`(`id`,`name`,`score`) VALUES (9,'zhang3',60);

and

UPDATE `user` SET `score`=70 WHERE `id`=9;

The article also includes source code snippets showing how InnoDB adds system columns, updates index entries, assigns read views via trx_assign_read_view , and performs visibility checks with functions like read_view_sees_trx_id and lock_clust_rec_cons_read_sees .

The purge thread removes old undo log versions based on the oldest active readview, ensuring storage efficiency.

Finally, it explains the differences between RR and RC levels: in RR the readview is created at the first select and persists until transaction commit, while in RC a new readview is generated for each select.

InnoDBundo logMVCCIsolation LevelsDatabase InternalsReadViewVisibility Algorithm
政采云技术
Written by

政采云技术

ZCY Technology Team (Zero), based in Hangzhou, is a growth-oriented team passionate about technology and craftsmanship. With around 500 members, we are building comprehensive engineering, project management, and talent development systems. We are committed to innovation and creating a cloud service ecosystem for government and enterprise procurement. We look forward to your joining us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.