Preface
Last night one buddy in tech wechat group asked "what's intention locks of InnoDB?"Thus,I'm gonna say someting about it.As we all know,there're various types of lock in InnoDB engine such as record locks,gap locks,next key locks and so forth.Intention locks is another kind of granularity of lock of InnoDB.
Introduce
1. Intention Locks
Intention locks of InnoDB are table-level locks.It's generated to indicate which type of lock relevant to a certain row in which the transaction will involve(shared or exclusive lock).It seems like that one guy is booking a ticket of the train to somewhere while the ticket system broadcasts there's a guy mean to ocuppy a seat of certain compartment in the train.But it does not block the action of booking ticket on the same train from another guy at the same time(another intention lock).That is,intention locks does not block each other at all only if you are modify the same row(booking the same seat).It's the effect of exclusive lock instead of intention lock.
There're two kinds of intention locks in InnoDB:
- Intention shared lock(IS): It indicates that a transaction is setting(or going to set) a shared lock on several rows for shared query operations.
- Intention exclusive lock(IX): It indicates that a transaction is setting(or going to set) a exclusive lock on several rows for exclusive modification operations.
Notice,any transaction who want to get row-level lock(shared or exclusive lock) on a record in a table must get the intention locks first.Generally speaking,S row-level lock is versus IS while X row-level lock is versus IX.There conflict relationship shows below.
X |
IX |
S |
IS |
|
---|---|---|---|---|
X |
Conflict | Conflict | Conflict | Conflict |
IX |
Conflict | Compatible | Conflict | Compatible |
S |
Conflict | Conflict | Compatible | Compatible |
IS |
Conflict | Compatible | Compatible | Compatible |
What we can see is that intention locks does not conflict themselves and always be compatible.In most scenarios,Intention locks do not block other transactions except for operation like "lock table ... writ;".The purpose of intention locks is to tell Innodb that someone is gonna add a lock on those relevant rows(for later reading or modifying) in a target table.
2. Insert Intention Locks
Now we've known clearly about intention locks,but what's the insert intention locks?Are the intention locks relevant with insert operations?Almost,it actually related to gap lock generated by insert operation.It indicates that transactions of insert do not need to wait for each other if they are not inserting at same position within the gap when they later get the exclusive locks on those inserted rows .
Examples
1. Intention locks test in the same session with "innodb_status_output_locks=off".
zlm@192.168.56.100: [zlm]>select @@transaction_isolation;
+-------------------------+
| @@transaction_isolation |
+-------------------------+
| REPEATABLE-READ |
+-------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>show variables like '%status%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_status_output | ON | //If set "on",it prints innodb status into error log and refresh every 20s by default.
| innodb_status_output_locks | OFF | //If set "off",there're no intention locks in result of "show engine innodb status;".
+----------------------------+-------+
rows in set (0.01 sec) zlm@192.168.56.100: [(none)]>select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| | //If does not specify "begin" or "start transaction" to explicitly generate a transaction,it commits after typing enter.
+--------------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>show create table t\G
*************************** . row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`id` int() NOT NULL,
`name` char() DEFAULT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
row in set (0.01 sec) zlm@192.168.56.100: [zlm]>begin;select * from t where name = 'aaa' lock in share mode;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | aaa |
+----+------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>select * from t for update;
+----+------+
| id | name |
+----+------+
| | aaa |
| | bbb |
| | ccc |
| | fff |
+----+------+
rows in set (0.00 sec) [root@zlm1 :: /data/mysql/mysql3306/data]
#echo '' > error.log [root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996003 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm
... ----------------------------
END OF INNODB MONITOR OUTPUT
============================
^C //There're no intention locks at all.
2. Intention locks test in the same session with "innodb_status_output_locks=on".
zlm@192.168.56.100: [zlm]>set @@global.innodb_status_output_locks=on;
Query OK, rows affected (0.00 sec) zlm@192.168.56.100: [zlm]>exit
Bye [root@zlm1 :: /data/mysql/mysql3306/data]
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. zlm@192.168.56.100: [(none)]>select @@transaction_isolation;
+-------------------------+
| @@transaction_isolation |
+-------------------------+
| REPEATABLE-READ |
+-------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>select @@global.innodb_status_output_locks;
+-------------------------------------+
| @@global.innodb_status_output_locks |
+-------------------------------------+
| |
+-------------------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>select @@global.innodb_status_output;
+-------------------------------+
| @@global.innodb_status_output |
+-------------------------------+
| |
+-------------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| |
+--------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>use zlm
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
zlm@192.168.56.100: [zlm]>begin;select * from t where name = 'aaa' lock in share mode;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | aaa |
+----+------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>select * from t for update;
+----+------+
| id | name |
+----+------+
| | aaa |
| | bbb |
| | ccc |
| | fff |
+----+------+
rows in set (0.00 sec) [root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996003 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm
TABLE LOCK table `zlm`.`t` trx id lock mode IS //Here's an "IS" intention lock generated by "select ... lock in share mode;" operation.
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock mode S //Here's a "S" shared lock of records.
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261011f; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc bbb ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261012e; asc a .;;
: len ; hex ; asc ;;
: len ; hex ; asc ccc ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db721; asc - !;;
: len ; hex 360000012c2a35; asc ,*;;
: len ; hex ; asc ;;
: len ; hex ; asc fff ;; TABLE LOCK table `zlm`.`t` trx id lock mode IX //Here's an "IX" intertion lock generated by "select ... for update;" operation.
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X //Here's a "X" exclusive lock of records.
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261011f; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc bbb ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261012e; asc a .;;
: len ; hex ; asc ;;
: len ; hex ; asc ccc ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db721; asc - !;;
: len ; hex 360000012c2a35; asc ,*;;
: len ; hex ; asc ;;
: len ; hex ; asc fff ;;
... ----------------------------
END OF INNODB MONITOR OUTPUT
============================
^C //We've got an "IS" intention loc,an "IX" intention lock,four "S" locks and four "X" locks.
//Why does "slect ... where name = 'aaa' lock in share mode;" operation holds four "S" locks while we just specify one line?'cause "name" column does not has index key on it.
//Therefore,if we need to observe the intention locks.The variable of "innodb_status_output_locks" should be set "on".
3. Intention locks test between two sessions.
//Session 1:
zlm@192.168.56.100: [zlm]>select @@global.innodb_status_output;
+-------------------------------+
| @@global.innodb_status_output |
+-------------------------------+
| |
+-------------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| |
+--------------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>begin;select * from t where name = 'aaa' lock in share mode;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | aaa |
+----+------+
row in set (0.00 sec) //Session 2:
zlm@192.168.56.100: [(none)]>select @@global.innodb_status_output_locks;
+-------------------------------------+
| @@global.innodb_status_output_locks |
+-------------------------------------+
| |
+-------------------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>select @@global.innodb_status_output;
+-------------------------------+
| @@global.innodb_status_output |
+-------------------------------+
| |
+-------------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| |
+--------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>begin;select * from t for update;
Query OK, rows affected (0.00 sec) ERROR (3D000): No database selected
zlm@192.168.56.100: [(none)]>begin;select * from zlm.t for update;
Query OK, rows affected (0.00 sec) ERROR (HY000): Lock wait timeout exceeded; try restarting transaction //Wait for 50 seconds(by default) then becomes timeout.
zlm@192.168.56.100: [(none)]> //Check the lock information in error log.
[root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996003 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec starting index read
mysql tables in use , locked
LOCK WAIT lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm Sending data
select * from zlm.t for update
------- TRX HAS BEEN WAITING SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; ------------------
TABLE LOCK table `zlm`.`t` trx id lock mode IX
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; ...
----------------------------
END OF INNODB MONITOR OUTPUT
============================
^C //Only an "IX" intention lock and an "X" record lock were found.There's no "IS" intention lock any more.
//Intention locks between transactons does not block each other,they don't conflict.Therefore,when session 2 is gonna to get "X" lock(for update),the "IX" intention lock was generated and the "IS" intention in session 1 didn't appear.
//How about reversing the operations in session 1 and session 2?Let's see below. //Session 1:
zlm@192.168.56.100: [zlm]>begin;select * from t for update;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | aaa |
| | bbb |
| | ccc |
| | fff |
+----+------+
rows in set (0.00 sec) //Session 2:
zlm@192.168.56.100: [(none)]>begin;select * from t where name = 'aaa' lock in share mode;
Query OK, rows affected (0.00 sec) ERROR (3D000): No database selected
zlm@192.168.56.100: [(none)]>begin;select * from zlm.t where name = 'aaa' lock in share mode;
Query OK, rows affected (0.00 sec) ERROR (HY000): Lock wait timeout exceeded; try restarting transaction
zlm@192.168.56.100: [(none)]> //Check the error log.
[root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996003 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm
TABLE LOCK table `zlm`.`t` trx id lock mode IX
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261011f; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc bbb ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261012e; asc a .;;
: len ; hex ; asc ;;
: len ; hex ; asc ccc ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db721; asc - !;;
: len ; hex 360000012c2a35; asc ,*;;
: len ; hex ; asc ;;
: len ; hex ; asc fff ;; ...
----------------------------
END OF INNODB MONITOR OUTPUT
============================
^C //We've still get merely "IX" intention lock.The different is that there're four "X" record lock genrated by session 1 and they blocks the session 2 to hold shared read lock on those records,becuase "X" record locks confilct with both "X" and "S" record locks.Remember that we have no index key on column "name" and "select ... where name = 'aaa' lock in share mode;" mean to hold all the "S" record locks on the "name" column.
4. Inert intention locks test.
//Session 1:
zlm@192.168.56.100: [(zlm)]>select @@transaction_isolation;
+-------------------------+
| @@transaction_isolation |
+-------------------------+
| REPEATABLE-READ |
+-------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [zlm]>begin;select * from t for update;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | aaa |
| | bbb |
| | ccc |
| | fff |
+----+------+
rows in set (0.00 sec) //Session 2:
zlm@192.168.56.100: [(zlm)]>select @@transaction_isolation;
+-------------------------+
| @@transaction_isolation |
+-------------------------+
| REPEATABLE-READ |
+-------------------------+
row in set (0.00 sec) zlm@192.168.56.100: [(none)]>begin;insert into zlm.t values(,'eee');
Query OK, rows affected (0.00 sec) ERROR (HY000): Lock wait timeout exceeded; try restarting transaction
zlm@192.168.56.100: [(none)]> //Check the error log for detail of locks.
[root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996020 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec inserting
mysql tables in use , locked
LOCK WAIT lock struct(s), heap size , row lock(s) //The two lock structs were intention lock("IX") and insert intention lock.
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm update
insert into zlm.t values(,'eee')
------- TRX HAS BEEN WAITING SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X insert intention waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; //Session 1 holds all "X" record locks of table "t".So it showed supremum what means the gap is infinite and no record can be inserted into the table at all. ------------------
TABLE LOCK table `zlm`.`t` trx id lock mode IX //The "IX" intention lock of session 2.
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X insert intention waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; ---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm
TABLE LOCK table `zlm`.`t` trx id lock mode IX //The "IX" intention lock of session 1.
RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex 73757072656d756d; asc supremum;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a8000002610110; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc aaa ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261011f; asc a ;;
: len ; hex ; asc ;;
: len ; hex ; asc bbb ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261012e; asc a .;;
: len ; hex ; asc ;;
: len ; hex ; asc ccc ;; Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db721; asc - !;;
: len ; hex 360000012c2a35; asc ,*;;
: len ; hex ; asc ;;
: len ; hex ; asc fff ;; ...
----------------------------
END OF INNODB MONITOR OUTPUT
============================
^C //Session 2 meant to get an insert intention lock when it was executing "insert into xxx" but waited until timeout.
//Whatif we only lock a certain record,what will session do then?Let's see below. //Session 1:
zlm@192.168.56.100: [zlm]>begin;select * from t where id= for update;
Query OK, rows affected (0.00 sec) +----+------+
| id | name |
+----+------+
| | ccc |
+----+------+
row in set (0.00 sec) //Session 2:
zlm@192.168.56.100: [(none)]>begin;insert into zlm.t values(,'ccc');
ERROR (HY000): Lock wait timeout exceeded; try restarting transaction
zlm@192.168.56.100: [(none)]> //Check error log again.
[root@zlm1 :: /data/mysql/mysql3306/data]
#tail -f error.log ...
------------
TRANSACTIONS
------------
Trx id counter
Purge done for trx's n:o < 2996020 undo n:o < 0 state: running but idle
History list length
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION , ACTIVE sec inserting
mysql tables in use , locked
LOCK WAIT lock struct(s), heap size , row lock(s), undo log entries
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm update
insert into zlm.t values(,'ccc')
------- TRX HAS BEEN WAITING SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id page no n bits index id of table `zlm`.`t` trx id lock_mode X locks gap before rec insert intention waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex ; asc ;; ------------------
TABLE LOCK table `zlm`.`t` trx id lock mode IX
RECORD LOCKS space id page no n bits index id of table `zlm`.`t` trx id lock_mode X locks gap before rec insert intention waiting
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex ; asc ;; ---TRANSACTION , ACTIVE sec
lock struct(s), heap size , row lock(s)
MySQL thread id , OS thread handle , query id zlm1 192.168.56.100 zlm
TABLE LOCK table `zlm`.`t` trx id lock mode IX
RECORD LOCKS space id page no n bits index id of table `zlm`.`t` trx id lock_mode X
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex ; asc ;; RECORD LOCKS space id page no n bits index GEN_CLUST_INDEX of table `zlm`.`t` trx id lock_mode X locks rec but not gap
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex 0000002db708; asc - ;;
: len ; hex a800000261012e; asc a .;;
: len ; hex ; asc ;;
: len ; hex ; asc ccc ;; RECORD LOCKS space id page no n bits index id of table `zlm`.`t` trx id lock_mode X locks gap before rec
Record lock, heap no PHYSICAL RECORD: n_fields ; compact format; info bits
: len ; hex ; asc ;;
: len ; hex ; asc ;; //The locks seem to be more and more complicated.
//Session 1(TRANSACTION 2996023) holded an "IX" intention lock,a "X" record lock,two gap locks.
//Session 2(TRANSACTION 2996024) asked for holded an "IX" intention lock and asked for an intert intention lock which was relevant with the gap before the record it meant to insert.The transaction of session 2 waited until timeout.
Summary
- intention locks are table-level locks created by InnoDB automatically when we have intentions to modify a certain record(or some of relevant records) in these tables.
- The main effect of intention locks is to make InnoDB be more compatible in multidimensional lock granularity(both table-level and row-level locks).
- It can simplify the mechanism in checking record locks of a certain table.For exmple,MySQL don't need to retrieve the full table when a client(or session) is modifying(or going to modify) records in that table.
- The variables "innodb_status_output_locks" should be set "on",if we want to see them in the output of "show engine innodb status" statement.
- Insert intention locks is similar with intention locks but it's merely relevant with those insert operations.