mysql database phantom read

1. What is phantom reading?

Transaction A reads data according to certain conditions, during which transaction B inserts new data within the search range of transaction A, and when transaction A reads data according to the original conditions again, it is found that the newly inserted data of transaction B is called Phantom reading.

Two, phantom reading processing

If snapshot reads are used in transactions, phantom reads will not occur, but phantom reads will occur when snapshot reads are used together with current reads.
Under normal circumstances, select * from is a snapshot read. Will not be locked.
for update, lock in share mode, update, and delect all belong to the current read.

To solve the phantom reading, the gap lock method can be used to solve the phantom reading problem. The range value of our team's query plus the range range lock, so that when other transactions perform update operations, they can only wait for the query business to be submitted before the update operation can be performed.

Guess you like

Origin blog.csdn.net/qq_15592789/article/details/115309365