Mysql’s method to solve non-repeatable reading: mvcc multi-version concurrency control is used. mvcc uses two hidden columns after each piece of data, namely the creation version number and the deletion version number. Each transaction is There will always be an incremental version number at the beginning.
【Related learning recommendations: mysql learning】
Mysql's method to solve non-repeatable reads:
In mysql, the default transaction isolation level is repeatable-read (repeatable-read). In order to solve non-repeatable reads, innodb uses mvcc (multiple Version Concurrency Control) to solve this problem.
mvcc uses two hidden columns (create version number and delete version number) after each piece of data. Each transaction will have an incremental version number at the beginning
New:
insert into user (id,name,age)values(1,"张三",10);
Update:
update user set age = 11 where id = 1;
The update operation is implemented by delete add. First, mark the current data as Delete
and add a new piece of data:
Delete: The deletion operation is to directly update the deleted version number of the data to the version number of the current transaction
delete from user where id = 1;##Query operation:
select * from user where id = 1;Query operation is to avoid To query old data or data that has been changed by other transactions, the following conditions need to be met: 1. The version number of the current transaction during query must be greater than or equal to the creation version number 2. Query The version number of the current transaction needs to be smaller than the deleted version numberThat is: create_version This can avoid querying the data modified by other transactions
The above is the detailed content of How to solve non-repeatable read in mysql. For more information, please follow other related articles on the PHP Chinese website!