MySQL Shared and Exclusive Locks

Posted xxoome

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL Shared and Exclusive Locks相关的知识,希望对你有一定的参考价值。

官方文档

InnoDB implements standard row-level locking where there are two types of locks, shared (S) locks and exclusive (X) locks.

  • A shared (S) lock permits the transaction that holds the lock to read a row.

  • An exclusive (X) lock permits the transaction that holds the lock to update or delete a row.

If transaction T1 holds a shared (S) lock on row r, then requests from some distinct transaction T2 for a lock on row r are handled as follows:

  • A request by T2 for an S lock can be granted immediately. As a result, both T1 and T2 hold an S lock on r.

  • A request by T2 for an X lock cannot be granted immediately.

If a transaction T1 holds an exclusive (X) lock on row r, a request from some distinct transaction T2 for a lock of either type on r cannot be granted immediately. Instead, transaction T2 has to wait for transaction T1 to release its lock on row r.

 shared  lock

A kind of lock that allows other transactions to read the locked object, and to also acquire other shared locks on it, but not to write to it. 

exclusive lock

A kind of lock that prevents any other transaction from locking the same row. Depending on the transaction isolation level, this kind of lock might block other transactions from writing to the same row, or might also block other transactions from reading the same row. The default InnoDB isolation level, REPEATABLE READ, enables higher concurrency by allowing transactions to read rows that have exclusive locks, a technique known as consistent read.

 

以上是关于MySQL Shared and Exclusive Locks的主要内容,如果未能解决你的问题,请参考以下文章

ARMV8 datasheet学习笔记3:AArch64应用级体系结构之Synchronization and semapores

dynamic-link library shared library of functions and resources

DHCP/DNS offload and Config drive support for adv shared network

《MySQL系列-部署维护》MySQL启动异常:error while loading shared libraries: libncurses.so.5: cannot open shared...

error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or

mysql: error while loading shared libraries: libmysqlclient