search

Home  >  Q&A  >  body text

mysql optimization - mysql innodb table lock problem

After testing, I found that the following situations will cause table locks
1.like
2.update, delete unconditional operations
3.update,delete are conditional operations but not primary key operations
Select will not lock the table whether it is conditional or unconditional, whether the condition is primary key or index, Is this correct? Is there something wrong with my test?

淡淡烟草味淡淡烟草味2773 days ago675

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-24 11:34:59

    select can specify various levels of locks such as shared locks, exclusive locks, etc., such as select ... FOR UPDATE.
    As for why locks are needed, here is a simple example. For example, if you have a document that inherits from the previous document, you can choose to add a read lock and lock the previous document to prevent others from modifying the previous document before you submit it. , causing data inconsistency.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-24 11:34:59

    As long as the condition does not contain the primary key, or contains the primary key but is not an equal sign or IN, the entire table will be locked, which includes all three situations in the question.

    Whether it is locking the entire table or locking a few rows, select adds read locks, and update and delete add write locks. As for what read locks and write locks are, you can Google them. As for the details, you can also look at the Transaction Isolation Level, which I won’t go into here.

    reply
    0
  • Cancelreply