Search code examples
mysqlconcurrencyinnodb

Does `UPDATE SET WHERE` have concurrency issues?


Consider the statement below

UPDATE SET is_locked = 1 WHERE id = 1 and is_locked = 0;

Does it have consistency problem under concurrent updates? Why?

(MySQL 5.7, with transaction isolation level of REPEATABLE-READ)


Solution

  • No, it does not, since update requires an exclusive lock on the record being updated and innodb will not grant more than 1 exclusive lock on a record at a time.