[20130109]SPM與sql profile.txt
[20130109]SPM與sql profile.txt
SPM是11G有的新特性,而sql profile在10g早已經存在。如果在11G,兩者都使用的話,執行會選擇那個呢?
自己做一個測試來說明情況:
1.建立測試環境:
2.我在執行計劃中使用full提示,執行計劃一定選擇全表掃描:
我建立sql profile,方法如下:
--這樣執行就是使用索引。先暫時禁用sql profile。
3.建立sql baseline:
--可以發現已經建立了sql baseline。使能sql profile。
4.兩者都存在的情況下,會使用那個呢?
--可以從Note中發現,提示兩者都使用,但是實際上執行計劃使用的是全表掃描。也就是講在兩者都存在的情況下,SPM優先。
5.如果關閉SPM,看看:
--再次證明兩者存在的情況下SPM優先,而不管那個執行效率高。
SPM是11G有的新特性,而sql profile在10g早已經存在。如果在11G,兩者都使用的話,執行會選擇那個呢?
自己做一個測試來說明情況:
1.建立測試環境:
SQL> select * from v$version where rownum<=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
SQL> create table t as select rownum id ,lpad('x',100,'x') name from dual connect by level<=10000;
Table created.
SQL> create unique index i_t_id on t(id);
SQL> exec dbms_stats.gather_table_stats(USER,'T',cascade => true);
SQL> variable a number ;
SQL> exec :a := 100;
SQL> select /*+ full(t) */ * from t where id = :a ;
2.我在執行計劃中使用full提示,執行計劃一定選擇全表掃描:
我建立sql profile,方法如下:
DECLARE
ret_val VARCHAR2(4000);
BEGIN
ret_val := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_id => '89u57qt97ftca',
plan_hash_value => NULL,
scope => 'COMPREHENSIVE',
time_limit => 1800,
task_name => 'test',
description => 'study');
Dbms_Sqltune.EXECUTE_TUNING_TASK('test');
END;
select Dbms_Sqltune.REPORT_TUNING_TASK('test', 'TEXT', 'all') report from dual
--提示執行如下:
execute dbms_sqltune.accept_sql_profile(task_name => 'test', task_owner=> 'SCOTT', replace => TRUE);
--這樣執行就是使用索引。先暫時禁用sql profile。
BEGIN
DBMS_SQLTUNE.ALTER_SQL_PROFILE (
name => 'SYS_SQLPROF_013c1cf4e9920000',
attribute_name => 'STATUS',
value => 'DISABLED');
END;
3.建立sql baseline:
SQL> alter session set optimizer_capture_sql_plan_baselines=true ;
SQL> select /*+ full(t) */ * from t where id = :a ;
SQL> select /*+ full(t) */ * from t where id = :a ;
SQL> alter session set optimizer_capture_sql_plan_baselines=false ;
SQL> select sql_handle, plan_name, sql_text,enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE PLAN_NAME SQL_TEXT ENA ACC FIX ORIGIN SIGNATURE
------------------------------ ------------------------------ -------------------------------------------------------- --- --- --- -------------- -----------------------
SYS_SQL_443d558815eb01e6 SQL_PLAN_48gapj0ayq0g694ecae5c select /*+ full(t) */ * from t where id = :a YES YES NO AUTO-CAPTURE 4917180411130085862
--可以發現已經建立了sql baseline。使能sql profile。
BEGIN
DBMS_SQLTUNE.ALTER_SQL_PROFILE (
name => 'SYS_SQLPROF_013c1cf4e9920000',
attribute_name => 'STATUS',
value => 'ENABLED');
END;
4.兩者都存在的情況下,會使用那個呢?
SQL> select /*+ full(t) */ * from t where id = :a ;
ID NAME
---------- --------------------------------------------------
100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SQL> @dpc ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 89u57qt97ftca, child number 0
-------------------------------------
select /*+ full(t) */ * from t where id = :a
Plan hash value: 1601196873
--------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------
| 0 | SELECT STATEMENT | | | 47 (100)|
|* 1 | TABLE ACCESS FULL| T | 1 | 47 (0)|
--------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
1 - (NUMBER): 100
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=:A)
Note
-----
- SQL profile SYS_SQLPROF_013c1cf4e9920000 used for this statement
- SQL plan baseline SQL_PLAN_48gapj0ayq0g694ecae5c used for this statement
- 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
31 rows selected.
--可以從Note中發現,提示兩者都使用,但是實際上執行計劃使用的是全表掃描。也就是講在兩者都存在的情況下,SPM優先。
5.如果關閉SPM,看看:
SQL> select sql_handle, plan_name, sql_text,enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE PLAN_NAME SQL_TEXT ENA ACC FIX ORIGIN SIGNATURE
------------------------------ ------------------------------ -------------------------------------------------------- --- --- --- -------------- -----------------------
SYS_SQL_443d558815eb01e6 SQL_PLAN_48gapj0ayq0g694ecae5c select /*+ full(t) */ * from t where id = :a YES YES NO AUTO-CAPTURE 4917180411130085862
SYS_SQL_443d558815eb01e6 SQL_PLAN_48gapj0ayq0g6e3e62b6b select /*+ full(t) */ * from t where id = :a YES NO NO AUTO-CAPTURE 4917180411130085862
variable v_basenum number;
exec :v_basenum := dbms_spm.alter_sql_plan_baseline(sql_handle=>'SYS_SQL_443d558815eb01e6',plan_name=>'SQL_PLAN_48gapj0ayq0g694ecae5c',attribute_name=>'ENABLED',attribute_value=>'NO');
SQL> select sql_handle, plan_name, sql_text,enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE PLAN_NAME SQL_TEXT ENA ACC FIX ORIGIN SIGNATURE
------------------------------ ------------------------------ -------------------------------------------------------- --- --- --- -------------- -----------------------
SYS_SQL_443d558815eb01e6 SQL_PLAN_48gapj0ayq0g694ecae5c select /*+ full(t) */ * from t where id = :a NO YES NO AUTO-CAPTURE 4917180411130085862
SYS_SQL_443d558815eb01e6 SQL_PLAN_48gapj0ayq0g6e3e62b6b select /*+ full(t) */ * from t where id = :a YES NO NO AUTO-CAPTURE 4917180411130085862
SQL> select /*+ full(t) */ * from t where id = :a ;
ID NAME
---------- --------------------------------------------------
100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SQL> @dpc ''
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------
SQL_ID 89u57qt97ftca, child number 0
-------------------------------------
select /*+ full(t) */ * from t where id = :a
Plan hash value: 1149237570
--------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | 2 (100)|
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 2 (0)|
|* 2 | INDEX UNIQUE SCAN | I_T_ID | 1 | 1 (0)|
--------------------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
1 - (NUMBER): 100
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=:A)
Note
-----
- SQL profile SYS_SQLPROF_013c1cf4e9920000 used for this statement
- 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
--再次證明兩者存在的情況下SPM優先,而不管那個執行效率高。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-752344/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Plan Management(SPM)SQL
- SQL大致流程、SPM、軟軟、軟、硬解析SQL
- ORACLE 通過SPM為SQL語句加HINTOracleSQL
- [20151201]備份遷移sql profile.txtSQL
- 自適應遊標共享(ACS)與sql計劃管理(SPM)的相互影響SQL
- [20130123]spm與sql profile的主要區別在那裡.txtSQL
- oracle11g中SQL最佳化(SQL TUNING)新特性之SQL Plan Management(SPM)OracleSQL
- [20130109]lftp與oracle的臨時檔案.txtFTPOracle
- 【SPM】Oracle計劃管理器SPM介紹及用例Oracle
- 【最佳化】SPM(上)自動捕獲sql執行計劃並演進SQL
- ORACLE 11G 使用SPM來調整SQL語句的執行計劃OracleSQL
- [20150430]11G SPM與cardinality feedback2
- 【SPM】Oracle如何固定執行計劃Oracle
- SPM適用的場景和示例
- 【最佳化】SPM(下)手工捕獲sql執行計劃並檢視演進情況SQL
- (原)汽車行業ERP要求四:SPM行業
- [20130109]使用bbcp傳輸檔案.txt
- SPM設定保留空間和保留時效
- (17)sql注入與sql modeSQL
- Oracle OCP 1Z0 053 Q201(DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE)OracleSQL
- 前端與SQL前端SQL
- 使用SPM和STA進行固定執行計劃
- 控制執行計劃之-SPM BASELINE(六)
- 控制執行計劃之-SPM BASELINE(五)
- 控制執行計劃之-SPM BASELINE(四)
- 控制執行計劃之-SPM BASELINE(三)
- 控制執行計劃之-SPM BASELINE(二)
- 控制執行計劃之-SPM BASELINE(一)
- 如何在SPM®5封裝上安裝散熱器封裝
- Sql介紹 與 Sql基礎查詢SQL
- 用spm2構建seajs專案的過程JS
- 3 SQL 聚合與排序SQL排序
- 前端與 SQL 全面梳理前端SQL
- 反對SQL與捍衛SQL的論戰SQL
- Oracle 11g系列:SQL Plus與PL/SQLOracleSQL
- sql net message from|to client與sql execution countSQLclient
- 透過SPM手動新增執行計劃到baseLine
- SPM12之fMRI批次預處理——NII檔案處理