Under what scenario table lock

Under what scenario table lock

InnoDB defaults row lock, escalate to a table lock when not in use index fields queries. MySQL is not designed to give you digging. It has its own design purposes.
Even if you use the index field in a condition, MySQL will perform according to their plan, consider whether to use the index (so explain command will possible_key and key). If you think that MySQL full table scan higher efficiency, it will not use the index, in this case the use InnoDB table locks instead of row locks. Therefore, when analyzing locking conflicts, do not forget to check the SQL execution plan to verify the real use of the index.

The first case: a full table update . Services need to update most or all of the data, and the table and relatively large. If the row locks, the transaction will lead to low efficiency, which may result in additional transaction locks for a long time waiting and more locks conflict.

The second case: multi-table cascade . Transactions involving several tables, complex queries association, is likely to lead to deadlock, resulting in a large number of transaction rollback. If this case involved a one-time transaction locking table, so as to avoid deadlocks and reduce overhead due to database transaction rollback brings.

Guess you like

Origin www.cnblogs.com/shujiying/p/12551758.html