in mysql document it said
It is also worth noting here that conflicting locks can be held on a gap by different transactions. For example, transaction A can hold a shared gap lock (gap S-lock) on a gap while transaction B holds an exclusive gap lock (gap X-lock) on the same gap. The reason conflicting gap locks are allowed is that if a record is purged from an index, the gap locks held on the record by different transactions must be merged.
I have a table users, the column id is primary key
mysql> select * from users;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | tom | 21 |
| 2 | jerry | 10 |
| 3 | eric | 18 |
| 5 | eric | 17 |
+----+-------+------+
4 rows in set (0.00 sec)
Sess1 mysql> start transaction;
mysql> select * from users where name='eric' for update;
+----+------+------+
| id | name | age |
+----+------+------+
| 3 | eric | 18 |
| 5 | eric | 17 |
+----+------+------+
2 rows in set (0.01 sec)
Sess2 mysql> start transaction;
mysql> select * from users where name='eric' lock in share mode; -- it's blocking!
if gap S-lock and gap X-lock can be hold by different transactions, why Sess2 is blocked?