当前位置:网站首页>事务隔离级别 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锁。
边栏推荐
- transform + asm资料
- 赋能「新型中国企业」,SAP Process Automation 落地中国
- GetMessage底层机制分析
- MySQL common graphics management tools | dark horse programmers
- [info() method in org.slf4j.logger]
- The intelligent epidemic prevention system provides safety guarantee for the resumption of work and production at the construction site
- 测试自学人必看:软件测试如何找测试项目?
- Junit单元测试框架详解
- Lake shore M91 fast hall measuring instrument
- Dom4j parsing XML, XPath retrieving XML
猜你喜欢
Shell高级进阶
Learn MySQL from scratch - database and data table operations
原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
使用环信提供的uni-app Demo,快速实现一对一单聊
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!
ECS summer money saving secret, this time @ old users come and take it away
智慧防疫系统为建筑工地复工复产提供安全保障
kubernetes命令入门(namespaces,pods)
如何正确使用Vertx操作Redis(3.9.4带源码分析)
随机推荐
求各种极限的方法
Learn MySQL from scratch - database and data table operations
torch.nn.functional.interpolate函数
OpenCV视频质量检测--清晰度检测
[to.Net] C set class source code analysis
GB28181之SIP协议
OpenCV视频质量诊断----视频遮挡诊断
宝,运维100+服务器很头疼怎么办?用行云管家!
Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
Witness the times! "The future of Renji collaboration has come" 2022 Hongji ecological partnership conference opens live broadcast reservation
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
【6.24-7.1】写作社区精彩技术博文回顾
Learning notes [Gumbel softmax]
kubernetes命令入门(namespaces,pods)
论文阅读【Discriminative Latent Semantic Graph for Video Captioning】
Reading the paper [learning to discretely compose reasoning module networks for video captioning]
见证时代!“人玑协同 未来已来”2022弘玑生态伙伴大会开启直播预约
GetMessage底层机制分析
商业智能BI开发和报表开发有什么本质区别?
Junit单元测试框架详解