MySQL Atomic UPDATE in InnoDB vs MyISAM

前端 未结 1 1152
我寻月下人不归
我寻月下人不归 2021-01-18 07:47

Is this \"compare and swap\" statement always atomic regardless of engine (e.g. InnoDB or MyISAM)? :

UPDATE tbl_name SET locked=1 WHERE id=ID AND locked <         


        
1条回答
  •  鱼传尺愫
    2021-01-18 08:13

    Yes. In InnoDB, the row will be locked (make you have an unique index on id, the update locks all rows it has to scan), updated and the lock released. If you are not in an explicit transaction / auto-commit is on, each statement is run in its own transaction, but it's still a transaction and lockings are performed

    0 讨论(0)
提交回复
热议问题