Oracle查看执行计划的三种方法

1 设置autotrace

 

序号          命令                                解释
 1           SET AUTOTRACE OFF                   此为默认值,即关闭Autotrace
 2           SET AUTOTRACE ON EXPLAIN            只显示执行计划
 3           SET AUTOTRACE ON STATISTICS         只显示执行的统计信息 
 4           SET AUTOTRACE ON                    包含2,3两项内容
 5           SET AUTOTRACE TRACEONLY             与ON相似,但不显示语句的执行结果
SQL> conn leo/leo     
Connected.
SQL> set autotrace on
SQL> select owner,OBJECT_NAME from leo;

OWNER			       OBJECT_NAME
------------------------------ ------------------------------
APEX_030200		       WWV_MIG_ACC_LOAD
APEX_030200		       WWV_FLOW_GENERATE_DDL
APEX_030200		       APEX_ADMIN
APEX_030200		       HTMLDB_ADMIN
APEX_030200		       WWV_FLOW_HELP
APEX_030200		       APEX_UI_DEFAULT_UPDATE
APEX_030200		       APEX_MIG_PROJECTS_UPDATE
SYS			       DATABASE_SUMMARY
PUBLIC			       COE_CONFIGURATION
XDB			       XMLROOT
PUBLIC			       XMLROOT

OWNER			       OBJECT_NAME
------------------------------ ------------------------------
PUBLIC			       COE_NAMESPACES
PUBLIC			       COE_DOM_HELPER
PUBLIC			       COE_UTILITIES
PUBLIC			       COE_TOOLS
LEO			       LEO

16 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1174476904

--------------------------------------------------------------------------
| Id  | Operation	  | Name | Rows  | Bytes | Cost (%CPU)| Time	 |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |	 |     1 |    34 |   276   (0)| 00:00:04 |
|   1 |  TABLE ACCESS FULL| LEO  |     1 |    34 |   276   (0)| 00:00:04 |
--------------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)


Statistics
----------------------------------------------------------
	  4  recursive calls
	  0  db block gets
       1058  consistent gets
	  0  physical reads
	  0  redo size
       1126  bytes sent via SQL*Net to client
	534  bytes received via SQL*Net from client
	  3  SQL*Net roundtrips to/from client
	  0  sorts (memory)
	  0  sorts (disk)
	 16  rows processed

2 使用SQL

 

 

SQL>EXPLAIN PLAN FOR sql语句;

SQL>SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));
	
操作:
SQL> EXPLAIN PLAN FOR select owner,OBJECT_NAME from leo;

Explained.

SQL> SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE'));
或者:
SQL>  select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1174476904

--------------------------------------------------------------------------
| Id  | Operation	  | Name | Rows  | Bytes | Cost (%CPU)| Time	 |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |	 |     1 |    34 |   276   (0)| 00:00:04 |
|   1 |  TABLE ACCESS FULL| LEO  |     1 |    34 |   276   (0)| 00:00:04 |
--------------------------------------------------------------------------

Note
-----

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   - dynamic sampling used for this statement (level=2)

12 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2137789089

---------------------------------------------------------------------------------------------
| Id  | Operation			  | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT		  |	    |  8168 | 16336 |	 29   (0)| 00:00:01 |
|   1 |  COLLECTION ITERATOR PICKLER FETCH| DISPLAY |  8168 | 16336 |	 29   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
	 33  recursive calls
	 12  db block gets
	197  consistent gets
	  0  physical reads
	  0  redo size
       1182  bytes sent via SQL*Net to client
	523  bytes received via SQL*Net from client
	  2  SQL*Net roundtrips to/from client
	  1  sorts (memory)
	  0  sorts (disk)
	 12  rows processed

3 3 查看真实的执行计划

select a.sid, a.event, a.sql_id, a.sql_child_number, b.sql_text
from v$session a, v$sql b
where a.sql_address = b.address
and a.sql_hash_value = b.hash_value
and a.sql_child_number = b.child_number
order by 1 desc;

查出sql_id,sql_child_number 传入以下参数
select * from table(dbms_xplan.display_cursor('sql_id',child_number));

你可能感兴趣的:(Oracle,11g)