硬解析和物理讀取與軟解析和邏輯讀取
參考:http://www.cnblogs.com/chinhr/archive/2009/03/14/1412100.html
001 預備知識
·Recursive Calls:有時為了執行使用者發出的一條SQL語句,Oracle必須執行額外的語句。這樣的額外的語句被稱為遞迴呼叫或者遞迴SQL語句。例如,如果你想往表中插入一行,但是該表沒有足夠的空間來容納這行,這個時候Oracle就會使用遞迴呼叫來自動分配空間。
·db block gets:Number of times a CURRENT block was requested. Current mode blocks are retrieved as they exist right now, not in a consistent read fashion.
Normally, blocks retrieved for a query are retrieved as they existed when the query began. Current mode blocks are retrieved as they exist right now, not from a previous point in time. During a SELECT, you might see current mode retrievals due to reading the data dictionary to find the extent information for a table to do a full scan (because you need the "right now" information, not the consistent read). During a modification, you will access the blocks in current mode in order to write to them.
·Consistent Gets:Number of times a consistent read was requested for a block. This is how many blocks you processed in "consistent read" mode. This will include counts of blocks read from the rollback segment in order to roll back a block. This is the mode you read blocks in with a SELECT, for example. Also, when you do a searched UPDATE/DELETE, you read the blocks in consistent read mode and then get the block in current mode to actually do the modification.
·Physical Reads:Total number of data blocks read from disk. This number equals the value of "physical reads direct" plus all reads into buffer cache.
·Sorts (disk):Number of sort operations that required at least one disk write. Sorts that require I/O to disk are quite resource intensive. Try increasing the size of the initialization parameter SORT_AREA_SIZE.
002
本文透過在3種不同場景下多次執行同一語句的區別。第一個例子在語句執行之前清空了共享池和緩衝區快取,這意味著該語句將會被硬解析,包含該查詢所需資料的塊(以及為了完成硬解析所需的所有關於系統物件的查詢)需要從磁碟上物理讀取。第二個例子展示瞭如果僅清空緩衝區快取將會發生什麼。最後一個例子展示的是共享池和緩衝區都不清空的場景。
2-1 在語句執行之前清空共享池和緩衝區快取
SYS@PROD1> alter system flush buffer_cache;
System altered.
SYS@PROD1> alter system flush shared_pool;
System altered.
SYS@PROD1> set autotrace traceonly statistics
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
161 recursive calls
0 db block gets
239 consistent gets
26 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
9 sorts (memory)
0 sorts (disk)
5 rows processed
SYS@PROD1> set autotrace off
2-2 僅清空緩衝區快取
SYS@PROD1> alter system flush buffer_cache;
System altered.
SYS@PROD1> set autotrace traceonly statistics
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
2 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
2-3 共享池和緩衝區都不清空
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
SYS@PROD1> set autotrace off
003 結論
可以從統計資訊中看到,當執行的查詢僅需軟解析並且能夠從緩衝區快取中讀取資料塊時,執行任務所耗用的資源是最少的。
我們的目標應該永遠是開發出能夠更多地重用共享池和緩衝區快取中資訊的程式碼。
001 預備知識
·Recursive Calls:有時為了執行使用者發出的一條SQL語句,Oracle必須執行額外的語句。這樣的額外的語句被稱為遞迴呼叫或者遞迴SQL語句。例如,如果你想往表中插入一行,但是該表沒有足夠的空間來容納這行,這個時候Oracle就會使用遞迴呼叫來自動分配空間。
·db block gets:Number of times a CURRENT block was requested. Current mode blocks are retrieved as they exist right now, not in a consistent read fashion.
Normally, blocks retrieved for a query are retrieved as they existed when the query began. Current mode blocks are retrieved as they exist right now, not from a previous point in time. During a SELECT, you might see current mode retrievals due to reading the data dictionary to find the extent information for a table to do a full scan (because you need the "right now" information, not the consistent read). During a modification, you will access the blocks in current mode in order to write to them.
·Consistent Gets:Number of times a consistent read was requested for a block. This is how many blocks you processed in "consistent read" mode. This will include counts of blocks read from the rollback segment in order to roll back a block. This is the mode you read blocks in with a SELECT, for example. Also, when you do a searched UPDATE/DELETE, you read the blocks in consistent read mode and then get the block in current mode to actually do the modification.
·Physical Reads:Total number of data blocks read from disk. This number equals the value of "physical reads direct" plus all reads into buffer cache.
·Sorts (disk):Number of sort operations that required at least one disk write. Sorts that require I/O to disk are quite resource intensive. Try increasing the size of the initialization parameter SORT_AREA_SIZE.
002
本文透過在3種不同場景下多次執行同一語句的區別。第一個例子在語句執行之前清空了共享池和緩衝區快取,這意味著該語句將會被硬解析,包含該查詢所需資料的塊(以及為了完成硬解析所需的所有關於系統物件的查詢)需要從磁碟上物理讀取。第二個例子展示瞭如果僅清空緩衝區快取將會發生什麼。最後一個例子展示的是共享池和緩衝區都不清空的場景。
2-1 在語句執行之前清空共享池和緩衝區快取
SYS@PROD1> alter system flush buffer_cache;
System altered.
SYS@PROD1> alter system flush shared_pool;
System altered.
SYS@PROD1> set autotrace traceonly statistics
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
161 recursive calls
0 db block gets
239 consistent gets
26 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
9 sorts (memory)
0 sorts (disk)
5 rows processed
SYS@PROD1> set autotrace off
2-2 僅清空緩衝區快取
SYS@PROD1> alter system flush buffer_cache;
System altered.
SYS@PROD1> set autotrace traceonly statistics
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
2 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
2-3 共享池和緩衝區都不清空
SYS@PROD1> select * from hr.employees where department_id=60;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
1647 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
SYS@PROD1> set autotrace off
003 結論
可以從統計資訊中看到,當執行的查詢僅需軟解析並且能夠從緩衝區快取中讀取資料塊時,執行任務所耗用的資源是最少的。
我們的目標應該永遠是開發出能夠更多地重用共享池和緩衝區快取中資訊的程式碼。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29067253/viewspace-2054658/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 硬解析物理讀VS軟解析邏輯讀 測試
- Oracle物理讀和邏輯讀Oracle
- 有關oracle邏輯讀和物理讀Oracle
- buffer cache實驗9-從buffer caceh中讀取資料塊解析-從邏輯讀到物理讀
- 在Oracle中,什麼是物理讀和邏輯讀?Oracle
- 軟解析和硬解析
- ORACLE 硬解析和軟解析 軟軟解析Oracle
- oracle 物理讀 邏輯讀的理解Oracle
- oracle 物理讀,邏輯讀的理解Oracle
- Oracle的硬解析和軟解析Oracle
- ORACLE SQL解析之硬解析和軟解析OracleSQL
- Oracle SQL的硬解析和軟解析OracleSQL
- QDomDocument 讀取和編輯xml檔案XML
- Oracle 硬解析與軟解析Oracle
- SAP UI5 應用讀取 CSRF token 的 HTTP head 請求邏輯解析UIHTTP
- 資料讀取之邏輯讀簡單解析--關於BUFFER CACHE
- 解析Pyspark如何讀取parquet資料Spark
- 讀取xml檔案 解析雙層xmlXML
- Oracle的軟解析(soft prase)和硬解析(hard prase)Oracle
- Commit和dbwr沒有任何關係、物理讀產生邏輯讀、快照過舊的理解MIT
- csv和excel讀取和下載Excel
- Java中的獲取檔案的物理絕對路徑,和讀取檔案Java
- 在oracle 10.2.0.5分析硬解析及軟解析及軟軟解析獲取shared pool latch機制系列五Oracle
- 邏輯架構和物理架構架構
- ORACLE 物理讀 邏輯讀 一致性讀 當前模式讀總結淺析Oracle模式
- 如何解析 Ethereum 資料:讀取 LevelDB 資料
- BufferedOutputStream的快取功能解析(原始碼閱讀)快取原始碼
- 讀取和儲存Excel表Excel
- javascript如何建立和讀取cookieJavaScriptCookie
- 徹底弄懂oracle硬解析、軟解析、軟軟解析Oracle
- 物理standby和邏輯standby的區別
- python讀取檔案——python讀取和儲存mat檔案Python
- 大量邏輯讀的瓶頸分析和優化優化
- os.Open 讀取檔案和 vim 編輯的問題
- Swoft 配置的設定和讀取
- MapReduce和Spark讀取HBase快照表Spark
- python xml讀取和寫入PythonXML
- redis和ssdb讀取效能對比Redis