语法:
explain plan for + 目标SQL
select * from table(dbms_xplan.display);
eg:
SQL> explain plan for select empno,ename,dname from scott.emp,scott.dept where emp.deptno=dept.deptno;
Explained.
SQL> set linesize 800
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------
Plan hash value: 844388907
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 364 | 6 (17)| 00:00:01 |
| 1 | MERGE JOIN | | 14 | 364 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 52 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 00:00:01 |
|* 4 | SORT JOIN | | 14 | 182 | 4 (25)| 00:00:01 |
| 5 | TABLE ACCESS FULL | EMP | 14 | 182 | 3 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
filter("EMP"."DEPTNO"="DEPT"."DEPTNO")
18 rows selected.
Oracle10g\11g中,如果我们对目标SQL执行explain plan命令,则oracle就将解析目标SQL所产生的执行计划的具体执行步骤写入PLAN_TABLE$,随后执行select * from table(dbms_xplan.display),只是从PLAN_TABLE$中将这些具体执行步骤以格式化的方式显示出来。
PLAN_TABLE$是一个on commit preserve rows的global temporary table,所以这里Oracle可以做到各个session只能看到自己执行的SQL所产生的执行计划,并且各个session往PLAN_TABLE$写入执行计划的过程互不干扰。
原文地址:https://blog.51cto.com/14387135/2465711