MVCCMVCC (Multi-Version Concurrency Control) is multi-version concurrency control. It is an important function of InnoDB to realize transaction concurrency and rollback. The lock mechanism can control concurrent operations, but its system overhead is large, and MVCC can replace row-level locks in most cases. Using MVCC can reduce its system overhead. The specific implementation is to add three additional fields to each row of the database:
Snapshot ReadFor example, an unlocked select operation is a snapshot read. The emergence of snapshot read is based on the consideration of improving concurrent performance. The implementation of snapshot read is based on multi-version concurrency control, namely MVCC. MVCC can be considered a variant of row locks. In many cases, it avoids locking operations and reduces overhead. Since it is based on multiple versions, the snapshot read may not necessarily read the latest version of the data, but may be a previous historical version. Current ReadingWhat is read is the current data, and there is no need to use undo log to trace back to the state before the transaction was started. What is read is the latest version of the record. When reading, it is also necessary to ensure that other concurrent transactions cannot modify the current record, and the read record will be locked.
To put it simply, MVCC is to achieve read-write conflict without locking, and this read refers to snapshot read, not current read. Current read is actually a locking operation, which is the implementation of pessimistic lock.
MVCC Implementation PrincipleThree hidden fields
Version chain/undo logBecause the undo log will record the old version of the data before the transaction, and then the rollback pointer in the row record will point to the old version position, thus forming a version chain. Read View will continue to traverse the DB_TRX_ID in the linked list until it finds a DB_TRX_ID that meets certain conditions. Then the old record where the DB_TRX_ID is located is the latest "old version" that the current transaction can see. Read ViewIt is a collection of all currently active transactions (transactions that have not been committed) when the transaction is opened. In other words, Read View is the read view generated when a transaction performs a snapshot read operation. At the moment when the snapshot read is executed by the transaction, a snapshot of the current database system will be generated, recording and maintaining the ID of the current active transaction in the system.
The overall process of MVCC implementation:Summarize
refer to:[MySQL Notes] Correctly understand MySQL's MVCC and implementation principles (recommended) MySQL · Engine Features · InnoDB Transaction System (taobao.org) Detailed explanation of mvcc - Jianshu (jianshu.com) This concludes this article on in-depth study of MySQL multi-version concurrency control MVCC. I hope it will be helpful for everyone’s study, and I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to change the color of the entire row (tr) when the mouse stops in HTML
>>: CSS3 transition rotation perspective 2d3d animation and other effects example code
Copy code The code is as follows: <!DOCTYPE ht...
Preface I believe that the syntax of MySQL is not...
If you want to understand React Router, you shoul...
In the table header, you can define the light bor...
Preface Recently, during an interview, I was aske...
This article mainly introduces several scheduling...
After creating a container locally, you can creat...
1. Node server setup + database connection The op...
The process of installing MySQL database and conf...
Table of contents Application scenarios: Method 1...
Alphabetical DTD: Indicates in which XHTML 1.0 DT...
This article uses examples to describe how to cre...
First check the /etc/group file: [root@localhost ...
Table of contents From father to son: 1. In the s...
This article records the installation and configu...