硬解析和物理讀取與軟解析和邏輯讀取
參考: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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在Oracle中,什麼是物理讀和邏輯讀?Oracle
- ORACLE SQL解析之硬解析和軟解析OracleSQL
- SAP UI5 應用讀取 CSRF token 的 HTTP head 請求邏輯解析UIHTTP
- QDomDocument 讀取和編輯xml檔案XML
- 解析Pyspark如何讀取parquet資料Spark
- Oracle的軟解析(soft prase)和硬解析(hard prase)Oracle
- Java中的獲取檔案的物理絕對路徑,和讀取檔案Java
- csv和excel讀取和下載Excel
- 2020-12-13:一文讀懂“&引用”、“&取地址”和“*解析地址”的使用
- 如何解析 Ethereum 資料:讀取 LevelDB 資料
- 讀取和儲存Excel表Excel
- TiKV 原始碼解析系列文章(十三)MVCC 資料讀取原始碼MVC
- os.Open 讀取檔案和 vim 編輯的問題
- MapReduce和Spark讀取HBase快照表Spark
- Python中CSV讀取和轉換Python
- Swoft 配置的設定和讀取
- 邏輯和物理計劃如何工作時讀蜂巢分割槽表在獸人pyspark dataframe嗎Spark
- SpringSession系列-sessionId解析和Cookie讀寫策略SpringGseSessionCookie
- HashMap原始碼解析和設計解讀HashMap原始碼
- Java 檔案處理完全指南:建立、讀取、寫入和刪除檔案詳細解析Java
- opencv讀取影片採集卡幀-調整解析度OpenCV
- Python 高階程式設計:深入解析 CSV 檔案讀取Python程式設計
- python檔案建立、讀取和寫入Python
- 如何讀取和寫入JSON檔案JSON
- 使用Python和OpenMV讀取條形碼Python
- csv檔案的寫入和讀取
- Laravel 原始碼閱讀指南 -- 載入和讀取 ENV 配置Laravel原始碼
- 解析jwt實現邏輯JWT
- JavaScript 建立與讀取cookieJavaScriptCookie
- 一文詳解 JuiceFS 讀效能:預讀、預取、快取、FUSE 和物件儲存UI快取物件
- 什麼是物理畫素和邏輯畫素?
- 達夢DM備份恢復(物理和邏輯)
- Mendmix程式碼解析:百搭的配置檔案讀取工具ResourceUtils
- PostgreSQL 原始碼解讀(120)- MVCC#5(獲取事務號-主邏輯)SQL原始碼MVCC#
- SAP Spartacus home 頁面讀取 product 資料的請求的 population 邏輯
- rpm包的校驗和檔案讀取
- Java 讀取PDF中的文字和圖片Java
- (slam工具)1檔案讀取和儲存SLAM
- 【springboot讀取配置檔案】@ConfigurationProperties、@PropertySource和@ValueSpring Boot