db block get和consistent read get
Buffer Modes
When a client requests data, Oracle Database retrieves buffers from the database buffer cache in either of the following modes:
-
Current mode
A current mode get, also called a db block get, is a retrieval of a block as it currently appears in the buffer cache. For example, if an uncommitted transaction has updated two rows in a block, then a current mode get retrieves the block with these uncommitted rows. The database uses db block gets most frequently during modification statements, which must update only the current version of the block.
-
Consistent mode
A consistent read get is a retrieval of a read-consistent version of a block. This retrieval may use . For example, if an uncommitted transaction has updated two rows in a block, and if a query in a separate session requests the block, then the database uses undo data to create a read-consistent version of this block (called a consistent read clone) that does not include the uncommitted updates. Typically, a query retrieves blocks in consistent mode.
這裡我們主要討論db block get發生的情況:
1.建立模擬資料:
SQL> create user test identified by test;
使用者已建立。
SQL> grant connect,resource to test;
授權成功。
SQL>
SQL>
SQL> connect test/test
已連線。
SQL> create table test(id number);
表已建立。
SQL> insert into test values (1);
已建立 1 行。
SQL> insert into test values (2);
已建立 1 行。
SQL> commit;
提交完成。
SQL>
SQL>
SQL> select DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid),id from test;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) ID
------------------------------------ ----------
174 1
174 2
建立了一張test表,插入了兩條記錄,兩條記錄都儲存在相同的塊。
2.用sys使用者執行如下兩個指令碼,使得test使用者也能跟蹤統計資訊:
SQL> @?/rdbms/admin/utlxplan.sql
表已建立。
SQL> @?/sqlplus/admin/plustrce.sql
SQL>
SQL> drop role plustrace;
drop role plustrace
*
第 1 行出現錯誤:
ORA-01919: 角色 'PLUSTRACE' 不存在
SQL> create role plustrace;
角色已建立。
SQL>
SQL> grant select on v_$sesstat to plustrace;
授權成功。
SQL> grant select on v_$statname to plustrace;
授權成功。
SQL> grant select on v_$mystat to plustrace;
授權成功。
SQL> grant plustrace to dba with admin option;
授權成功。
SQL>
SQL> set echo off
SQL> grant plustrace to test;
授權成功。
3.模擬db block gets發生情況,db block gets多發生在執行DML語句的時候。
場景1:事務A讀取了一個塊到記憶體中,這時事務B也需要讀取這個塊來進行修改,事務B不需要從磁碟上讀取,直接從事務A之前讀取到記憶體中的塊來讀取,如果事務B操作的資料對應的塊和事務A選擇的資料是在同一個塊上就會發生db block gets。
會話1:
SQL> set autotrace trace statistics;
SQL> select * from test where id=1;
統計資訊
----------------------------------------------------------
268 recursive calls
0 db block gets
46 consistent gets
17 physical reads
0 redo size
417 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
1 rows processed
會話2:
SQL> set autotrace trace statistics;
SQL> update test set id=6 where id=2;
已更新 1 行。
統計資訊
----------------------------------------------------------
6 recursive calls
3 db block gets
20 consistent gets
2 physical reads
0 redo size
671 bytes sent via SQL*Net to client
600 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
場景2:如果事務A修改某條資料,從磁碟中讀到了記憶體,並未提交,這時事務B也修改了表的一條資料,資料所在的塊和事務A修改的資料在相同的塊上。事務B不會從磁碟讀取這個塊,而是直接中事務A讀取到記憶體中的塊讀取,這時也會發生db block gets,db block gets的發生產生了髒讀,也就說事務A沒有提交的資料也讀取到事務B的塊中來了,但是由於事務B與事務A修改的不是同一條資料,所以髒讀並不會造成資料的不一致。db block gets這也是提高SQL執行效率的處理方式。
先用sys使用者清空shared_pool和buffer_cache:
SQL> alter system flush buffer_cache;
系統已更改。
SQL> alter system flush shared_pool;
系統已更改。
會話1:
SQL> set autotrace trace statistics;
SQL> update test set id=5 where id=1;
已更新 1 行。
統計資訊
----------------------------------------------------------
239 recursive calls
3 db block gets
48 consistent gets
11 physical reads
0 redo size
674 bytes sent via SQL*Net to client
600 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
1 rows processed
會話2:
SQL> set autotrace trace statistics;
SQL> update test set id=6 where id=2;
已更新 1 行。
統計資訊
----------------------------------------------------------
4 recursive calls
3 db block gets
17 consistent gets
0 physical reads
476 redo size
670 bytes sent via SQL*Net to client
599 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23135684/viewspace-697963/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- db block gets 與 consistent read getsBloC
- Arraysize 對consistent get的影響
- Consistent Gets(就是logical read)+ DB Block Gets = 所謂的Logical ReadsBloC
- DB Block Gets、Consistent Gets、Physical ReadsBloC
- 對'Consistent Gets',''Physical Reads'和'DB Block Gets'的理解BloC
- oracle buffer gets=db block gets+consistent getsOracleBloC
- Consistent Gets,Physical Reads和DB Block Gets的解釋(轉)BloC
- recursive calls, db block gets,consistent gets,physical ReadsBloC
- recursive calls ,db block gets , consistent gets的含義BloC
- error:unable to get logical block size for spfileErrorBloC
- 對'Consistent Gets',''Physical Reads'和'DB Block Gets'的理解和解釋BloC
- consistent gets、db block gets的簡單精闢的理解BloC
- 關於統計中Consistent Gets,Physical Reads和DB Block Gets的意義BloC
- (轉)關於 db block gets,consistent gets,physical reads的概念BloC
- python:get和setPython
- get和post區別
- lombok get/set 與 JavaBean get/setLombokJavaBean
- 關於執行計劃裡recursive calls,db block gets和consistent gets引數的解釋BloC
- GET和POST的區別?
- GET和POST的區別
- GET 和 POST 的區別
- POST 和 GET 的區別
- 初學 PHP __set ( ) 和 __ get ( )PHP
- jQuery – AJAX get() 和 post() 方法jQuery
- 等待事件db file sequential read、db file scattered read和direct read的區別事件
- get的被動用法(get-passive)
- Get/Post
- URLSearchParams get()
- jQuery get()jQuery
- arrive get
- MPI_Get_processor_name,MPI_Get_version
- Python探析get和post方法Python
- pt-get和dpkg區別?
- 面試之 get 和 post 區別面試
- javascript get和set訪問器JavaScript
- python set和get實現Python
- Get和Post請求詳解
- Get和Post、冪等、淨荷