当前位置:网站首页>MySQL mvcc multi version concurrency control

MySQL mvcc multi version concurrency control

2022-06-10 23:10:00 Li_ XiaoJin

Some content about multi version concurrency control . Mainly from 《 High performance MySQL》, Make notes .

MCVV The implementation of the , It is achieved by saving a snapshot of the data at a certain point in time . No matter how long it takes , Each transaction sees the same data . Depending on when the transaction started , Each transaction is on the same table , The data seen at the same time may be inconsistent .

This paper mainly introduces InnoDB Of MVCC Realization .

InnoDB Of MVCC This is achieved by saving two hidden columns after each row of records . These two columns , A save line creation time , An expiration time for a saved row ( Or delete the time ). The actual storage is not time , It can be regarded as the system version number .

Each time a transaction is started , The system version number will be incremented . The system version number at the start of the transaction will be the version number of the transaction , Used to compare with each row of records queried .

stay REPEATABLE READ Under isolation level ,MCCC The operation is as follows :

  1. SELECT InnoDB Each line of records will be checked according to two conditions :
    1. InnoDB Only find data rows older than the current transaction version , This ensures that the rows read by the transaction , Or something that existed before it started , Either the transaction itself inserts or modifies .
    2. The deleted version of the line is either undefined , Or greater than the current transaction , You can ensure that the rows read by the transaction , Delete before the transaction starts .

Only when the above two conditions are met can the query result be returned .

  1. INSERT InnoDB Save the current system version number for each newly inserted row as the row version number .
  2. DELETE InnoDB Save the current system version number for each deleted row as the deletion ID of the row .
  3. UPDATE InnoDB Insert a new record for , Save the current version number as the line version number of the line , At the same time, save the current system version number to the original line as the line deletion identifier .

Save the pros and cons of these two version numbers

advantage :

  1. This allows most read operations to be unlocked
  2. It can make data operation simple , Good performance , This ensures that only rows that meet the criteria will be read

shortcoming :

  1. Each row requires additional storage space
  2. More line checking operations are required
  3. Some extra maintenance work is required

MVCC Only in REPEATABLE READ and READ COMMITED These two isolation levels work , The other two isolation levels are incompatible ,READ UNCOMMITED Read only the latest data row at a time , Instead of data lines that match the current transaction version ,SERIALIZABLE All read rows will be locked .

Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/mvcc Multi version concurrency control

原网站

版权声明
本文为[Li_ XiaoJin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102147101161.html