(轉)oracle效能工具包Explain plan、Autotrace、Tkprof
Oracle:效能工具Explain plan、Autotrace、Tkprof(2008-06-25 16:52:26)
相關檔案
@$ORACLE_HOME/rdbms/admin/utlxplan.sql
@$ORACLE_HOME/rdbms/admin/utlxpls.sql
@$ORACLE_HOME/rdbms/admin/utlxplp.sql
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
1、sqlplus " / as sysdba"登入
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
2、@$ORACLE_HOME/rdbms/admin/utlxplan.sql
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
3、create public synonym plan_table for
plan_table;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
4、grant select ,insert,update ,delete on plan_table to
public
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
注:這裡沒有考慮安全性,plan_table對所有人都開發了增刪改查許可權,如果需要有安全性,可以針對某一個USER建立一個plan_table;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
使用:
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
@$ORACLE_HOME/rdbms/admin/utlxpls.sql
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
注:還有一個utlxplp.sql用於顯示並行查詢計劃的內容;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
分析報告說明:
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
以oracle的scott使用者登入(這個使用者是被鎖定的,使用前使用alter
user scott account unlock;解鎖)。
<wbr>SQL> explain
plan for SELECT * FROM emp, dept WHERE emp.deptno =
dept.deptno <wbr> AND empno = 7782;
<wbr>SQL>
@$ORACLE_HOME/rdbms/admin/utlxpls.sql
<wbr>PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------
| Id<wbr> |
Operation <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr>
| Name <wbr> <wbr> <wbr> |
Rows <wbr> | Bytes | Cost (%CPU)|
Time <wbr> <wbr> <wbr> <wbr>
|
----------------------------------------------------------------------------------------
|<wbr> <wbr>
0 | SELECT
STATEMENT <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr> <wbr>
1 | <wbr> <wbr> 117
| <wbr> <wbr> <wbr> <wbr>
3 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
|<wbr> <wbr>
1 | <wbr> NESTED
LOOPS <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr> <wbr>
1 | <wbr> <wbr> 117
| <wbr> <wbr> <wbr> <wbr>
3 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
|<wbr> <wbr>
2 | <wbr> <wbr> TABLE ACCESS BY INDEX
ROWID|
EMP <wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr> <wbr>
1 | <wbr> <wbr> <wbr> 87
| <wbr> <wbr> <wbr> <wbr>
2 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
|*<wbr> 3
| <wbr> <wbr> <wbr> INDEX
UNIQUE SCAN <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr>
| PK_EMP <wbr>
| <wbr> <wbr> <wbr> <wbr>
1
| <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr> <wbr>
1 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
|<wbr> <wbr>
4 | <wbr> <wbr> TABLE ACCESS BY INDEX
ROWID| DEPT <wbr> <wbr> <wbr>
| <wbr> <wbr> 409 | 12270
| <wbr> <wbr> <wbr> <wbr>
1 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
|*<wbr> 5
| <wbr> <wbr> <wbr> INDEX
UNIQUE SCAN <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr>
| PK_DEPT
| <wbr> <wbr> <wbr> <wbr>
1
| <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
| <wbr> <wbr> <wbr> <wbr>
0 <wbr> <wbr> <wbr>
<wbr>(0)| 00:00:01 |
----------------------------------------------------------------------------------------
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
注意看Operation的“縮排”。這個語句被解析成一棵“樹”。這課樹大約是
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
1
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
/
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
2 <wbr> <wbr> 4
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
/ <wbr> <wbr> <wbr> <wbr>
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
3 <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
5
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
上面的數字,和PLAN_TABLE_OUTPUT中的“Id”是對應的。簡單來說,就是這個語句有2,4構成;2又由3構成;4由5構成。
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
詳細的SQL查詢計劃可以參閱其他書籍,作為初學者可以僅僅關注一下報告中的“TABLE
ACCESS FULL”。如果你有where子句還有這個TABLE ACCESS
FULL出現,表明你缺少索引(這僅僅針對初學者,但是現實生活中卻也能解決60-70%的問題)。
<wbr> <wbr> <wbr> 2、AUTOTRACE:目的是為了給出執行SQL時,實際進行了多少工作。
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>autotrace的特點在於簡單。
----------------------------------------------------------------------------------------
| Id
----------------------------------------------------------------------------------------
|
|
|
|*
|
|*
----------------------------------------------------------------------------------------
SQL> set autotrace ?
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
Statistics
----------------------------------------------------------
關閉:
alter session set events '10046 trace name context off';
------- ------
Parse
Execute
Fetch
------- ------
total
Elapsed times include waiting on following events:
********************************************************************************
參見:《Oracle高效設計》 Thomas Kyte
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70612/viewspace-1019714/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- EXPLAIN PLAN and SQL*PLUS AUTOTRACE may not generate actual plansAISQL
- autotrace explain plan 相關引數解釋AI
- EXPLAIN PLAN FOR 和 SET AUTOTRACE之間的差別AI
- Oracle EXPLAIN PLAN用法OracleAI
- oracle explain plan for的用法OracleAI
- autotrace 和explain plan for可能導致執行計劃錯誤AI
- ORACLE EXPLAIN PLAN的總結OracleAI
- Explain PlanAI
- explain plan VS execution planAI
- USE EXPLAIN PLANAI
- Explain Plan中AUTOTRACE引起的SP2-0613和SP2-0611錯誤 (轉)AI
- Explain for the Statistics of Execution PlanAI
- explain plan 的用法AI
- Oracle執行計劃Explain Plan 如何使用OracleAI
- oracle 使用explain plan分析查詢語句OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- 配置oracle 解釋執行計劃--explain planOracleAI
- 《oracle效能工具包》Oracle
- sql中使用函式導致explain plan for和set autotrace得到執行計劃不準確SQL函式AI
- Use the statspack to generate the accurate explain planAI
- explain plan 學習記錄AI
- Error: cannot fetch last explain plan from PLAN_TABLEErrorASTAI
- Using Statspack to Record Explain Plan DetailsAI
- 用EXPLAIN PLAN 分析SQL語句AISQL
- oracle explain plan for獲取執行計劃並不可靠.OracleAI
- 【Explain Plan】10g中的PLAN_TABLE$臨時表AI
- Oracle AutotraceOracle
- 轉:使用 Tkprof 分析 ORACLE 跟蹤檔案Oracle
- oracle tkprof使用小結 -- 轉自網路Oracle
- toad顯示explain plan的問題AI
- Oracle Trace 及TKPROFOracle
- (轉):學習Oracle動態效能表-(6)-V$SQL,V$SQL_PLANOracleSQL
- 使用EXPLAIN PLAN來檢視執行計劃AI
- TOAD中檢視執行計劃(Explain Plan)AI
- 【Explain Plan】檢視SQL的執行計劃AISQL
- Oracle工具篇之TkprofOracle
- oracle tkprof使用小結Oracle