oracle——查看sql的执行计划

oracle——查看sql的执行计划

在sql plus中,输入set autotrace on ; 直接写条sql,按F5,就可以调出执行计划,但在pl/sql developer 的情况下,只能用下面这个语句了,
explain plan for select ....
然后再来一句
select * from table(dbms_xplan.display());
就会出现一个类似下面的信息
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

----------------------------------------------------------------------------
| Id  | Operation                    |  Name       | Rows  | Bytes | Cost  |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |             |       |       |       |
|   1 |  NESTED LOOPS                |             |       |       |       |
|   2 |   TABLE ACCESS FULL          | AC01        |       |       |       |
|   3 |   TABLE ACCESS BY INDEX ROWID| AB01        |       |       |       |
|   4 |    INDEX UNIQUE SCAN         | PK_AB01     |       |       |       |
----------------------------------------------------------------------------


PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Note: rule based optimization, PLAN_TABLE' is old version

就能看到执行计划了。




一、什么是执行计划
An explain plan is a representation of the access path that is taken when a query is executed within Oracle.

二、如何访问数据
At the physical level Oracle reads blocks of data. The smallest amount of data read is a single Oracle block, the largest is constrained by operating system limits (and multiblock i/o). Logically Oracle finds the data to read by using the following methods:
Full Table Scan (FTS)                 --全表扫描
Index Lookup (unique & non-unique)    --索引扫描(唯一和非唯一)
Rowid    --物理行id

三、执行计划层次关系
When looking at a plan, the rightmost uppermost operation is the first thing that is executed. --采用最右最上最先执行的原则看层次关系,在同一级如果某个动作没有子ID就最先执行

1.一个简单的例子:

SQL> select    *  from emp e;

Execution Plan
----------------------------------------------------------
   0    

你可能感兴趣的:(oracle监控,调优)