当前位置:网站首页>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 .
边栏推荐
- Panel display technology: LCD and OLED
- PMP examination experience sharing
- [chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
- MySql数据库-事务-学习笔记
- C语言指针(习题篇)
- JVM 垃圾回收 详细学习笔记(二)
- C language pointer (special article)
- Full link voltage test of the e-commerce campaign Guide
- Markdown editor Use of MD plug-in
- C language for calculating the product of two matrices
猜你喜欢
Mysql数据库-锁-学习笔记
Implementation of corner badge of Youmeng message push
PMP Exam details after the release of the new exam outline
Druid monitoring - Introduction to JMX usage and principle
Output all composite numbers between 6 and 1000
Systick tick timer
H3C vxlan configuration
Reading notes of pyramid principle
C language pointer (exercises)
Led analog and digital dimming
随机推荐
Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
Do you have any certificates with high gold content?
OpenGL frame buffer
C language pointer (special article)
Confitest of fixture py
Record of structured interview
Analysis of Hessian serialization principle
Port multiplexing and re imaging
Cmake command line use
Original collection of hardware bear (updated on May 2022)
DRF defines views and routes
串口实验——简单数据收发
OpenGL 3D graphics rendering
C language pointer (Part 2)
面板显示技术:LCD与OLED
模拟卷Leetcode【普通】1705. 吃苹果的最大数目
Locust performance test 5 (analysis)
ChaosBlade:混沌工程简介(一)
【ChaosBlade:节点 CPU 负载、节点网络延迟、节点网络丢包、节点域名访问异常】
【istio简介、架构、组件】