Intention Locks && Intention Locking Protocol

Intention Locks && Intention Locking Protocol

http://dev.mysql.com/doc/refman/5.6/en/glossary.html#glos_intention_lock

intention lock

A kind of lock that applies to the table level, used to indicate what kind of lock the transaction intends to acquire on rows in the table. Different transactions can acquire different kinds of intention locks on the same table, but the first transaction to acquire an intention exclusive (IX) lock on a table prevents other transactions from acquiring any S or X locks on the table. Conversely(相反的), the first transaction to acquire an intention shared (IS) lock on a table prevents other transactions from acquiring any X locks on the table. The two-phase process allows the lock requests to be resolved in order, without blocking locks and corresponding operations that are compatible.

Intention Locks

Additionally, InnoDB supports multiple granularity(间隔尺寸,粒度) locking which permits coexistence(共存,并立) of record locks and locks on entire tables. To make locking at multiple granularity levels practical, additional types of locks called intention locks are used. Intention locks are table locks in InnoDB that indicate which type of lock (shared or exclusive) a transaction will require later for a row in that table. There are two types of intention locks used in InnoDB (assume that transaction T has requested a lock of the indicated type on table t):

Intention shared (IS): Transaction T intends to set S locks on individual rows in table t.

Intention exclusive (IX): Transaction T intends to set X locks on those rows.

For example, SELECT ... LOCK IN SHARE MODE sets an IS lock and SELECT ... FOR UPDATE sets an IX lock.

Intention Locking Protocol

The intention locking protocol is as follows:

Before a transaction can acquire an S lock on a row in table t, it must first acquire an IS or stronger lock on t.

Before a transaction can acquire an X lock on a row, it must first acquire an IX lock on t.

These rules can be conveniently summarized by means of the following lock type compatibility matrix(相容性矩阵).

X IX S IS
X Conflict Conflict Conflict Conflict
IX Conflict Compatible Conflict Compatible
S Conflict Conflict Compatible Compatible
IS Conflict Compatible Compatible Compatible

A lock is granted to a requesting transaction if it is compatible(兼容的,相容的) with existing locks, but not if it conflicts with existing locks. A transaction waits until the conflicting existing lock is released. If a lock request conflicts with an existing lock and cannot be granted because it would cause deadlock, an error occurs.

Thus, intention locks do not block anything except full table requests (for example, LOCK TABLES ... WRITE). The main purpose of IX and IS locks is to show that someone is locking a row, or going to lock a row in the table.

==============END==============

Intention Locks && Intention Locking Protocol

时间: 2024-10-15 02:33:50

Intention Locks && Intention Locking Protocol的相关文章

转 mysql Next-Key Locking

原文:http://dev.mysql.com/doc/refman/5.5/en/innodb-next-key-locking.html 14.5.2.5 Avoiding the Phantom Problem Using Next-Key Locking The so-called phantom problem occurs within a transaction when the same query produces different sets of rows at diffe

【转载】如果有人问你数据库的原理,叫他看这篇文章

原文:如果有人问你数据库的原理,叫他看这篇文章 本文由 伯乐在线 - Panblack 翻译,黄利民 校稿.未经许可,禁止转载!英文出处:Christophe Kalenzaga.欢迎加入翻译组. 一提到关系型数据库,我禁不住想:有些东西被忽视了.关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradata .但很少有文章讲解数据库是如何工作的.你可以自己谷歌/百度一下『关系型数据库原理』,看看结果多么的稀少[译者注:百度为您找到相关结果约1,850,000个…] 

[转]如果有人问你数据库的原理,叫他看这篇文章

推荐一篇文章:http://blog.jobbole.com/100349/  --原文出处 一提到关系型数据库,我禁不住想:有些东西被忽视了.关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradata .但很少有文章讲解数据库是如何工作的.你可以自己谷歌/百度一下『关系型数据库原理』,看看结果多么的稀少[译者注:百度为您找到相关结果约1,850,000个…] ,而且找到的那些文章都很短.现在如果你查找最近时髦的技术(大数据.NoSQL或JavaScript),你

MySQL锁和事务(一):InnoDB锁(MySQL 官方文档粗翻)

// 写在前面,实际上,数据库加锁的类型和范围受到多种因素的影响,例如数据库隔离等级,SQL语句,是否使用主键.索引等等.可以查看博文: http://www.cnblogs.com/zhaoyl/p/4121010.html 了解 这一章节讲述了InnoDB使用的锁类型. 共享锁(S)和独占锁(X) 意向锁 行锁(record lock,不知道叫 记录锁是不是更好,百度了一下有人叫行锁) 间隙锁(gap lock) Next-Key锁 插入意向锁 AUTO-INC(自增长)锁 空间锁(Pred

如果有人问你数据库的原理,叫他看这篇文章

一提到关系型数据库,我禁不住想:有些东西被忽视了.关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradata .但很少有文章讲解数据库是如何工作的.你可以自己谷歌/百度一下『关系型数据库原理』,看看结果多么的稀少[译者注:百度为您找到相关结果约1,850,000个-] ,而且找到的那些文章都很短.现在如果你查找最近时髦的技术(大数据.NoSQL或JavaScript),你能找到更多深入探讨它们如何工作的文章. 难道关系型数据库已经太古老太无趣,除了大学教材.研究文

MYSQL术语表

MYSQL术语表 http://dev.mysql.com/doc/refman/5.6/en/glossary.html MySQL Glossary These terms are commonly used in information about the MySQL database server. This glossary originated as a reference for terminology about the InnoDB storage engine, and th

数据库的原理,一篇文章搞定(三)

合并联接 合并联接是唯一产生排序的联接算法. 注:这个简化的合并联接不区分内表或外表:两个表扮演同样的角色.但是真实的实现方式是不同的,比如当处理重复值时. 1.(可选)排序联接运算:两个输入源都按照联接关键字排序. 2.合并联接运算:排序后的输入源合并到一起. 排序 我们已经谈到过合并排序,在这里合并排序是个很好的算法(但是并非最好的,如果内存足够用的话,还是哈希联接更好). 然而有时数据集已经排序了,比如: 如果表内部就是有序的,比如联接条件里一个索引组织表 [译者注: index-orga

数据库原理分析(强烈推荐)

转自:https://blog.csdn.net/ptsx0607/article/details/68941750 一提到关系型数据库,我禁不住想:有些东西被忽视了.关系型数据库无处不在,而且种类繁多,从小巧实用的 SQLite 到强大的 Teradata .但很少有文章讲解数据库是如何工作的.你可以自己谷歌/百度一下『关系型数据库原理』,看看结果多么的稀少[译者注:百度为您找到相关结果约1,850,000个-] ,而且找到的那些文章都很短.现在如果你查找最近时髦的技术(大数据.NoSQL或J

mysql锁

锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所有数据库必须解决的一个问题,锁冲突也是影响数据库并发访问性能的一个重要因素.从这个角度来说,锁对数据库而言显得尤其重要,也更加复杂.本章我们着重讨论MySQL锁机制的特点,常见的锁问题,以及解决MySQL锁问题的一些方法或建议. MySQL锁概述 相对其他数据库而言,MySQL的锁机制比较简单,其最显著