Table locks in SHOW INNODB STATUS

PREVIOUS POST
NEXT POST

Quite frequently I see people confused what table locks reported by SHOW INNODB STATUS really mean. Check this out for example:

This output gives us an impression Innodb has taken table lock on test/t1 table and many people tend to think Innodb in fact in some circumstances would abandon its row level locking and use table locks instead. I’ve seen various theories ranging from lock escalation to using table locks in special cases, for example when no indexes are defined on the table. None of this is right.

In fact Innodb uses Multiple Granularity Locking and there is always lock taken on the whole table before individual locks can be locked.
Such locks are called intention lock, hence abbreviation IX = Intention eXclusive. Intention locks do not work the same way as table locks – Intention exclusive lock does not prevent other threads taking intention shared or even intention exclusive locks on the same table.

What does Intention mean ? Just what it says. If Innodb sets intention exclusive lock on the table this means it plans to lock some of the rows in exclusive mode. What would these be used for ? They are used to be able to handle operation on the whole table – for example to drop the table you need to lock it exclusively.

So do not worry intention table locks you may observe in SHOW INNODB STATUS output, they almost never would be cause of your lock waits or deadlocks.

PREVIOUS POST
NEXT POST

Comments

  1. martin says

    Hi,

    I have a general (maybe stupid) question about MGL locking. For example, we have physical hierarchy db->table->row. I want modify row -> If I use MGL, put IX to DB, IX to table and X to row (as you shown). Can I use ony S and X locks? e.g. S lock on DB, X lock on table? => row cannot be inserted/deleted/updated/read. Or I can do S lock on DB, X lock on table, find row, X lock on row, unlock table, modify row. (I known, MGL come from predicate lock and its explanation is widely known [e.g. Gray: Transaction processing].

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *