当前位置:网站首页>数据库-当前读与快照读
数据库-当前读与快照读
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比较来确定是取哪个版本的数据。
边栏推荐
猜你喜欢
【微信小程序】搭建开发工具环境
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
C language bubble sort
[postman] test script writing and assertion details
[Thesis code] SML part code reading
GTSAM中李群的运用
LeetCode 732. 我的日程安排表 III
PAT(乙级)2022年夏季考试
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
LeetCode 731. 我的日程安排表 II
随机推荐
二维码的前世今生 与 六大测试点梳理
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
leaflet 地图
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
【Postman】Collections配置运行过程
Request forwarding and redirection
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
GTSAM中李群的运用
C language bubble sort
进程和线程的理解
(中)苹果有开源,但又怎样呢?
Amazon Engineer: eight important experiences I learned in my career
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
请求转发与重定向
[postman] collections - run the imported data file of the configuration
Interface test: what are the components of the URL in fiddler
LeetCode 739. 每日温度
[Thesis code] SML part code reading
Nodejs realizes the third-party login of Weibo
What are the test sites for tunnel engineering?