当前位置:网站首页>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
边栏推荐
- Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
- [Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
- Besides lying flat, what else can a 27 year old do in life?
- Rasterization: a practical implementation (2)
- Tensor ellipsis (three points) slice
- Nppexec get process return code
- Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
- SQL server安装位置改不了
- Qt development - scrolling digital selector commonly used in embedded system
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Qt development - scrolling digital selector commonly used in embedded system

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer

Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text

Besides lying flat, what else can a 27 year old do in life?

The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%

Tencent internship interview sorting

运维体系的构建

B2020 分糖果

Troubleshooting method of CPU surge
随机推荐
Yolov5进阶之九 目标追踪实例1
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
el-switch 赋值后状态不变化
Unity hierarchical bounding box AABB tree
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
Vs+qt application development, set software icon icon
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
Introduction to opengl4.0 tutorial computing shaders
Byte practice surface longitude
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
【pytorch学习笔记】Transforms
PS tips - draw green earth with a brush
Pytoch deep learning and target detection practice notes
B2020 分糖果
QT - draw something else
官网MapReduce实例代码详细批注
零拷贝底层剖析
Yolov5 advanced 8 format conversion between high and low versions
4-29——4.32
Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share