Mysql: since repeatable RR transaction isolation solves the phantom read problem, what are the benefits of serializable isolation over RR isolation?

Mysql: since repeatable RR transaction isolation solves the problem of phantom reading, what are the advantages of serializable isolation over RR isolation?

Mar.30,2022

it is not good for general business, but it has an impact on performance, which is more convenient for special business

RR solves phantom reading through manual locking. If locking is incorrect, phantom reading will still occur. Without full table locking, it is difficult to avoid that other transactions will not affect the current transaction.

therefore, the advantage of serializable is that it completely isolates the impact of other transactions on current transactions. When developers do not understand the database enough, using serializable is safer than locking manually

.

Repeatable read can solve phantom reading?
can be read repeatedly. All queries within the same transaction are consistent at the beginning of the transaction, with the InnoDB default level. In the SQL standard, this isolation level eliminates unrepeatable reads, but there are phantom reads.


repeatable reading does not solve phantom reading. There is no interline lock added.
if a scope query or scope update is not needed in a transaction, then repeatable reading is fine.


innodb reads are divided into snapshot reads and current reads.

at the RR level ,
ordinary select is a snapshot read; select in share mode and update are current reads;
current and current reads will not have phantom readings. There is no illusion between snapshot reading and snapshot reading.
but for current and snapshot reads, there may be phantom readings. Therefore, the situation of Cheng Chi-Ming's test came into being.

,
select is also locked by default at the Serializable level, so it is equivalent to current reads.

Summary :
at the RR level, programmers are required to actively avoid alternating snapshot reads and current reads in transactions in order to avoid phantom reading.
at the Serializable level, they are all currently read, so they naturally do not produce phantom readings.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3603e-4d67a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3603e-4d67a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?