当前位置:网站首页>mysql innodb 存储引擎的特性—行锁剖析
mysql innodb 存储引擎的特性—行锁剖析
2022-07-03 15:05:00 【小姐姐修灯泡吗】
先放上一张思维导图,没办法很穷只能用免费版的模板,毕竟我还在每天吃土,没钱办会员。看懂这个图,其实对于 innodb 存储引擎的特性你已经掌握了。
一、mysql的常用存储引擎
myisam:不支持事务,表锁。数据文件和索引文件分开,文件可压缩
innnodb:支持事务,行锁(可升级为表锁),支持主外键等。
今天主要讨论innodb的存储引擎,其他不多做补充。
二、事物的隔离级别
先在网上随意找个图,说下结论,在mysql的 innodb搜索引擎下,默认的RR可重复读级别下,是可以解决幻读的。图中并不准确,已标出
图中已有各个情况下的解释,这里我简单明了的快速掠过
脏读: 事务A读取了事务B未提交的数据 A读 B update未提交
不可重复读:事务A读取2次,2次数据不一致 A读2次,B update已提交
幻读 :A 范围查询读了2次,B insert后 (临界锁: 左开右闭可以解决,可以对当前的范围查找加上写锁,将导致不能插入数据,也就不会两次
范围查找结果集不一致)
三、基于隔离级别的思考
普通场景,并发或者业务要求不高:我们的查询语句基本都是快照度MVCC
该并发场景下,要保证隔离性,那就只能加锁了,利用锁的互斥性控制,LBCC当前读。
1.利用锁 lbcc当前读
insert
delect
update
// 行锁分类
select 。。。。。for update 写锁
select 。。。。。lock in share mode 读锁
2.快照 MVCC
普通的select语句都是快照都是
四、innodb下锁是怎么实现的呢,为什么临界锁可以解决幻读呢?
1.innnodb时默认在给索引上加上行锁,如果查询的条件不是索引,对不起将升级为表锁
2. 行锁的具体实现和分类 :
记录锁:
1.当sql按找等值匹配方式对索引进行数据的检索
2.命中数据
间隙锁:左开右开
1.当sql按找等值匹配方式对索引进行数据的检索
2.数据不命中时
临界锁: 左开右闭
1.当SQL执行按找范围查找对索引进行数据检索时
2.且有数据命中时
关于图的附加说明到此为止,如果有疑问或不同的意见欢迎提出学习。
至此讲的是事物的隔离级别中引申的锁机制
但是还是想分享下事物的传播行为,特别是一个很常见的场景,同一个类中,事务方法A调用非事务方法B,事务是生效的,且无论是A还是B方法发生异常都会回滚事务。
有时间写代码验证下,这里先贴一个作者写的结论。可以转载查看https://blog.csdn.net/qq_39355504/article/details/109893065
边栏推荐
- [engine development] in depth GPU and rendering optimization (basic)
- 什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
- Qt development - scrolling digital selector commonly used in embedded system
- Web server code parsing - thread pool
- 牛客 BM83 字符串变形(大小写转换,字符串反转,字符串替换)
- C language dup2 function
- Yolov5 advanced 8 format conversion between high and low versions
- B2020 points candy
- [wechat applet] wxss template style
- C language DUP function
猜你喜欢
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
[engine development] in depth GPU and rendering optimization (basic)
There are links in the linked list. Can you walk three steps faster or slower
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
Zero copy underlying analysis
PS tips - draw green earth with a brush
QT - draw something else
Qt development - scrolling digital selector commonly used in embedded system
CentOS7部署哨兵Redis(带架构图,清晰易懂)
Vs+qt multithreading implementation -- run and movetothread
随机推荐
QT program font becomes larger on computers with different resolutions, overflowing controls
Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
Awvs batch operation script
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5系列(一)——网络可视化工具netron
Byte practice surface longitude
.NET六大设计原则个人白话理解,有误请大神指正
Introduction to opengl4.0 tutorial computing shaders
cpu飙升排查方法
Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
PS tips - draw green earth with a brush
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
Yolov5 advanced nine target tracking example 1
[engine development] rendering architecture and advanced graphics programming
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
NOI OPENJUDGE 1.6(09)
[ue4] Niagara's indirect draw
Functional modules and application scenarios covered by the productization of user portraits