Using Statspack to Record Explain Plan Details
?/rdbms/admin/sprepsql.sql
An SQL report can be executed on one SQL statement, searching for a bottleneck, where the hash value for the SQL code statement is found in the STATSPACK instance report.
From Oracle9i onwards, oracle stores the execution plan of each of the child
cursor loaded in the library cache. The view v$sql_plan can be queried to
retrieve this information. In addition an enhancement was made to the Oracle9i
statspack report to capture the sql plans.
Capturing a snapshot at i_snap_level>=6 will capture the execution plans of
any SQL statements present in the library cache at the time the snapshot is
taken, that have exceeded one of the SQL thresholds.
Example
~~~~~~~
To capture a snapshot at level 6, execute the following:
SQL> execute statspack.snap (i_snap_level=>6, i_modify_parameter=>'true');
In addition to the snapshot level, there are parameters which can be configured:
These parameters are used as thresholds when collecting data on SQL
statements; data will be captured on any SQL statements that breach
the specified thresholds.
For example :
~~~~~~~~~~~~~
i_executions_th : number of times statement was executed (default 100)
i_disk_reads_th : number of disk reads the statement made (default 1000)
Threshold values can be reduced so that this snapshot captures most
of the SQL statements present in the library cache at that point of time.
To verify whether there is any change in the plan at a future point of time,
take another snapshot at level 6. Using the script:
$ORACLE_HOME/rdbms/admin/sprepsql.sql
Explain plans between the two snapshots can be compared.
SQL Text
~~~~~~~~
INSERT INTO ORGANIZE_OPERATION_LOG(LOG_ID,MASTER_ID,GUEST_ID,LOG
_TIME,OPERATION_TYPE_ID) SELECT SEQ_LOG_ID.NEXTVAL, 'EAF', A.STA
FF_ID, SYSDATE, 504 FROM (SELECT STAFF.STAFF_ID, STAFF.STATUS, S
TAFF.STAFF_TYPE, MAX(PASSWORD_HISTORY.MODIFY_TIME) PWD_MODIFY_TI
ME FROM STAFF, PASSWORD_HISTORY WHERE STAFF.STAFF_ID=PASSWORD_HI
STORY.STAFF_ID GROUP BY STAFF.STAFF_ID, STAFF.STATUS, STAFF.STAF
F_TYPE) A WHERE A.STATUS IN (-1, 0) AND A.STAFF_TYPE=0 AND (SYSD
ATE-A.PWD_MODIFY_TIME)>=:B2 AND (SYSDATE-A.PWD_MODIFY_TIME)<:b1>
Known Optimizer Plan(s) for this Hash Value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows all known Optimizer Plans for this database instance, and the Snap Id's
they were first found in the shared pool. A Plan Hash Value will appear
multiple times if the cost has changed
-> ordered by Snap Id
First First Plan
Snap Id Snap Time Hash Value Cost
-------- --------------- ------------ ----------
191 17 Jul 07 10:13 1211322769 0
191 17 Jul 07 10:13 2094815075 18
191 17 Jul 07 10:13 3647221266 11
Plans in shared pool between Begin and End Snap Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows the Execution Plans found in the shared pool between the begin and end
snapshots specified. The values for Rows, Bytes and Cost shown below are those
which existed at the time the first-ever snapshot captured this plan - these
values often change over time, and so may not be indicative of current values
-> Rows indicates Cardinality, PHV is Plan Hash Value
-> ordered by Plan Hash Value
--------------------------------------------------------------------------------
| Operation | PHV/Object Name | Rows | Bytes| Cost |
--------------------------------------------------------------------------------
|INSERT STATEMENT |----- 1211322769 ----| | | |
|SEQUENCE | | | | |
| VIEW | | | | |
| FILTER | | | | |
| SORT GROUP BY | | | | |
| NESTED LOOPS | | | | |
| TABLE ACCESS FULL |PASSWORD_HISTORY | | | |
| TABLE ACCESS BY INDEX ROWID|STAFF | | | |
| INDEX UNIQUE SCAN |PK_STAFF | | | |
|INSERT STATEMENT |----- 2094815075 ----| | | 18 |
|SEQUENCE | | | | |
| VIEW | | 1 | 44 | 18 |
| FILTER | | | | |
| SORT GROUP BY | | 1 | 53 | 18 |
| FILTER | | | | |
| NESTED LOOPS | | 1 | 53 | 16 |
| TABLE ACCESS FULL |STAFF | 1 | 35 | 14 |
| INDEX RANGE SCAN |PK_PASSWORD_HISTORY | 1 | 18 | 2 |
|INSERT STATEMENT |----- 3647221266 ----| | | 11 |
|SEQUENCE | | | | |
| VIEW | | 1 | 44 | 11 |
| FILTER | | | | |
| SORT GROUP BY | | 1 | 31 | 11 |
| FILTER | | | | |
| HASH JOIN | | 491 | 14K| 8 |
| TABLE ACCESS FULL |STAFF | 657 | 8K| 4 |
| TABLE ACCESS FULL |PASSWORD_HISTORY | 981 | 17K| 3 |
--------------------------------------------------------------------------------
End of Report
This example containts 3 plans.
Usage Suggestion
================
Recording a snapshot of SQL execution can be useful in managing any system
change that may modify query plans.
Before any operation which can cause a plan change, (such as after large data
loads, or after gathering new optimizer statistics) capture the snapshot at
level 6 and use this as the base line for future comparisons.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/38542/viewspace-926808/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Use the statspack to generate the accurate explain planAI
- Explain PlanAI
- explain plan VS execution planAI
- USE EXPLAIN PLANAI
- Oracle EXPLAIN PLAN用法OracleAI
- Explain for the Statistics of Execution PlanAI
- explain plan 的用法AI
- oracle explain plan for的用法OracleAI
- ORACLE EXPLAIN PLAN的總結OracleAI
- explain plan 學習記錄AI
- Error: cannot fetch last explain plan from PLAN_TABLEErrorASTAI
- 用EXPLAIN PLAN 分析SQL語句AISQL
- 【Explain Plan】10g中的PLAN_TABLE$臨時表AI
- Oracle執行計劃Explain Plan 如何使用OracleAI
- oracle 使用explain plan分析查詢語句OracleAI
- EXPLAIN PLAN and SQL*PLUS AUTOTRACE may not generate actual plansAISQL
- toad顯示explain plan的問題AI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- autotrace explain plan 相關引數解釋AI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- EXPLAIN PLAN FOR 和 SET AUTOTRACE之間的差別AI
- 使用EXPLAIN PLAN來檢視執行計劃AI
- TOAD中檢視執行計劃(Explain Plan)AI
- (轉)oracle效能工具包Explain plan、Autotrace、TkprofOracleAI
- 配置oracle 解釋執行計劃--explain planOracleAI
- 【Explain Plan】檢視SQL的執行計劃AISQL
- Systemwide Tuning using STATSPACK ReportsIDE
- 【最佳化】explain plan for 方式存取執行計劃AI
- MySQL explain結果Extra中"Using Index"與"Using where; Using index"區別MySqlAIIndex
- [20171201]關於explain plan.txtAI
- set autot traceonly與explain plan for的一點小區別AI
- 11G新特性,explain plan 可以評估出索引大小AI索引
- Script: Script to Simplify the Use of Explain Plan (Doc ID 1019631.6)AI
- autotrace 和explain plan for可能導致執行計劃錯誤AI
- * Recommended Method for Obtaining a Formatted Explain Plan [ID 235530.1]AIORM
- oracle explain plan for獲取執行計劃並不可靠.OracleAI
- 檢視執行計劃方法總結之一:explain plan命令AI
- 【執行計劃】格式化EXPLAIN PLAN的輸出結果AI