Lock and MVCC mechanism in MySQL

About the lock:

          InnoDB: Use row-level locks

          MyISAM: Use table-level locks

About MVCC (multi-version concurrency control):

         The realization of MVCC is realized by saving a snapshot of the data at a certain point in time. This means that no matter how long a transaction runs, a consistent view of data can be seen in the same transaction. According to the time when the transaction starts, it also means that the data in the same table seen by different transactions at the same time may be different.

InnoDB's MVCC implementation saves two additional hidden columns in each row of data: the version number when the current row is created and the version number when it is deleted (may be empty, in fact, there is another column called the rollback pointer, used for transaction back roll). The version number here is not the actual time value, but the system version number. Every time a new transaction is started, the system version number is automatically incremented. The system version number at the start of the transaction will be used as the version number of the transaction to be compared with the version number of each row of the query. Each transaction has its own version number, so when CRUD operations are executed within the transaction, the purpose of data version control is achieved through the comparison of version numbers.

Guess you like

Origin blog.csdn.net/qq_42407917/article/details/100761627