(2) Deep understanding of MySql lock and transaction isolation level

1. Detailed explanation of MVCC mechanism

MVCC is mainly to improve the high concurrent read and write performance, allowing multiple transactions to read and write concurrently without locking.
Insert picture description here
For operations with a transaction id of 12, first query select * from account ( a query snapshot is created, and the record is the largest at the moment when SQL is executed. The committed transaction id of the snapshot point has the largest transaction id committed ), for the operation of transaction 13, first delete the record with id=1, then update the record with id=2, and then submit. For deletion operations, the bottom layer of mysql will record the deletion The delete transaction id of the data row, for the update operation mysql bottom layer will add a row of the same data and record the corresponding creation transaction id

Execute the query operation in the transaction with id 12, the bottom layer of mysql will bring filter conditions, create transaction id<=max (when the transaction id is 12, the maximum transaction id that has been committed at the snapshot point, delete the transaction id>max (current transaction id is 12 , The maximum transaction id committed at the snapshot point])

Note: The begin/start transaction command is not the starting point of a transaction. After executing the first statement that operates the InnoDB table after them, the transaction is really started, and then the transaction id will be applied to mysql. MySQL is strictly in accordance with the start of the transaction. Order to allocate transaction id

Guess you like

Origin blog.csdn.net/qq_43565087/article/details/109276110