Table-level locks and row-level locks

MyISAM in mysql5.x  only supports table-level locks, while InnoDB supports row-level locks

Reprint: For details, please refer to http://www.jb51.net/article/50047.htm

1) Table-level lock: low overhead, fast locking; no deadlock; large locking granularity, the highest probability of lock conflict, and the lowest concurrency.
2) Row-level locks: high overhead, slow locking; deadlocks; the smallest locking granularity, the lowest probability of lock conflicts, and the highest concurrency.
3) Page lock: overhead and locking time are between table locks and row locks; deadlocks will occur; locking granularity is between table locks and row locks, and the degree of concurrency is average.

     The three types of locks each have their own characteristics. From the perspective of locks, table-level locks are more suitable for applications that focus on querying and only a small amount of data is updated according to index conditions, such as WEB applications; row-level locks are more suitable for A large number of concurrently updating a small amount of different data according to index conditions, and concurrently querying applications, such as some online transaction processing (OLTP) systems.

  The biggest difference between InnoDB locks and MyISAM locks is: First, it supports transactions (TRANCSACTION), and second, it adopts row-level locks; a transaction is a logical processing unit composed of a set of SQL statements, which has four attributes (ACID attributes for short), They are:

Atomicity, Consistent, Isolation, Durable

 

InnoDB row locks are implemented by locking index items, that is, only by retrieving data through index conditions, InnoDB uses row-level locks, otherwise table locks are used! Example: http://keshion.iteye.com/blog/1409563

 

Lock query SQL statement:

show OPEN TABLES where In_use > 0;

show processlist;

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS; 

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS; 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326861971&siteId=291194637