当前位置:网站首页>数据库-当前读与快照读
数据库-当前读与快照读
2022-07-06 06:08:00 【雪峰.贵】
当前读:insert update delete for update
快照读:不加锁的非阻塞读,select。目的是为了提高并发性能
在RC隔离级别下,当前读与快照读结果是一样的。
在RR隔离级别下,当前读与快照读结果有可能是不一样的
例如
事务1 与事务2 都读了一条数据。
select * from user where id =1;
id money
1 200
事务2 修改数据
update user set money = 1000 where id = 1;
commit;
事务1 再读(快照读):
select * from user where id = 1;
id money
1 200
而在执行(当前读) select * from user where id = 1 for update;
id money
1 1000
RR 级别下非阻塞读的实现原理:
数据行实际还有3个字段分别为:
DB_TRX_ID :修改这个数据的事务ID
DB_ROLL_PRT:回滚指针
DB_ROW_ID:隐藏的行ID
事务id=1,把数据从12 改为了32。
- 该行加排他锁
- 复制修改前数据,到undo log里面
- 修改当前行数据,填写事务id,回滚指针

事务id=2,又对此行进行Field3进行修改. - 加排他锁
- 复制修改前数据,到undo
- 修改当前行数据,填写事务id,回滚指针
每做一次修改,都会生成一条UNDO log数据。在事务来快照读数据的时候会通过readView算法,用当前事务id与log的DB_TRX_ID比较来确定是取哪个版本的数据。
边栏推荐
- As3013 fire endurance test of cable distribution system
- 误差的基本知识
- [C language syntax] the difference between typedef struct and struct
- HCIA review
- 把el-tree选中的数组转换为数组对象
- H3C S5820V2_ Upgrade method after stacking IRF2 of 5830v2 switch
- Arrays and collections
- 一文揭开,测试外包公司的真 相
- How to recover Huawei router's forgotten password
- Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
猜你喜欢
随机推荐
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
Database: ODBC remote access SQL Server2008 in oracel
Function of contenttype
Usage of test macro of GTEST
全链路压测:构建三大模型
[postman] dynamic variable (also known as mock function)
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
[C language syntax] the difference between typedef struct and struct
HCIA复习
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Software test interview questions - Test Type
一文揭开,测试外包公司的真 相
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
Network protocol model
Nodejs realizes the third-party login of Weibo
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
對數據安全的思考(轉載)
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
How Huawei routers configure static routes
isam2运行流程







