【PLAN STABILITY】 STORED-OUTLINE
stored outline用來儲存標準的sql執行計劃,無論環境或統計資訊的變化,都將不影響sql的效能。 11g以後stored outline被SQL plan management 代理,oracle建議11g以後將stored outline複製到SQL Plan Baselines
1. 建立outline
需要的許可權
CREATE ANY OUTLINE
EXECUTE_CATALOG_ROLE
建立outline的兩種方式
CREATE OUTLINE emp_dept FOR CATEGORY scott_outlines
ON SELECT e.empno, e.ename, d.dname FROM emp e;
--v$sql
BEGIN
DBMS_OUTLN.create_outline(
hash_value => SQL hash_value ,
child_number => 0,
category => 'SCOTT_OUTLINES');
END;
/
2. 查詢outline
Outline儲存於outln.OL$;outln.OL$HINTS; outln.OL$NODES;
也可以使用 dba_outlines檢視查詢
3. 使用outline
ALTER SESSION SET query_rewrite_enabled=TRUE;
ALTER SESSION SET use_stored_outlines=SCOTT_OUTLINES;
use_stored_outlines設定為true 使用DEFAULT目錄
查詢outline 是否被使用
SELECT name, category, used FROM user_outlines;
4. 刪除outline
BEGIN
DBMS_OUTLN.drop_by_cat (cat => 'SCOTT_OUTLINES');
END;
/
5. 自動建立outline
啟動該選型oracle 將自動對執行的sql建立outline
ALTER SYSTEM SET create_stored_outlines=TRUE| category_name ;
ALTER SESSION SET create_stored_outlines=TRUE| category_name ;
6. 調整outline的執行計劃
How to Edit a Stored Outline to Use the Plan from Another Stored Outline (Doc ID 730062.1)
7. Outline 注意事項
Outline是SQL文字全匹配, 不支援FORCE_MATCHING,對變數繫結的sql 必須要保證變數值一致
8. 示例
SQL> conn / as sysdba
Connected.
SQL> grant connect,resource to test;
Grant succeeded.
SQL> grant create any outline,alter any outline to test;
Grant succeeded.
SQL> alter user outln identified by outln account unlock;
User altered.
SQL> conn test/oracle
Connected.
SQL> create table t as select * from all_objects;
Table created.
SQL> set autotrace traceonly explain;
SQL> select * from t where OBJECT_ID=888;
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 27 | 3456 | 439 (2)| 00:00:06 |
|* 1 | TABLE ACCESS FULL| T | 27 | 3456 | 439 (2)| 00:00:06 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=888)
Note
-----
- dynamic sampling used for this statement
SQL> set autotrace off
SQL> create outline t_outln1 for category CATEGORY_T on select * from t where OBJECT_ID=888;
Outline created.
SQL> create index i_t on t(object_id);
Index created.
SQL> set autotrace traceonly explain;
SQL> select * from t where OBJECT_ID=258;
Execution Plan
----------------------------------------------------------
Plan hash value: 2928007915
--------------------------------------------------------------------------------
----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
----
| 0 | SELECT STATEMENT | | 1 | 128 | 2 (0)| 00:00:
01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 128 | 2 (0)| 00:00:
01 |
|* 2 | INDEX RANGE SCAN | I_T | 1 | | 1 (0)| 00:00:
01 |
--------------------------------------------------------------------------------
----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=258)
Note
-----
- dynamic sampling used for this statement
SQL> select * from t where OBJECT_ID=888;
Execution Plan
----------------------------------------------------------
Plan hash value: 2928007915
--------------------------------------------------------------------------------
----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
----
| 0 | SELECT STATEMENT | | 1 | 128 | 2 (0)| 00:00:
01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 128 | 2 (0)| 00:00:
01 |
|* 2 | INDEX RANGE SCAN | I_T | 1 | | 1 (0)| 00:00:
01 |
--------------------------------------------------------------------------------
----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=888)
Note
-----
- dynamic sampling used for this statement
SQL> alter session set use_stored_outlines=CATEGORY_T;
Session altered.
SQL> select * from t where OBJECT_ID=888;
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2027 | 253K| 439 (2)| 00:00:06 |
|* 1 | TABLE ACCESS FULL| T | 2027 | 253K| 439 (2)| 00:00:06 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=888)
Note
-----
- outline "T_OUTLN1" used for this statement
SQL> select * from t where OBJECT_ID=258;
Execution Plan
----------------------------------------------------------
Plan hash value: 2928007915
--------------------------------------------------------------------------------
----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
----
| 0 | SELECT STATEMENT | | 1 | 128 | 2 (0)| 00:00:
01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 128 | 2 (0)| 00:00:
01 |
|* 2 | INDEX RANGE SCAN | I_T | 1 | | 1 (0)| 00:00:
01 |
--------------------------------------------------------------------------------
----
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=258)
Note
-----
- dynamic sampling used for this statement
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-1221950/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Plan Stability in Oracle 8i/9iOracle
- Stability Study with SAP Quality Management
- explain plan VS execution planAI
- 突發!Stability AI的CEO,跑路了AI
- Explain PlanAI
- "The Alberta Plan for AI Research" - "Research Plan" from Richard SuttonAI
- Oracle -- 深入體會PLAN_TABLE、PLAN_TABLE$Oracle
- Oracle --- PLAN_TABLE$和PLAN_TABLE區別Oracle
- oracle execution planOracle
- SQL Plan ManagementSQL
- USE EXPLAIN PLANAI
- Error: cannot fetch last explain plan from PLAN_TABLEErrorASTAI
- 奈奎斯特穩定判據(Nyquist stability criterion)UI
- ME5701 Linear stability analysis of Mathieu equation
- Oracle EXPLAIN PLAN用法OracleAI
- SQL Plan Management(SPM)SQL
- Oracle SYSTEM_PLANOracle
- Oracle simple resource planOracle
- team building planUI
- Explain for the Statistics of Execution PlanAI
- explain plan 的用法AI
- Oracle Performance Tune PlanOracleORM
- 【Explain Plan】10g中的PLAN_TABLE$臨時表AI
- oracle explain plan for的用法OracleAI
- Understanding Parallel Execution PlanParallel
- get_plan_by_sqlidSQL
- SQL Plan Management介紹SQL
- sql_plan_baselineSQL
- SQL PLAN Management的測試SQL
- plan9 assembly 入門
- WRH$_SQL_PLAN 被鎖SQL
- 11g-sql plan managementSQL
- ORACLE EXPLAIN PLAN的總結OracleAI
- Use the statspack to generate the accurate explain planAI
- 【筆記】使用 plan_table筆記
- sql plan baselines(一)SQL
- sql plan baseline(二)SQL
- explain plan 學習記錄AI