当前位置:网站首页>事务隔离级别 gap锁 死锁
事务隔离级别 gap锁 死锁
2022-07-01 18:45:00 【这样の我】
1.事务隔离级别
- 序列化(SERIALIZABLE)
- 可重复读(REPEATABLE READ)
- 提交读(READ COMMITTED)
- 未提交读(READ UNCOMMITTED)
四个隔离级别分别对应增删改查
2.gap锁分析:
未提交读(READ UNCOMMITTED):增删改查不加锁。
提交读(READ COMMITTED):增时锁住索引一段的距离(如添加时索引为12,锁住一段索引在12上下的一段距离),等事务提交时候释放锁。
可重复读(REPEATABLE READ):增删改数据时锁住索引一段距离(insert如上,删改时若索引为12,则锁住上一行以及下一行索引的距离,若没有上一行或者下一行,则锁住一段距离)
序列化(SERIALIZABLE):增删改查都会加锁,事务只能一个一个提交,获取到的事务直接锁表
3.gap 死锁
两个事务同事获得了一段区间锁,且同时操作区间
111 delete from ts_column_log_test wherecol_id=10;
222 delete from ts_column_log_test where col_id=11;
111 INSERT INTO ts_column_log_test (col_id,start_time, end_time, data_time, status) VALUES (10, NULL, NULL, '20111209','running');
222 INSERT INTO ts_column_log_test (col_id, start_time, end_time,data_time, status) VALUES (11, NULL, NULL, '20111209', 'running');
这个时候,你可能就会得到错误提示ERROR 1213 (40001): Deadlock found when trying toget lock; try restarting transaction。
原因是前两条语句都已经获得了[2,20)这个区间内记录的S锁,然后两个事务又分别对该区间段内的col_id=10这个位置请求X锁,这时就发生死锁,谁都请求不到X锁,因为互相都持有S锁。
边栏推荐
- 测试自学人必看:软件测试如何找测试项目?
- 241. Different Ways to Add Parentheses
- 118. 杨辉三角
- Is PMP cancelled??
- 【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
- XML语法、约束
- Dom4j parsing XML, XPath retrieving XML
- Lake shore optimag superconducting magnet system om series
- Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
- English语法_形容词/副词3级 -注意事项
猜你喜欢

uni-app微信小程序一键登录获取权限功能

测试自学人必看:软件测试如何找测试项目?

Supervarimag superconducting magnet system SVM series

论文泛读【FiLM: Visual Reasoning with a General Conditioning Layer】

DTD建模

智慧防疫系统为建筑工地复工复产提供安全保障

Solidity - truncated and checked modes of arithmetic operations - new features of 0.8.0

论文阅读【Learning to Discretely Compose Reasoning Module Networks for Video Captioning】
![[pytorch record] automatic hybrid accuracy training torch cuda. amp](/img/a5/cf1eb2801380cf2887dfd532d3eb1e.jpg)
[pytorch record] automatic hybrid accuracy training torch cuda. amp

Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
随机推荐
[go ~ 0 to 1] day 4 June 30 defer, structure, method
Solution and summary of Nacos startup failure
宝,运维100+服务器很头疼怎么办?用行云管家!
ECS summer money saving secret, this time @ old users come and take it away
正则表达式=Regex=regular expression
DTD建模
记一次 .NET 差旅管理后台 CPU 爆高分析
Write it down once Net travel management background CPU Explosion Analysis
【pytorch记录】模型的分布式训练DataParallel、DistributedDataParallel
面试题 16.16. 部分排序-双指针法
Facebook聊单,SaleSmartly有妙招!
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
axure不显示元件库
微信公众号开发相关流程及功能介绍
Implement a Prometheus exporter
[6.24-7.1] review of wonderful technical blog posts in the writing community
使用环信提供的uni-app Demo,快速实现一对一单聊
transform + asm资料
如何正确使用Vertx操作Redis(3.9.4带源码分析)
下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***