Home > Database > Mysql Tutorial > How to solve non-repeatable read in mysql

How to solve non-repeatable read in mysql

coldplay.xixi
Release: 2020-09-02 13:50:19
Original
8968 people have browsed it

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.

How to solve non-repeatable read in mysql

【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);
Copy after login

How to solve non-repeatable read in mysql

Update:

update user set age = 11 where id = 1;
Copy after login

The update operation is implemented by delete add. First, mark the current data as Delete

How to solve non-repeatable read in mysql

and add a new piece of data:

How to solve non-repeatable read in mysql

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;
Copy after login

How to solve non-repeatable read in mysql

##Query operation:

select * from user where id = 1;
Copy after login
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 number

That 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template