db block gets (current gets) VS. consistent gets

本文深入解析了Oracle数据库中的逻辑读取(包括当前读与一致读)和物理读取的区别,通过实例展示了如何在不同操作场景下选择合适的读取模式,以实现高效的数据管理和操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当前读(db block gets / current gets)与一致读(consistent gets)统称为逻辑读,逻辑读可能需要物理读把块读到cache中。

当前读指读现在已提交了的数据,一般在全表扫描读数据字典、更新、删除时发生。

一致读指读发出SELECT的那个时间点SCN的数据,一般在查询(增删改都可能有隐式查询)时发生。


db block gets are blocks read in 'current' mode.  meaning, get me the block as it exists right now, 
no read consistency.  do NOT undo changes.  Again, it is a mode, not an indication of how many 
blocks didn't need changes -- rather how many blocks we asked for in that MODE.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:865586003021


In general, a statement will either get a block from the cache in current mode or consistent read mode. 
Those are logical IO's. The logical IO might need to do a physical IO in order to get the block into the cache - 
but the statement is doing either a consistent read or current mode read. 
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:878847787577


You Asked

hi tom

i your discussion regarding consistant gets and db dblock gets
you mention about block read in CURRENT MODE AND consistent mode

Could you please explain exact meaning of this words by giving 
some examples?

Thanks 


and we said...

Ok, when you turn on autotrace in sqlplus you can see these stats.  

Lets run a query:

ops$tkyte@ORA817.US.ORACLE.COM> set autotrace traceonly statistics
ops$tkyte@ORA817.US.ORACLE.COM> 
ops$tkyte@ORA817.US.ORACLE.COM> select * from emp;

14 rows selected.


Statistics
----------------------------------------------------------
          0  recursive calls
          4  db block gets
          2  consistent gets
          0  physical reads
          0  redo size
       1979  bytes sent via SQL*Net to client
        430  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         14  rows processed

Here we had 4 db block gets.  Those were blocks read in CURRENT MODE.  The blocks that 
were read are actually the blocks that tell us how to FULL SCAN the dept table (data 
dictionary type of information).  We need to get that in CURRENT MODE (as of RIGHT NOW) 
to get an accurate picture of what the table looks like.  

We also had 2 consistent gets -- these are blocks we read in "consistent read" mode -- 
also known as query mode.  This means we were reading them as of the POINT IN TIME the 
query began.  See

http://download-east.oracle.com/docs/cd/A81042_01/DOC/server.816/a76965/c23cnsis.htm#17882

for a great discussion of this.


Now, if we do a delete:

ops$tkyte@ORA817.US.ORACLE.COM> delete from emp;

14 rows deleted.


Statistics
----------------------------------------------------------
          0  recursive calls
         20  db block gets
          1  consistent gets
          0  physical reads
       4220  redo size
       1009  bytes sent via SQL*Net to client
        796  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         14  rows processed

we do lots more db block gets -- why?  because in order to delete the data we need to get 
the block in CURRENT MODE, as it exists right then.

why did we do a consistent get?  because the "read" part of the delete uses the 
consistent read mechanism -- we only delete data that existed in the table as of the 
point in time the delete began.  Consider if DEPT was a 1,000,000 row table instead.  
It'll take a while to delete all of those rows.  As you are deleting however, other 
sessions are inserting and committing data.  This consistent read mechanism makes it so 
that we only delete the rows that existed WHEN WE BEGAN the delete.  We will not delete 
this new data being inserted.
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:878847787577


How Oracle Manages Data Concurrency and Consistency
http://docs.oracle.com/cd/B10501_01/server.920/a96524/c21cnsis.htm#2570

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值