Let's begin our story with below 2 test cases.

SQL代码

  1. Case1:
  2. HELLODBA.COM>set time on
  3. 10:22:09 HELLODBA.COM>update t_test1 set SECONDARY='A' where object_id = -1;
  4. 1 row updated.
  5. 10:22:22 HELLODBA.COM>commit;
  6. Commit complete.
  7. Session 1:
  8. 10:22:25 HELLODBA.COM>update t_test1 set SECONDARY='B' where  object_id = -1 and SECONDARY='B' and (select count(*) from t_test2 t1, t_test2 t2) > 0;
  9. 0 rows updated.
  10. 10:23:15 HELLODBA.COM>
  11. Session 2:
  12. 10:22:37 HELLODBA.COM>update t_test1 set SECONDARY='B' where object_id = -1;
  13. 1 row updated.
  14. 10:23:02 HELLODBA.COM>commit;
  15. Commit complete.
  16. 10:23:04 HELLODBA.COM>
  17. Case2:
  18. 10:25:38 HELLODBA.COM>update t_test1 set SECONDARY='A' where object_id = -1;
  19. 1 row updated.
  20. 10:25:48 HELLODBA.COM>commit;
  21. Commit complete.
  22. Session 1:
  23. 10:26:05 HELLODBA.COM>update t_test1 set SECONDARY='B' where  object_id = -1 and SECONDARY='A' and (select count(*) from t_test2 t1, t_test2 t2) > 0;
  24. 0 rows updated.
  25. 10:27:21 HELLODBA.COM>
  26. Session 2:
  27. 10:26:16 HELLODBA.COM>update t_test1 set SECONDARY='B' where object_id = -1;
  28. 1 row updated.
  29. 10:26:41 HELLODBA.COM>commit;
  30. Commit complete.
  31. 10:26:42 HELLODBA.COM>

If you observed these 2 cases carefully enough, you will find an intereting phenomena: No matter did Session 1 read the data block or not, it finally failed to update the data. The root cause is the difference between Current Mode Read and Consistent Gets.

As we know, to reduce the concurent conflicts, Oracle invole MVCC(Multiversion Concurrent Control, also known as MCC) method. With MVCC, unless modifying the same records, concurrent transactions will not block each other for consistent reason. They will undo the changes from log to align the data with the SCN that transaction started with. In oracle, such reading action is known as Consistent Reads (CR).

However, the CR data blocks are just a snapshot with specical timestamp, which means the data is read only. Hence, to modify the data, oracle should read CURRENT data blocks instead, which is DB Gets in Current Mode.

In an UPDATE, oracle will consistents get the data blocks with spcified filter and TX SCN. Then, with block ID, it reads the data in current mode. Bu if the data blocks were changed during the period time after TX started and before data block read, we will get unexpected result.

Look back to the 1st case. We started the UPDATE transaction in Session 1 at 10:22:25. However, because of a large subquery, it will read specical data block to be updated tens of seconds later. In Session 2, we updated this data at 10:22:37 and commited it 10:23:02, when before the data block be read in session 1. In session 1, after data changed commited in sesion 2, the transaction read the data block. But because the SCN of tansaction in Session 2 is larger than SCN of transaction in session 1, it read the undo block and rollbacked the change for consistent reason, which means it read the data with SECONDARY='A'. With the filter (SECONDARY='B'), the transaction in session 1 did not hit any data block, and correspondingly, it did not update any data rows.

In the case 2, similar things happened in transaction of session 1 before it consistent get the data block. And after it rollbacked the undo changes in log, it got a data block fulfill with the filter condition (SECONDARY='A') in consistent mode. Then, it read the data block with the block id in current mode. However, becasue the current data block had been updated by tansaction in session 2, it failed to read the block due to the filter condition.

I hope these 2 cases can help readers to understand the difference between DB gets in Current Mode and Consistent Gets.

总结:

两种情况

case1:session1在执行语句后会进行长时间的读,在读到要修改的块之前,session2对块进行了修改,在session1读到需要的块时发现scn比自己的要大,开始从undo中进行一致性读,但是原始数据是A,条件中是B,因此未找到满足条件的数据,导致更新数据为0

case2:session1在执行语句后会进行长时间的读,在读到要修改的块之前,session2对块进行了修改,在session1读到需要的块时发现scn比自己的要大,开始从undo中进行一致性读,此时正常进行一致性读,当要修改数据时,发现块已经被session2修改,因此最终修改的数据也是0

Oracle 一致性读和当前读相关推荐

  1. oracle 一致性读数量,ORACLE 一致性读原理记录

    什么是一致性读? 一致性读指的是在从查询那一刻起,中间的变化不予理会. 举例说明 比如我有两个帐户A,B. A 有1000块,B有1000快.我查询的时候查询速度比较慢.中间A转500到B账户. 已经 ...

  2. Oracle 物理读 逻辑读 一致性读 当前模式读总结浅析

    Oracle 物理读 逻辑读 一致性读 当前模式读总结浅析 在ORACLE数据库中有物理读(Physical Reads).逻辑读(Logical Reads).一致性读(Consistant Get ...

  3. 在Oracle中,什么是物理读和逻辑读?

    在Oracle中,什么是物理读和逻辑读? 当会话所需要的数据在内存的 Buffer Cache 中找不到,此时就要去磁盘上的数据文件中读取,这样就产生了物理读( Physical Reads ),即物 ...

  4. oracle的逻辑读、物理读总结

    (一).物理读:把数据从数据块读取到buffer cache中 1.第一次查询一个表t select * from t ; 2.第二次查询: select * from t: 第一次查询有6次物理读, ...

  5. (未看)ORACLE物理读和逻辑读(SET AUTOTRACE ON 部分参数解释)[逻辑IO只有逻辑读,没有逻辑写]

    逻辑IO只有逻辑读,没有逻辑写 ORACLE物理读和逻辑读(SET AUTOTRACE ON 部分参数解释) set autotrace 产生部分信息解读的官方文档基本的定义为如下: recursiv ...

  6. MySQL怎么运行的系列(十一)快照读、锁定读、半一致性读 和 加锁语句分析

    本系列文章目录 展开/收起 MySQL怎么运行的系列(一)mysql体系结构和存储引擎 MySQL怎么运行的系列(二)Innodb缓冲池 buffer pool 和 改良版LRU算法 Mysql怎么运 ...

  7. oracle 物理读突然增加的原因_请教一个诡异的物理读比逻辑读还多的问题!!!!

    本帖最后由 wxjzqym 于 2012-6-1 10:27 编辑 为了更好的理解物理读和逻辑读的关系,模拟了以下实验:(DB 10.2.0.1.0 32bit) 1.在scott用户下创建测试表和相 ...

  8. Oracle逻辑读,物理读

    逻辑读和物理读 当执行计划创建成功后,就可以执行类似于update这样的语句.第一步是要在缓存高速缓冲区中查找数据快,数据快包含了要更新的行片段信息.通过内存中一个叫做最近最小使用列表的结构去进行查找 ...

  9. oracle怎么判断逻辑读,如何查看Oracle数据库物理读、逻辑读前10的sql?

    概述 今天主要介绍几个sql,可能很多人就收藏一下但很少会去用,所以结合案例来做一下分析,这样就知道在什么场景用了. 下面介绍一下案例. 1.监控分析 从监控发现物理IO读处于比较高的水平,截图如下: ...

最新文章

  1. 二三代基因组混合组装流程的搭建与香菇基因组精细图谱的获得
  2. c++中关于char数组/char*指针/string类型
  3. 10分钟搞懂:亿级用户的分布式数据存储解决方案
  4. 微软算法面试题(2)
  5. 【Python】 linux中python命令的命令行参数
  6. MySQL字段类型与Java数据类型的对应关系
  7. comps电磁场模拟软件_电气工程仿真
  8. cron表达式 每天0点10分和30分_查找特定时间段cron任务方法
  9. 音视频开发(7)---流媒体服务器原理和架构解析
  10. [NOIp2012]开车旅行
  11. spark java.lang.StackOverflowError
  12. 关于计算机网络ppt背景图片,ppt怎么换背景图片
  13. vue实现导出excel,pdf功能
  14. 附件上传后台报The field uploadFile exceeds its maximum permitted size of 1048576 bytes.
  15. 外贸最全出口流程,外贸必看基础知识
  16. 陈莉君教授: 回望踏入Linux内核之旅(下篇)
  17. 20寸JAVA16速自行车_健康成长 快乐骑行 JAVA16/20寸儿童自行车介绍
  18. Huffman Codes
  19. 全网最简单的RFM模型制作方法,3岁小孩都能学会!
  20. 新式 AIMD 拥塞控制

热门文章

  1. 知识产品经理需要掌握什么知识?
  2. 人生必读的100本书隐私政策
  3. 2020年熔化焊接与热切割多少钱及熔化焊接与热切割模拟试题
  4. daterangepicker时间插件控制起始和截至日期的选择范围
  5. IDEA版最新SMM整合,根据手机号实现登录/注册/修改密码
  6. 统信UOS专业版软件包的安装与使用
  7. 【微信小程序开发与设计】垃圾智能分类小程序
  8. Broadcast的onReceive方法中弹出AlertDialog
  9. 利用Fierce2查询子域名
  10. BOGNER博格纳宣布演员王紫璇、超模雎晓雯担任品牌大使