[20120220]Adaptive Cursor Sharing 與hints.txt
11G的新特性裡面Adaptive Cursor Sharing採用新特性來解決PEEKED BIND的問題,但是必須要經過一次執行後,來改變執行計劃。能否繞過這個步驟,選擇合理的執行計劃呢?從11G開始也提供一個提示BIND_AWARE來繞過這個特性,直接選擇合理的執行計劃。
例子如下:
1.環境說明:
SQL> select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--建立測試例子:
create table t as select rownum id ,'test' name from dual connect by level<=1000;
insert into t select 1001,'aaaa' from dual connect by level<=1000;
commit ;
create index i_t_id on t(id);
exec dbms_stats.gather_table_stats(OWNNAME =>user,TABNAME =>'T',Method_Opt=>'FOR COLUMNS id SIZE 254');
我建立的表id分佈很不均勻。
cat dpc.sql
select * from table(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS LAST PEEKED_BINDS cost'));
2.開始測試:
SQL> variable a number;
SQL> exec :a := 42;
SQL> select /*+ BIND_AWARE */ * from t where id = :a ;
3.看看v$sql檢視:
--看看是什麼原因產生子游標:
例子如下:
1.環境說明:
SQL> select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--建立測試例子:
create table t as select rownum id ,'test' name from dual connect by level<=1000;
insert into t select 1001,'aaaa' from dual connect by level<=1000;
commit ;
create index i_t_id on t(id);
exec dbms_stats.gather_table_stats(OWNNAME =>user,TABNAME =>'T',Method_Opt=>'FOR COLUMNS id SIZE 254');
SQL> column data_type format a20
SQL> SELECT table_name, column_name, data_type, histogram FROM dba_tab_cols WHERE table_name ='T' ;
TABLE_NAME COLUMN_NAME DATA_TYPE HISTOGRAM
------------------------------ ------------------------------ -------------------- ---------------
T NAME CHAR NONE
T ID NUMBER FREQUENCY
我建立的表id分佈很不均勻。
cat dpc.sql
select * from table(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS LAST PEEKED_BINDS cost'));
2.開始測試:
SQL> variable a number;
SQL> exec :a := 42;
SQL> select /*+ BIND_AWARE */ * from t where id = :a ;
SQL> @dpc
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID cx60c99054skh, child number 0
-------------------------------------
select /*+ BIND_AWARE */ * from t where id = :a
Plan hash value: 4153437776
--------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | 2 (100)|
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 2 (0)|
|* 2 | INDEX RANGE SCAN | I_T_ID | 1 | 1 (0)|
--------------------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
1 - (NUMBER): 42
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=:A)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
30 rows selected.
SQL> exec :a := 1001;
SQL> select /*+ BIND_AWARE */ * from t where id = :a ;
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID cx60c99054skh, child number 1
-------------------------------------
select /*+ BIND_AWARE */ * from t where id = :a
Plan hash value: 1601196873
--------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------
| 0 | SELECT STATEMENT | | | 4 (100)|
|* 1 | TABLE ACCESS FULL| T | 1012 | 4 (0)|
--------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
1 - (NUMBER): 1001
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=:A)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
--可以發現執行計劃在:a :=1001的情況下選擇了全表掃描。
29 rows selected.
3.看看v$sql檢視:
SQL> select sql_id,child_number,plan_hash_value,executions, is_bind_aware, is_shareable from v$sql
where sql_text like 'select /*+ BIND_AWARE */ %' and sql_id='cx60c99054skh';
SQL_ID CHILD_NUMBER PLAN_HASH_VALUE EXECUTIONS I I
------------- ------------ --------------- ---------- - -
cx60c99054skh 0 4153437776 1 Y Y
cx60c99054skh 1 1601196873 1 Y Y
--看看是什麼原因產生子游標:
SQL> @ share.sql cx60c99054skh
old 15: and q.sql_id like ''&1''',
new 15: and q.sql_id like ''cx60c99054skh''',
SQL_TEXT = select /*+ BIND_AWARE */ * from t where id = :a
SQL_ID = cx60c99054skh
ADDRESS = 000000008D298DC0
CHILD_ADDRESS = 000000008D29A050
CHILD_NUMBER = 0
--------------------------------------------------
SQL_TEXT = select /*+ BIND_AWARE */ * from t where id = :a
SQL_ID = cx60c99054skh
ADDRESS = 000000008D298DC0
CHILD_ADDRESS = 000000008F702708
CHILD_NUMBER = 1
BIND_EQUIV_FAILURE = Y
--------------------------------------------------
PL/SQL procedure successfully completed.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-716844/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Adaptive Cursor SharingAPT
- Adaptive Cursor Sharing(第二篇)APT
- Adaptive Cursor Sharing(第三篇)APT
- Adaptive Cursor Sharing(第四篇)APT
- Adaptive Cursor Sharing(第五篇)APT
- Adaptive Cursor Sharing (第一篇)APT
- Adaptive Cursor Sharing: Worked Example (Doc ID 836256.1)APT
- 11G Adaptive Cursor Sharing(ACS)的研究APT
- 優化器革命之- adaptive cursor sharing (三)優化APT
- 優化器革命之- adaptive cursor sharing (二)優化APT
- 11GR1 新特性 adaptive cursor sharingAPT
- 最佳化器革命之- adaptive cursor sharing (三)APT
- 最佳化器革命之- adaptive cursor sharing (四)APT
- 11G Adaptive Cursor Sharing(ACS)的研究 (轉)APT
- 驗證11g的adaptive cursor sharing功能APT
- Oracle自適應共享遊標——Adaptive Cursor Sharing(上)OracleAPT
- Oracle自適應共享遊標——Adaptive Cursor Sharing(下)OracleAPT
- [20120327]Adaptive Cursor Sharing 的問題APT
- 11gR2 新特性之(一)Adaptive Cursor Sharing(ACS)APT
- 揭秘自適應遊標共享技術(Adaptive Cursor Sharing)APT
- Oracle 11g SQL效能的新特性(一)- Adaptive Cursor SharingOracleSQLAPT
- 揭祕自適應遊標共享技術(Adaptive Cursor Sharing)APT
- [20221227]Adaptive Cursor Sharing & 直方圖.txtAPT直方圖
- 繫結變數之自適應遊標共享(Adaptive Cursor Sharing)變數APT
- 11G Adaptive Cursor Sharing(ACS)自適應遊標測試APT
- 繫結變數的正確使用,bind peeking,Adaptive Cursor Sharing變數APT
- cursor_sharing=similar 與 直方圖MILA直方圖
- 【DBA】Oracle 11g 針對SQL效能的新特性(一)- Adaptive Cursor SharingOracleSQLAPT
- V$SQL_遊標、adaptive cursor sharing、bind peeking、直方圖的概念SQLAPT直方圖
- oracle11g中SQL最佳化新特性之Adaptive Cursor Sharing (ACS)OracleSQLAPT
- CURSOR_SHARING=SIMILARMILA
- Postgresql的CURSOR SHARINGSQL
- oracle cursor_sharing [轉]Oracle
- Cursor_sharing=SIMILAR取值與直方圖(上)MILA直方圖
- Cursor_sharing=SIMILAR取值與直方圖(下)MILA直方圖
- cursor_sharing與v$sqlarea_v$sql_v$sql_shared_cursorSQL
- 關於 cursor_sharing = similarMILA
- oracle引數-cursor_sharingOracle