当前位置:网站首页>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
边栏推荐
- Yolov5进阶之七目标追踪最新环境搭建(二)
- [ue4] cascading shadow CSM
- Incluxdb2 buckets create database
- 【pytorch学习笔记】Datasets and Dataloaders
- Yolov5进阶之九 目标追踪实例1
- Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
- Qt development - scrolling digital selector commonly used in embedded system
- What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
- el-switch 赋值后状态不变化
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
猜你喜欢
零拷贝底层剖析
cpu飙升排查方法
Pytoch deep learning and target detection practice notes
Influxdb2 sources add data sources
4-20-4-23 concurrent server, TCP state transition;
远程服务器后台挂起 nohup
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
Vs+qt multithreading implementation -- run and movetothread
[graphics] adaptive shadow map
随机推荐
什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
How to color ordinary landscape photos, PS tutorial
Unity hierarchical bounding box AABB tree
C language memory function
el-switch 赋值后状态不变化
C language fcntl function
B2020 分糖果
4-20-4-23 concurrent server, TCP state transition;
QT - draw something else
Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
Web server code parsing - thread pool
Introduction to opengl4.0 tutorial computing shaders
Awvs batch operation script
On MEM series functions of C language
基础SQL教程
What is machine reading comprehension? What are the applications? Finally someone made it clear
Yolov5进阶之八 高低版本格式转换问题
2022/02/14
Yolov5进阶之九 目标追踪实例1