ギャップロックの発生を抑える方法 • トランザクション分離レベルをREAD COMMITTEDに変更すれば、 ギャップロックを取得しない 13 MySQL 8.0 Reference Manual / 15.7.1 InnoDB Locking / Gap Locks https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html#innodb-gap-locks => Gap locking can be disabled explicitly. This occurs if you change the transaction isolation level to READ COMMITTED. Under these circumstances, gap locking is disabled for searches and index scans and is used only for foreign-key constraint checking and duplicate-key checking. There are also other effects of using the READ COMMITTED isolation level. Record locks for nonmatching rows are released after MySQL has evaluated the WHERE condition. For UPDATE statements, InnoDB does a “semi-consistent” read, such that it returns the latest committed version to MySQL so that MySQL can determine whether the row matches the WHERE condition of the UPDATE.
その他の影響 • トランザクション分離レベルをREAD COMMITTEDに変更すれば、 インデックスを使わない更新処理によるロックも行ロックになる (本資料の22~24ページ参照) 14 MySQL 8.0 Reference Manual / 15.7.1 InnoDB Locking / Gap Locks https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html#innodb-gap-locks => Gap locking can be disabled explicitly. This occurs if you change the transaction isolation level to READ COMMITTED. Under these circumstances, gap locking is disabled for searches and index scans and is used only for foreign-key constraint checking and duplicate-key checking. There are also other effects of using the READ COMMITTED isolation level. Record locks for nonmatching rows are released after MySQL has evaluated the WHERE condition. For UPDATE statements, InnoDB does a “semi-consistent” read, such that it returns the latest committed version to MySQL so that MySQL can determine whether the row matches the WHERE condition of the UPDATE.