# 什么是插入意向锁？

Insert Intention Lock，中文我们也称之为插入意向锁。

## 1. 为什么需要插入意向锁

id 是主键自增；age 是一个普通索引，现在表中有如下数据：

## 2. 什么是插入意向锁

An insert intention lock is a type of gap lock set by INSERT operations prior to row insertion. This lock signals the intent to insert in such a way that multiple transactions inserting into the same index gap need not wait for each other if they are not inserting at the same position within the gap. Suppose that there are index records with values of 4 and 7. Separate transactions that attempt to insert values of 5 and 6, respectively, each lock the gap between 4 and 7 with insert intention locks prior to obtaining the exclusive lock on the inserted row, but do not block each other because the rows are nonconflicting.

## 4. 小结

1. 插入意向锁虽然名字中有意向二字，但实际上是一个特殊的间隙锁。
2. 插入意向锁之间不互斥。
3. 插入意向锁和排他锁之间互斥。