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. SP34096 【DIVCNTK - Counting Divisors (general)】

    题目 求 \[\sum_{i=1}^n \sigma(i^k)\] 我们先来设一个函数\(f(i)=\sigma(i^k)\) 根据约数个数定理 \[f(p)=\sigma(p^k)=k+1\] \[ ...

  2. VS2013安装部署过程详解

    注意:缺少安装部署的小伙伴,看上一篇有详细介绍 程序在“Release”平台下编译运行没有错误 第一步:“新建”------“项目”------“其他项目类型”------“安装部署”------“I ...

  3. A Gentle Introduction to Transfer Learning for Deep Learning | 迁移学习

    by Jason Brownlee on December 20, 2017 in Better Deep Learning Transfer learning is a machine learni ...

  4. 【luogu P1939 【模板】矩阵加速(数列)】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1939 对于矩阵推序列的式子: 由题意知: f[x+1] =1f[x] + 0f[x-1] + 1f[x-2] ...

  5. Jstorm TimeCacheMap源代码分析

    /*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/ pac ...

  6. Java日期类题目

    每类题都有各种各样解决的方式,大家随意发散 分析以下需求,并用代码实现 1.已知日期字符串:"2015-10-20",将该日期字符串转换为日期对象 2.将(1)中的日期对象转换为日 ...

  7. git详细使用教程入门到精通(史上最全的git教程)

    Git是分布式版本控制系统,那么它就没有中央服务器的,每个人的电脑就是一个完整的版本库,这样,工作的时候就不 需要联网了,因为版本都是在自己的电脑上.既然每个人的电脑都有一个完整的版本库,那多个人如何 ...

  8. XML解析方式

    两种解析方式概述 dom解析 (1)是W3C组织推荐的处理XML的一种解析方式. (2)将整个XML文档使用类似树的结构保存在内存中,在对其进行操作. (3)可以方便的对XML进行增删改查的操作 (4 ...

  9. 05 oracle中lock和latch的用途

    oracle中lock和latch的用途   本文向各位阐述Oracle的Latch机制,Latch,用金山词霸翻译是门插栓,闭锁,专业术语叫锁存器,我开始接触时就不大明白为什么不写Lock,不都是锁 ...

  10. MFC+ODBC+SQL Server+Visual C++

    利用SQL Server 和MFC实现对数据库的简单管理 工具:SQL Server,VC6.0 步骤如下: 1.建立一个数据库studentinfo,再建立一个表testtable,表设计和初始值如 ...