MySQL MVCC explained

MVCC定义:Multiversion concurrency control 

Multi-version concurrency control is just a conceptual term, and there is no uniform implementation standard. The core concept is data snapshots. Different transactions access different versions of data snapshots to achieve different transaction isolation levels.

Concurrency control technology used to provide concurrent access control to the database. The opposite of MVCC is concurrency control based on locks. The biggest advantage of MVCC is that everyone is familiar with it: reading is not locked, writing is still locked, and there is no conflict between reading and writing.

 

The InnoDB engine in Mysql cleverly implements multi-version data snapshots through transaction undo-log .

The transaction of the database sometimes needs to be rolled back, and then the previous operation needs to be undone. Therefore, when the data is modified, InnoDB will generate an undo log. When the transaction needs to be rolled back, InnoDB can use these undo logs to roll back the data to the way it was before the modification.

According to different behaviors, undo log is divided into two types: insert undo log and update undo log

①insert undo log: is the undo log generated in the insert operation. Because the record of the insert operation is only visible to the transaction itself, this record is not visible to other transactions, so the insert undo log can be deleted directly after the transaction is committed without the need to perform a purge operation.

②update undo log: is the undo log generated in the update or delete operation, because it will affect the existing records, in order to provide the MVCC mechanism, the update undo log cannot be deleted when the transaction is committed, but will be released when the transaction is committed. Go to the historylist, and wait for the purge thread to perform the final delete operation.

In order to ensure that there is no conflict when writing their respective undo logs during concurrent operations of transactions, InnoDB uses a rollback segment method to maintain the development, writing and persistence of the undo log. The rollback segment is actually an Undo file organization method.

InnoDB row records have three hidden fields: the rowid corresponding to the row , the transaction number db_trx_id, and the rollback pointer db_roll_ptr , where db_trx_id represents the id of the most recently modified transaction, and  db_roll_ptr points to the undo log in the rollback segment .

Guess you like

Origin blog.csdn.net/LB_Captain/article/details/115030237