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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL explain結果Extra中"Using Index"與"Using where; Using index"區別MySqlAIIndex
- Oracle執行計劃Explain Plan 如何使用OracleAI
- Writing on important detailsImportAI
- statspack、awr、addm,ash影片分享
- SAP Purchasing Group in DetailsAI
- 7.89 FEATURE_DETAILSAI
- 7.46 CLUSTER_DETAILSAI
- 大量STATSPACK資料統計分析
- "The Alberta Plan for AI Research" - "Research Plan" from Richard SuttonAI
- MySQL explainMySqlAI
- [Mysql]ExplainMySqlAI
- PostgreSQL:EXPLAINSQLAI
- react-recordReact
- Active Record Associations
- screen-record
- angular4 反向代理detailsAngularAI
- Virtualbox host plan
- 4.2.1.1 Plan the PDBs
- AAPT2 error: check logs for detailsAPTErrorAI
- ES6+ ---- record
- Daily record-SeptemberAI
- Learn and Record12
- Camera List Record - 120
- explain記錄AI
- MySQL 索引 +explainMySql索引AI
- MySQL 索引優化 Using where, Using filesortMySql索引優化
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- sql_plan_baselineSQL
- Travel Notes-Record mood
- Homework record-Simple sorting
- 自動刪除過期的statspack統計資料
- Using hints for PostgresqlSQL
- String interpolation using $
- using的用法
- Using mysqldump for backupsMySql
- MySQL 之 USINGMySql
- 1030 Travel Plan (30分)
- 【Lintcode】1891. Travel Plan
- BULK In-BIND與RECORD(轉)