简体   繁体   English

MySQL InnoDB 意向锁有什么用?

[英]What are MySQL InnoDB intention locks used for?

I have read the MySQL mannual about intention lock: http://dev.mysql.com/doc/refman/5.5/en/innodb-locking.html#innodb-intention-locks我已经阅读了MySQL关于意向锁的手册: http://dev.mysql.com/doc/refman/5.5/en/innodb-locking.html#innodb-intention-locks

It says that "To make locking at multiple granularity levels practical", but how?它说“使多个粒度级别的锁定变得实用”,但是如何呢? It does not tell us about it.它没有告诉我们这件事。

Can anyone give a detailed explanation and a sample?任何人都可以给出详细的解释和示例吗?

Think of the InnoDB data space as a collection of databases, each database being a collection of tables, and each table being a collection of rows. 将InnoDB数据空间视为数据库集合,每个数据库都是表的集合,每个表都是行的集合。 This forms a hierarchy, where lower and lower levels offer more and more granularity. 这形成了一个层次结构,其中较低和较低级别提供越来越多的粒度。

Now, when you want to update some part(s) of this tree in a transaction, how do you do it? 现在,当您想要在事务中更新此树的某些部分时,您是如何做到的? Well, InnoDB employs multiple granularity locking (MGL) . 好吧,InnoDB采用多粒度锁定(MGL) The mechanism in MGL is that you specify "intentions" to lock at a particular granularity level as shared or exclusive, then MGL combines all these intentions together and marches up the hierarchy until it finds the minimum spanning set that has to be locked given those intentions. MGL中的机制是指定“意图”将特定粒度级别锁定为共享或排他,然后MGL将所有这些意图组合在一起并推进层次结构,直到找到必须锁定的最小生成集给定这些意图。

Without intention locks, you have high level shared and exclusive locks which really don't give you much flexibility: they're all or nothing, which is what we see in MyISAM. 没有意图锁定,你有高级共享独占锁定,这实际上没有给你很大的灵活性:它们是全部或全部,这是我们在MyISAM中看到的。 But MGL brings the concept of intended shared and intended exclusive , which it uses as I said above to provide "just enough" locking. 但是MGL带来了预期的共享预期的独占概念,正如我上面提到的那样,它提供了“恰到好处”的锁定。

If you'd like to know about the specific C level implementation, refer to Introduction to Transaction Locks in InnoDB . 如果您想了解特定的C级实现,请参阅InnoDB中的事务锁简介

From this link这个链接

the table-level intention locks are still not released so other transactions cannot lock the whole table in S or X mode.表级意向锁仍未释放,因此其他事务无法在 S 或 X 模式下锁定整个表。

I think the existance of intention lock is to allow table locking more effective(Mysql don't have to travse the entrie tree to see if there is a conflicted lock).我认为意向锁的存在是为了让表锁更有效(Mysql不必遍历entrie树来查看是否有冲突锁)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM