In MySQL5.7, when READ COMMITTED isolation level is used, or the deprecated innodb_locks_unsafe_for_binlogsystem variable is enabled, there is no InnoDB gap locking exceptfor foreign-key constraint checking and duplicate-key checking.Also, record locks for nonmatching rows arereleased after MySQL has evaluatedthe WHERE condition.
经验证手册里的东西有误。其实,测试情况并不是这样,重复键检查和外键检查并不是一定加gap锁。
外键检查
子表中更新的值