透過SPM手動新增執行計劃到baseLine
透過SPM方法手動將新的執行計劃新增到baseLine裡面,這相當就是把
並非系統算出來的“最優”的執行計劃放在最佳化器裡,在往後的查詢中,最佳化器
自動呼叫該執行計劃。以下是演示過程:
---建立測試表:
SQL> create table t3 (id int);
Table created.
---插入測試資料:
SQL> insert into t3 select level from dual connect by level<=100000;
100000 rows created.
---執行查詢語句:
SQL> select count(*) from t3 where id=1;
COUNT(*)
----------
1
Execution Plan
----------------------------------------------------------
Plan hash value: 463314188
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 44 (3)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
|* 2 | TABLE ACCESS FULL| T3 | 2 | 26 | 44 (3)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=1)
Note
-----
- dynamic sampling used for this statement (level=2)
---檢視share pool資訊:
SQL> col sql_text for a50
SQL> select sql_id,sql_text from v$sql where sql_text like 'select count(*) from t3 where id=1';
SQL_ID SQL_TEXT
------------- --------------------------------------------------
82w9knc509xx4 select count(*) from t3 where id=1
---給測試表建立索引:
SQL> create index idx_t3 on t3(id);
Index created.
SQL> select count(*) from t3 where id=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 2808915302
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
|* 2 | INDEX RANGE SCAN| IDX_T3 | 1 | 13 | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---檢視baseline中的資訊:
SQL> select sql_handle,sql_text,plan_name,origin,version,created,last_modified,last_executed,last_verified,enabled,accepted,fixed
from dba_sql_plan_baselines where sql_text like '%select count(*) from t3 where id=1%';
no rows selected
---手工裝載執行計劃再次檢視baseline及演進資訊:
SQL> DECLARE
2 my_plans PLS_INTEGER;
3 BEGIN
4 my_plans := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE( sql_id => '82w9knc509xx4');
5 END;
6 /
PL/SQL procedure successfully completed.
---再次檢視baseline中的資訊:
SQL> select sql_handle,sql_text,plan_name,origin,version,created,last_modified,last_executed,last_verified,enabled,accepted,fixed
from dba_sql_plan_baselines where sql_text like '%select count(*) from t3 where id=1';
SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN
-------------------- --------------- --------------- --------------
VERSION CREATED
---------------------------------------------------------------- ----------
LAST_MODIF LAST_EXECU LAST_VERIF ENA ACC FIX
---------- ---------- ---------- --- --- ---
SQL_f83b4cd9c6676181 select count(*) SQL_PLAN_ghfucv MANUAL-LOAD
from t3 where 736fsc1f140b502
id=1
11.2.0.4.0 17-OCT-16
12.30.54.0
00000 PM
17-OCT-16 YES YES NO
12.30.54.0
00000 PM
#新增成功。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2129901/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux透過計劃任務驅動Windows伺服器執行命令LinuxWindows伺服器
- Oracle如何手動重新整理執行計劃Oracle
- 【SPM】Oracle計劃管理器SPM介紹及用例Oracle
- 執行計劃-1:獲取執行計劃
- 透過空間佔用和執行計劃瞭解SQL Server的行儲存索引SQLServer索引
- 【SQL_PLAN】Oracle 透過檢視sql_plan 格式化執行計劃SQLOracle
- 分析執行計劃優化SQLORACLE的執行計劃(轉)優化SQLOracle
- Oracle 通過註釋改變執行計劃Oracle
- MySQL——通過EXPLAIN分析SQL的執行計劃MySqlAI
- MySQL執行計劃MySql
- SYBASE執行計劃
- MySQL 執行計劃MySql
- 【執行計劃】Oracle獲取執行計劃的幾種方法Oracle
- 9i and 10g 透過SQL_ADDRESS 或sql_id查詢執行計劃SQL
- 007 Rust 非同步程式設計,透過 join 執行 FutureRust非同步程式設計
- MySQL執行計劃解析MySql
- mysql explain 執行計劃MySqlAI
- explain執行計劃分析AI
- mysql執行計劃explainMySqlAI
- oracle 固定執行計劃Oracle
- Oracle sql執行計劃OracleSQL
- 執行計劃執行步驟原則
- Promise拆解計劃:手寫Promise並透過官方全部測試用例Promise
- 【PG執行計劃】Postgresql資料庫執行計劃統計資訊簡述SQL資料庫
- mysql透過計劃任務建立月表MySql
- 透過DNS TXT記錄執行powershellDNS
- mongodb執行計劃解釋MongoDB
- 檢視 OceanBase 執行計劃
- MySQL執行計劃解析(四)MySql
- 讀懂MySQL執行計劃MySql
- Explain執行計劃詳解AI
- PostgreSQL執行計劃變化SQL
- explain 查詢執行計劃AI
- eclipse 手動新增jar包到maven庫EclipseJARMaven
- 手動新增git到 右鍵選單Git
- 透過歷史記錄執行本地模型模型
- [20190111]執行計劃bitmap and.txt
- mysql explain 執行計劃詳解MySqlAI
- 十六、Mysql之Explain執行計劃MySqlAI