[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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20180521]dataguard 與 spm.txt
- 【SPM】Oracle計劃管理器SPM介紹及用例Oracle
- 【轉載】淘寶SPM流量跟蹤體系
- 如何在SPM®5封裝上安裝散熱器封裝
- Sql介紹 與 Sql基礎查詢SQL
- Disable the Evolve Job SYS_AUTO_SPM_EVOLVE_TASK in Oracle 12cOracle
- 府安就開完收種自戰著角到spm
- 3 SQL 聚合與排序SQL排序
- 反對SQL與捍衛SQL的論戰SQL
- SPM12之fMRI批次預處理——NII檔案處理
- MySQL中普通sql與預編譯sql 區別MySql編譯
- sql與nosql的權衡SQL
- SQL 解析與執行流程SQL
- 與SQL視窗函式相同SQL函式
- 位運算與SQL實現SQL
- PostgreSQL與Oracle的sql差異SQLOracle
- mybatis動態sql與分頁MyBatisSQL
- XSS與SQL隱碼攻擊SQL
- fMRI預處理之DICOM格式轉NII格式——SPM12批次碼
- MySQL 資料庫與 SQL 優化MySql資料庫優化
- python SQL基礎與python互動PythonSQL
- Spark SQL / Catalyst 內部原理 與 RBOSparkSQL
- Flink Sql Gateway的原理與實踐SQLGateway
- Spark SQL知識點與實戰SparkSQL
- 【SQL】Oracle sql語句 minus函式執行效率與join對比SQLOracle函式
- Oracle 11 sql tuning advisor sql access advisor關閉以及job檢視與停止OracleSQL
- [20180918]檔案格式與sql_id.txtSQL
- [20240320]空格與sqlpus的sql語句.txtSQL
- Spark SQL中的RDD與DataFrame轉換SparkSQL
- MySQL的sql_mode解析與設定MySql
- sql.bsq與資料庫的建立SQL資料庫
- 【Oracle SQL】months_between與trunc函式OracleSQL函式
- [20220324]toad與sql profile使用問題.txtSQL
- SQL Server與雲端計算(下)WCSQLServer
- SQL Server與雲端計算(上)UHSQLServer
- Spark SQL知識點大全與實戰SparkSQL
- SQL JOIN 中 on 與 where 有何區別SQL
- Oracle 高效能SQL引擎剖析--SQL優化與調優機制詳解OracleSQL優化
- spark sql與mysql 資料載入與匯出資料到mysqlSparkMySql