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.

InnoDB意向锁和插入意向锁的更多相关文章

  1. InnoDB的锁机制浅析(二)—探索InnoDB中的锁(Record锁/Gap锁/Next-key锁/插入意向锁)

    Record锁/Gap锁/Next-key锁/插入意向锁 文章总共分为五个部分: InnoDB的锁机制浅析(一)-基本概念/兼容矩阵 InnoDB的锁机制浅析(二)-探索InnoDB中的锁(Recor ...

  2. mysql innodb插入意向锁

    innodb中有插入意向锁.专门针对insert,假设插入前,该间隙已经由gap锁,那么Insert会申请插入意向锁. 那么这个插入意向锁的作用是什么? 1.为了唤起等待.由于该间隙已经有锁,插入时必 ...

  3. innodb insert buffer 插入缓冲区的理解

    今天在做一个大业务的数据删除时,看到下面的性能曲线图 在删除动作开始之后,insert buffer 大小增加到140.对于这些状态参数的说明 InnoDB Insert Buffer 插入缓冲,并不 ...

  4. python,java操作mysql数据库,数据引擎设置为myisam时能够插入数据,转为innodb时无法插入数据

    今天想给数据库换一个数据引擎,mysiam转为 innodb 结果 python 插入数据时失败,但是自增id值是存在的, 换回mysiam后,又可以插入了~~ 想换php插入试试,结果php数据引擎 ...

  5. InnoDB Insert(插入)操作(下)--mysql技术内幕

    接上一篇文章,最后做的那个实验,我是想证明mysql innodb存储引擎,commit操作与flush数据到磁盘之间的关系,当与同事交流之后,他说,你应该把innodb_buffer_size的大小 ...

  6. InnoDB的锁机制浅析(四)—不同SQL的加锁状况

    不同SQL的加锁状况 文章总共分为五个部分: InnoDB的锁机制浅析(一)-基本概念/兼容矩阵 InnoDB的锁机制浅析(二)-探索InnoDB中的锁(Record锁/Gap锁/Next-key锁/ ...

  7. InnoDB的锁机制浅析(All in One)

    目录 InnoDB的锁机制浅析 1. 前言 2. 锁基本概念 2.1 共享锁和排它锁 2.2 意向锁-Intention Locks 2.3 锁的兼容性 3. InnoDB中的锁 3.1 准备工作 3 ...

  8. (转)InnoDB存储引擎MVCC实现原理

    InnoDB存储引擎MVCC实现原理 原文:https://liuzhengyang.github.io/2017/04/18/innodb-mvcc/ 简单背景介绍 MySQL MySQL是现在最流 ...

  9. MySql InnoDB中的锁研究

    # MySql InnoDB中的锁研究 ## 1.InnoDB中有哪些锁### 1. 共享和排他(独占)锁(Shared and Exclusive Locks) InnoDB实现标准的行级锁定,其中 ...

随机推荐

  1. sql注入二

    大家早上好!今天由我给大家带来<web安全之SQL注入篇>系列晨讲,首先对课程进行简单介绍,SQL注入篇一共分为三讲:        第一讲:“纸上谈兵:我们需要在本地架设注入环境,构造注 ...

  2. ASP.NET Web API编程——接口安全与角色控制

    1 API接口验证与授权 JWT JWT定义,它包含三部分:header,payload,signature:每一部分都是使用Base64编码的JSON字符串.之间以句号分隔.signature是”h ...

  3. js 模拟百度关键字搜索与跳转

    测试效果: css样式: ul{ display:none; } html代码: <input type="text" id="text" /> & ...

  4. Coursera 机器学习基石 第4讲 学习的可行性

    这一节讲述的是机器学习的核心.根本性问题——学习的可行性.学过机器学习的我们都知道,要衡量一个机器学习算法是否具有学习能力,看的不是这个模型在已有的训练数据集上的表现如何,而是这个模型在训练数据外的数 ...

  5. Fine Tuning

    (转载自:WikiPedia) Fine tuning is a process to take a network model that has already been trained for a ...

  6. firefox下载文件弹出框之终极解决方案-vbs模拟键盘操作

    由于近期一直被firefox的保存文件弹出框困扰,摸索尝试过几种方法,已有的方法可以跑通但是对对效果不太满意,因此一直在寻找合适的解决办法. 最近发现了也可以通过VBS来处理弹出框,速度也不错,其原理 ...

  7. MVC导航菜单高亮显示实现思路

    ///代码不是我写的,但是已经亲自测试过了,按照我的理解写的注释,不对的地方大家评论指出 @{ @*这个是把当前的路由值格式化并保存到currentController这个变量中,这里是格式化为Con ...

  8. ubuntu server遇到的问题

    1.在呢用is把隐藏的文件显示出来: ls -a 就可以啦 2.vim退出: 在命令模式中,连按两次大写字母Z,若当前编辑的文档曾被修改过,则Vi保存该文档后退出,返回到shell:若当前编辑的文档没 ...

  9. Swift_枚举

    Swift_枚举 点击查看源码 空枚举 //空枚举 enum SomeEnumeration { // enumeration definition goes here } 枚举基本类型 //枚举基本 ...

  10. CF1066D Boxes Packing(二分答案)

    题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$.$Maksim$先生想把物品装入盒子中.对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个 ...