当前位置:网站首页>[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
边栏推荐
猜你喜欢
vulnhub之presidential
Hongmeng fourth training
Download address and installation tutorial of vs2015
《剑指offer 03》数组中重复的数字
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
Vulnhub narak
Qt+vtk+occt reading iges/step model
vulnhub之momentum
外插散点数据
Quantitative calculation research
随机推荐
shardingSphere分库分表<3>
Sheet1$.输出[Excel 源输出].列[XXX] 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项。”。
Excel表格转到Word中,表格不超边缘纸张范围
MySQL searches and sorts out common methods according to time
Colleagues wrote a responsibility chain model, with countless bugs
OpenGL 绘制彩色的三角形
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
vulnhub之pyexp
利用Zabbix动态监控磁盘I/O
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
【mysql官方文档】死锁
vulnhub之narak
DEJA_VU3D - Cesium功能集 之 054-模拟火箭发射全过程
Extrapolated scatter data
php 获取文件夹下面的文件列表和文件夹列表
Slam mapping and autonomous navigation simulation based on turnlebot3
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
MySQL uses the method of updating linked tables with update