当前位置:网站首页>[MySQL special] read lock and write lock
[MySQL special] read lock and write lock
2022-07-03 11:59:00 【Programmer Xiao Li】
mysql There are four queues in , Respectively store the information of the current acquisition of read lock 、 Currently obtain the information of write lock 、 Wait for the lock reading message 、 Wait for the message of writing the lock :
| queue | meaning |
| current read-lock queue | Currently acquire read lock queue |
| current write-lock queue | Currently get write lock queue |
| pending read-lock queue | Waiting for lock reading queue |
| pending write-lock queue | Waiting for the write lock queue |

Acquisition conditions of read lock
1. The current resource is not written and the lock is occupied .
2. There is currently no Waiting for the write lock queue There is no high priority write lock waiting in .
If the above conditions are met , The read lock can be obtained directly , If one cannot be satisfied , entering PRQ

Write lock acquisition conditions
1. The current resource is not occupied by write lock .
2. PWQ No waiting to write lock
3. RQ No read lock

lock , It's a computer .
Existing write lock , Repel any lock
as everyone knows , Write lock repels everything , For data security , And the accuracy of data reading , Write lock repels all other forms of lock .
Writing locks is like playing 【 Write 】 The computer game , Others must not play at the same time 【 Write 】 This computer , Want to play 【 Intention to write 】 I can't play . meanwhile , People who play games are also selfish , Afraid of losing and losing face , Don't let others watch 【 read 】, Want to see 【 Intentional reading 】 Don't let me see .

Existing lock reading , Exclude all forms of write lock , Including intentional write lock
When there is a read lock , No more write locks . But concurrent reads are allowed . Although intention lock is a kind of intention , The lock is not in the real sense , But there is also the truth that reading and writing are exclusive .
Reading a lock is like watching it on a computer 【 read 】 The movie , Others must not play at the same time 【 Write 】 The computer game , Want to play 【 Intention to write 】 I can't play . meanwhile , People who watch movies know how to share , Invite others to watch 【 read 】, Want to see 【 Intentional reading 】 Let's see .

When writing lock with existing intention , Exclude all entity locks
Intention writing lock , It means I want to write , The next step is to really get the write lock , Therefore, entity read / write locks will be excluded , But intention is intention after all , No practical significance has been obtained , You can't help but allow others to imagine .
Intentional lock writing is like waiting in line for the computer to play 【 Write 】 game , The next one is you , Waiting in line for so long , Others come to play 【 Write 】 You definitely don't agree with the game , Others come to see 【 read 】 You must not agree to the movie . Someone made a wish :” I hope it's time for me to play games next 【 Intention to write 】“, You say? :” If there is no accident, it will come to me right away , You go on YY Well , Allow you to think “. Someone made a wish :” I hope it's my next movie 【 Intentional reading 】“, You say? :” If there is no accident, it will come to me right away , You go on YY Well , Allow you to think “.

When the existing intention reads the lock , Exclude entity write lock
Intention to write lock is an intention , Intend to read , The next step is to acquire the read lock . This will exclude the actual write lock . As mentioned earlier, concurrent reading is allowed , Therefore, read lock will not be excluded . Intention is intention after all , You can't help but allow others to imagine .
Intentional lock reading is like waiting in line 【 Write 】 The movie , The next one is you , Others come to play 【 Write 】 You definitely don't agree with the game , Others come to see 【 read 】 You readily agree to the movie ( After all, I haven't arrived yet , Besides, he may invite me to watch ). Someone made a wish :” I hope it's time for me to play games next 【 Intention to write 】“, You say? :” If there is no accident, it will come to me right away , You go on YY Well , Allow you to think “. Someone made a wish :” I hope it's my next movie 【 Intentional reading 】“, You say? :” If there is no accident, it will come to me right away , Keep making wishes , Maybe we can watch it together “.

Update Use where When the conditions , Hit index , Lock a line , Row write lock use

Update Use where When the conditions , No hit index , Lock table

update Use where When the conditions , Hit index , But the scope of use , Locking clearance
update Use where Conditions , Some conditions use indexes , Lock all data rows covered by this index , Data row lock
Both transactions operate on two tables , Acquire different locks successively , Lead to a deadlock
边栏推荐
- Interview experience in summer camp of Central South University in 2022
- Keepalived中Master和Backup角色选举策略
- Qt OpenGL 旋转、平移、缩放
- Socket TCP for network communication (I)
- 安装electron失败的解决办法
- Go语言实现静态服务器
- (数据库提权——Redis)Redis未授权访问漏洞总结
- XML (DTD, XML parsing, XML modeling)
- Uniapp implementation Click to load more
- Extrapolated scatter data
猜你喜欢

Hongmeng third training (project training)

Vulnhub geminiinc V2

cgroup简介

Excel表格转到Word中,表格不超边缘纸张范围

VS2015的下载地址和安装教程

Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements

ftp登录时,报错“530 Login incorrect.Login failed”

vulnhub之GeminiInc v2

vulnhub之momentum

Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
随机推荐
previous permutation lintcode51
STL教程10-容器共性和使用场景
Unity3D学习笔记5——创建子Mesh
安装electron失败的解决办法
【mysql专项】读锁和写锁
Ripper of vulnhub
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
During FTP login, the error "530 login incorrect.login failed" is reported
简单工厂和工厂方法模式
ftp登录时,报错“530 Login incorrect.Login failed”
Redis 笔记 01:入门篇
MCDF Experiment 1
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
同事写了一个责任链模式,bug无数...
Vulnhub's Tomato (tomato)
vulnhub之momentum
并发编程-单例
Nestjs configuration service, configuring cookies and sessions
Go语言实现静态服务器