Oracle 的 cursor_sharing引數
先來看看官方文件中對這個引數的解釋
CURSOR_SHARING
Property | Description |
---|---|
Parameter type | String |
Syntax | CURSOR_SHARING = { SIMILAR | EXACT | FORCE } |
Default value | EXACT |
Modifiable | ALTER SESSION, ALTER SYSTEM |
Basic | No |
CURSOR_SHARING determines what kind of SQL statements can share the same cursors.
Values:
-
FORCE
Forces statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect the meaning of the statement.
-
SIMILAR
Causes statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect either the meaning of the statement or the degree to which the plan is optimized.
-
EXACT
Only allows statements with identical text to share the same cursor.
================================================================================
引數cursor_sharing的解釋
--------------------------------------
這個引數的設定,oracle是為了滿足一些以前開發的程式,裡面有大量的similar statement,但是重寫又不現實的情況下使用的一個引數。(並且oracle也不建議使用這個引數)
什麼時候需要修改這個引數呢?需要滿足以下的條件。
一個是由於大量的shared pool hit miss影響了使用者的響應時間(就是當前的shared pool無法滿足共享sql語句儲存的需要,Alan:當前libary cache中沒有我們所需要重用的explain和sql),如果沒有這個問題,那麼設定這個引數,可能會造成更糟糕的效能。這個引數只會減少parse的時間。
另外一個就是在現有程式中有大量的similar statement,可以透過設定這個引數來獲得比較好的效能。
cursor_sharing這個引數有三個值可選,exact、similar、force。當值為exact時為預設值,也是oracle的預設處理方式。就是當一個statement parse的時候,首先到shared pool區檢視是否有exact statement存在(就是看是否在shared pool中有和當前要解析的statement完全一樣的語句存在),如果不存在,就執行hard parse
如果該引數設定為similar,那麼如果在shared pool中無法找到exact statement的存在的時候,就會在shared pool進行一次新的查詢,就是查詢和當前要解析的語句是否是similar statement的語句。這裡需要對similar statement進行解釋,similar statement就是除了value of some literal不同的語句,別的地方都相同的語句。比如下面:
select * from a where a=1;
select * from a where a=2;
當cursor_sharing設定為similar時,如果在shared pool中查詢到這樣的語句,就會做下一步的檢查,看shared pool中快取的這個語句的execution plan是否適合當前解析的語句,如果適合,就會使用shared pool的語句,而不去做hard parse。如果cursor_sharing設定為force的時候,當在shared pool中發現了similar statement之後,就不會再去檢查執行計劃了,而直接使用在shared pool的這個語句了。
將cursor_sharing設定為force實際上是危險的。這會可能形成sub optimal的執行計劃。比如對於一個範圍查詢的語句,比如
select * from a where a>10 and a<20這樣型別的語句,快取中的語句的執行計劃可能對於正在解析的語句就是不適合的,不是最優的執行計劃。
這樣看起來是減少了parse惡的時間,但是大大增大了execution的時間。
對於新開發的application,最好是不要設定這個引數,而是針對可以共享的語句使用繫結變數,而對於不適合共享的語句,就不使用繫結變數。將cursor_sharing保持預設值,也就是exact。
調整cursor_sharing的關鍵一定是要看調整cursor_sharing的條件是否存在。
就是是否有比較大的shared pool hit miss,如果這個條件沒有,那就沒有必要調整這個引數。cursor_sharing的目的是減少parse time,但是在整個db time中,可能parse time只佔很小的一部分。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9399028/viewspace-745931/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE中Cursor_sharing引數詳解Oracle
- 初始化引數遊標之cursor_sharing
- Oracle 核心引數Oracle
- ORACLE並行相關的引數Oracle並行
- Oracle:PDB 引數管理Oracle
- Oracle中的sysctl.conf核心引數Oracle
- Oracle初始化引數的來源Oracle
- Oracle GoldenGate常用引數詳解OracleGo
- oracle rac 核心引數詳解Oracle
- Oracle Table建立引數說明Oracle
- Oracle JDBC ResultSet引數測試OracleJDBC
- 使用 XmlCommand 對Oracle傳引數XMLOracle
- Oracle RAC引數檔案管理Oracle
- oracle中的processes,session,transaction引數詳解OracleSession
- oracle O7_DICTIONARY_ACCESSIBILITY 引數Oracle
- [20190917]oracle引數deferred屬性.txtOracle
- Oracle面試寶典-引數篇Oracle面試
- Oracle RAC修改引數檔案位置Oracle
- Oracle ENABLE=broken引數與TCP KeepAliveOracleTCP
- EDBPPAS(Oracle相容版)Oracle與PostgreSQL相容模式的引數配置切換OracleSQL模式
- 【Oracle】簡單引數也有講究,JOB_QUEUE_PROCESS引數調研Oracle
- EDB PPAS(Oracle 相容版) Oracle與PostgreSQL 相容模式的引數配置切換OracleSQL模式
- Oracle安裝相關Linux引數(轉)OracleLinux
- Oracle undo保留時間的幾個相關引數Oracle
- 聊聊Oracle表空間Offline的三種引數(上)Oracle
- 聊聊Oracle表空間Offline的三種引數(中)Oracle
- 聊聊Oracle表空間Offline的三種引數(下)Oracle
- Oracle 叢集心跳及其引數misscount/disktimeout/reboottimeOracleboot
- oracle 升級12c引數樣例Oracle
- oracle非同步IO之filesystemio_options引數Oracle非同步
- Oracle 10g expdp attach引數體驗Oracle 10g
- Oracle RAC一鍵部署002(引數檢查)Oracle
- Oracle direct path read相關隱含引數Oracle
- Oracle RAC 環境 引數檔案的啟動順序Oracle
- Oracle 效能最佳化之核心的shmall 和shmmax 引數OracleHMM
- solaris10中安裝oracle核心引數的調整Oracle
- 【PARANETERS】Oracle異常恢復相關的隱含引數Oracle
- Oracle 12C 中CDB和PDB的引數檔案管理Oracle
- Oracle:SYS_REFCURSOR作為函式中的輸出引數Oracle函式