当前位置:网站首页>Mysql database lock learning notes
Mysql database lock learning notes
2022-07-07 09:14:00 【White butterfly】
What is a lock
A lock is a mechanism by which a computer coordinates multiple processes or threads to access a resource concurrently , Used to manage concurrent access to shared resources
Table lock
Table lock , Lock the whole table with each operation . Large locking size , The highest probability of lock collisions , Lowest degree of concurrency . Apply to MyISAM、 InnoDB Wait for the storage engine
Table locks
- Watch reading lock ( grammar :lock tables Table name read; )
- Watch write lock ( grammar :lock tables Table name write; )
- Release the lock (unlock tables)
Read the lock :
Write lock :
Metadata lock
meta data lock , Metadata lock , Abbreviation MDL.
MDL The main function of locks is to maintain Data consistency of table metadata , When there are transactions on the table , The table structure cannot be modified . for fear of DML And DDL Conflict , Ensure the correctness of reading and writing
Intent locks
for fear of DML When executed , Conflict between row lock and table lock , stay InnoDB Intention lock is introduced in , So that the table lock does not need to check whether each row of data is locked , Use intent lock to reduce the checking of table lock .
- Intention sharing lock (IS): By statement select … lock in share mode add to ; And Table locks share locks (read) compatible , Exclusive lock with watch lock (write) Mutually exclusive .
- Intending to be exclusive (IX): from insert、update、delete、select…for update add to ; Share lock with table lock (read) And exclusive lock (write) Are mutually exclusive , Intent locks are not mutually exclusive .
Once the transaction is committed , Intention sharing lock 、 The intentional exclusive lock will be automatically cancelled
Row-level locks
Row-level locks , Each operation locks the corresponding row data . Locking granularity minimum , The lowest probability of lock collisions , Highest concurrency . Apply to InnoDB In the storage engine .
InnoDB The data is organized based on indexes , Row locking is achieved by locking the index items on the index , Instead of adding to the record lock . For row level locks , It is mainly divided into the following three categories :
Row lock
Shared lock (S): Allow a transaction to read a line , Prevent other transactions from obtaining exclusive locks on the same dataset .
Exclusive lock (X): Allow to get transaction update data of exclusive lock , Prevent other transactions from obtaining shared and exclusive locks of the same dataset .
When searching for a unique index , When performing equivalence matching on existing records , It will be automatically optimized as row lock .
InnoDB The row lock of is a lock added to the index , Retrieve data without index criteria , that InnoDB All items in the table will be marked Record and lock , here Will be upgraded to table lock .
Clearance lock & Temporary key lock
- Equivalent query on Index ( unique index ), When locking records that do not exist , Optimized for clearance lock .
- Equivalent query on Index ( It's not the only common index ), When traversing to the right, the last value does not meet the query requirements ,next-key lock Degenerate to clearance lock .
- Range query on Index ( unique index )– Access to the first value that does not satisfy the condition .
Be careful : The only purpose of a gap lock is to prevent other transactions from inserting gaps . Gap locks can coexist , The gap lock adopted by a transaction will not Prevent another transaction from adopting gap lock on the same gap .
The only purpose of a gap lock is to prevent other transactions from inserting gaps . Gap locks can coexist , A gap lock adopted by one transaction will not prevent another transaction from adopting a gap lock on the same gap .
边栏推荐
- Common short chain design methods
- Locust performance test 4 (custom load Policy)
- Golang etcdv3 reports an error. The attribute in grpc does not exist
- C语言指针(上篇)
- 面试题:高速PCB一般布局、布线原则
- [chaosblade: node CPU load, node network delay, node network packet loss, node domain name access exception]
- [chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
- Interpretation of MySQL optimization principle
- Locust performance test 2 (interface request)
- How does the project manager write the weekly summary and weekly plan?
猜你喜欢
UnityShader入门精要个人总结--基础篇(一)
Postman interface debugging method
H3C vxlan configuration
How to pass the PMP Exam in a short time?
Three updates to build applications for different types of devices | 2022 i/o key review
MySql数据库-事务-学习笔记
JWT certification used in DRF
Postman interface test (I. installation and use)
Confitest of fixture py
2022-06-30 unity core 8 - model import
随机推荐
寄存器地址名映射
5A summary: seven stages of PMP learning
Self awakening from a 30-year-old female programmer
Simulation volume leetcode [general] 1609 Parity tree
Port occupation troubleshooting
Unityshader introduction essentials personal summary -- Basic chapter (I)
Simulation volume leetcode [general] 1705 The maximum number of apples to eat
Common operating commands of Linux
[istio introduction, architecture, components]
Markdown editor Use of MD plug-in
C语言指针(下篇)
模拟卷Leetcode【普通】1557. 可以到达所有点的最少点数目
Several methods of calculating the average value of two numbers
OpenGL三维图形绘制
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
C language pointer (Part 2)
Unity Shader入门精要初级篇(一)-- 基础光照笔记
Run can start normally, and debug doesn't start or report an error, which seems to be stuck
模拟卷Leetcode【普通】1609. 奇偶树
Detailed learning notes of JVM memory structure (I)