Mysql has MVCC, under RR isolation level. Is there a shared lock?

recently in the study of MVCC-related knowledge, encountered a problem, I would like to ask you bosses, mysql has MVCC, under the RR isolation level, is there a shared lock (S Lock)? It feels that MVCC can completely replace the shared lock. When you read it, you only look at the version number, and you don"t need to add a read lock.

what"s more, innodb, if the query field is indexed and has MVCC, will it still use uplink locks?

Jul.31,2021

for the database engine with multi-version control, there is really no need to lock the reading of the table, and MVCC can ensure the integrity of the read. MVCC only works on a single row (or a single field), and locks can achieve transaction locking of multiple rows, multiple tables and multiple operations. The purpose of lock is different from that of MVCC. It can be said that the implementation of transaction depends on the characteristics of MVCC, but the transaction is much more complex than MVCC itself. Locks are only possible if you don't want the records to be modified while reading.


shared locks still exist, in the mysql5.6 innodb,RR isolation level.
use the primary key index to query a piece of data that does not exist, and an s lock will be added.
you can try:
start two transactions and use the primary key to query the same piece of non-existent data (using select. For update) .
both transactions return an empty result.
at this point, no one of the two transactions can insert the data with this primary key.

Menu