MySQL concurrent updates

前端 未结 1 824
遥遥无期
遥遥无期 2021-01-03 04:00

I have small POS system with server side uses PHP and MySql (InnoDB). When \"Sale\" is being completed the following query is executed for update stock quantity:

<         


        
相关标签:
1条回答
  • 2021-01-03 04:27
    1. If you use innodb, then all sql statements are executed in a transaction, you do not need to explicitly specify that.

    2. Concurrency control is done via locks, not transactions. Transactions may only determine the lifespan of locks.

    3. The update statement places an exclusive lock on the records that it wants to modify, meaning no other statements can modify (sometimes cannot even read) the locked record until the exclusive lock is released. So, your statement is safe from concurrency point of view.

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