Row lock (partial write)
Features:
bias InnoDB storage engine, lock large lock slow; there will be a deadlock; locking granularity smallest and lowest probability of lock conflicts, have the highest degree of concurrency.
The biggest difference InnoDB and MyISAM are two points: First, to support the transaction (TRANSACTION); the second is using row-level locking.
Affairs (Line Lock Support Services)
ACID properties of the transaction and its
problems caused by concurrent transactions:
update loss
dirty reads,
non-repeatable read (solutions to add a row lock)
phantom reads
transaction isolation level: (MYSQL default repeatable read)
case study:
Build SQL table
Line Lock Basic Presentation (add an index (row locks) do not have a full table scan to locate the line directly, using the primary key is the use of row locks)
different rows updated no problem
No index, row lock escalation to a table lock
varchar type b written in a numeric column index failed to make at this time session 2-operation will be stepping into a different line of waiting
gap lock Hazard
face questions: How often test a row lock
Case Conclusion
Row lock analysis
Optimization Tips
- As far as possible to retrieve all the data are done by the index, the index line to avoid no lock escalation to a table lock.
- Rational design of the index, minimizing lock range
- As a search condition is less, to avoid gaps lock
- Try to control the size of the transaction, and the length of time to reduce the amount of resources locked
- The transaction isolation level as low as possible