3.解释执行计划的方法
2013-08-20 15:11
281 查看
2013-08-06
--------------解释执行计划的方法----------------------------
用autotrace前提:
SQL> @/u01/oracle/product/10.2.0/db_1/sqlplus/admin/plustrce.sql --sys用户下执行
SQL>
SQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist
SQL> create role plustrace;
Role created.
SQL> grant select on v_$sesstat to plustrace;
Grant succeeded.
SQL> grant select on v_$statname to plustrace;
Grant succeeded.
SQL> grant select on v_$mystat to plustrace;
Grant succeeded.
SQL> grant plustrace to dba with admin option;
Grant succeeded.
SQL> set echo off
SQL> grant plustrace to scott; --将权限授予SCOTT可以用autotrace
Grant succeeded.
-------------------------------------------------------------
1、autotrace工具详解
SQL> set autotrace off ――默认情况下是关闭的
SQL> set autotrace on exp --显示查询结果、执行计划
SQL> select * from t where rownum=1;
OWNER OBJECT_TYPE
------------------------------ -------------------
PUBLIC SYNONYM
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 45659 | 1248K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
SQL> set autotrace on --显示查询结果、执行计划、执行的物理统计信息
SQL> select * from t where rownum=1;
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
DUAL TABLE
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
71 recursive calls
0 db block gets
146 consistent gets
155 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace on stat --显示查询结果、执行的物理统计信息
SQL> select * from t where rownum=1;
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
DUAL TABLE
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace exp --显示执行计划
SQL> select * from t where rownum=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
SQL> set autotrace trace exp stat --显示执行计划和物理统计信息
SQL> select * from t where rownum=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace stat --显示物理统计信息
SQL> select * from t where rownum=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
---------------------------------------------------------------
总结:
set autotrace on = set autotrace on exp stat
set autotrace on exp stat
on exp
on stat
trace = trace exp stat
trace exp stat
trace exp
trace stat
只要有on,一定会显示数据,只要有trace,就不显示数据。
--------------------------------------------------------------------
2、dbms_xplan --通过内部的包,仅仅显示执行计划
解释执行计划
SQL> explain plan for select * from t where rownum=1;
Explained.
查看执行计划
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
18 rows selected.
本文出自 “云迹” 博客,请务必保留此出处http://chenhuican.blog.51cto.com/6965507/1278960
--------------解释执行计划的方法----------------------------
用autotrace前提:
SQL> @/u01/oracle/product/10.2.0/db_1/sqlplus/admin/plustrce.sql --sys用户下执行
SQL>
SQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist
SQL> create role plustrace;
Role created.
SQL> grant select on v_$sesstat to plustrace;
Grant succeeded.
SQL> grant select on v_$statname to plustrace;
Grant succeeded.
SQL> grant select on v_$mystat to plustrace;
Grant succeeded.
SQL> grant plustrace to dba with admin option;
Grant succeeded.
SQL> set echo off
SQL> grant plustrace to scott; --将权限授予SCOTT可以用autotrace
Grant succeeded.
-------------------------------------------------------------
1、autotrace工具详解
SQL> set autotrace off ――默认情况下是关闭的
SQL> set autotrace on exp --显示查询结果、执行计划
SQL> select * from t where rownum=1;
OWNER OBJECT_TYPE
------------------------------ -------------------
PUBLIC SYNONYM
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 45659 | 1248K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
SQL> set autotrace on --显示查询结果、执行计划、执行的物理统计信息
SQL> select * from t where rownum=1;
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
DUAL TABLE
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
71 recursive calls
0 db block gets
146 consistent gets
155 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace on stat --显示查询结果、执行的物理统计信息
SQL> select * from t where rownum=1;
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
DUAL TABLE
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace exp --显示执行计划
SQL> select * from t where rownum=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
SQL> set autotrace trace exp stat --显示执行计划和物理统计信息
SQL> select * from t where rownum=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace trace stat --显示物理统计信息
SQL> select * from t where rownum=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
483 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
---------------------------------------------------------------
总结:
set autotrace on = set autotrace on exp stat
set autotrace on exp stat
on exp
on stat
trace = trace exp stat
trace exp stat
trace exp
trace stat
只要有on,一定会显示数据,只要有trace,就不显示数据。
--------------------------------------------------------------------
2、dbms_xplan --通过内部的包,仅仅显示执行计划
解释执行计划
SQL> explain plan for select * from t where rownum=1;
Explained.
查看执行计划
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 28 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 43751 | 1196K| 2 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - filter(ROWNUM=1)
Note
-----
- dynamic sampling used for this statement
18 rows selected.
本文出自 “云迹” 博客,请务必保留此出处http://chenhuican.blog.51cto.com/6965507/1278960
相关文章推荐
- PostgreSQL执行计划的解释
- [Oracle]获取执行计划的各个方法总结
- 获得执行计划方法二-explain plan
- Oracle之深入浅出(二)--SQL原理、解释计划与执行计划
- 执行计划里recursive calls,db block gets和consistent gets参数的解释
- oracle 查看执行计划方法(SQL developer,sqlplus)
- 简单对比查看执行计划的两种方法EXPLAIN PLAN 和 AUTOTRACE
- Oracle 执行计划 提示 'PLAN_TABLE' is old version 解决方法
- PostgreSQL执行计划的解释
- Oracle之SQL优化专题01-查看SQL执行计划的方法
- ORACLE数据库查看执行计划的方法
- 获得执行计划方法-一 ORACLE AUTOTRACE
- PostgreSQL SQL的性能调试方法3--查看执行计划
- 获得执行计划方法四-使用10046事件
- [Oracle]获取执行计划的各个方法总结
- PHP定时执行计划任务的多种方法小结
- win2008中设置计划任务执行PHP文件的方法
- 获得执行计划方法-一 ORACLE AUTOTRACE
- 关于Android中调用了post方法后貌似没有执行run方法的解释及解决办法
- 获取SQL执行计划的常见几种方法