difference between explain plan and execution plan

隐身守侯 提交于 2019-11-29 00:39:45

问题


Can anyone explain me what is the difference between execution plan and explain plan.

When I execute

 set autotrace traceonly;
 select * from emp where empno=7369;

Execution Plan
----------------------------------------------------------
  0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=1 Card=1 Bytes=38)
  1    0    TABLE ACCESS BY INDEX ROWID SCOTT.EMP (Cost=1 Card=1 Bytes=38)
  2    1      INDEX UNIQUE SCAN SCOTT.PK_EMP (Cost=0 Card=1)


 Explain Plan

 explain plan for select * from emp where empno=7369;
 select * from table(dbms_xplan.display);

Plan hash value: 2949544139

--------------------------------------------------------------------------------------
| Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |        |     1 |    38 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    38 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | PK_EMP |     1 |       |     0   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

I am getting the same output, so what is the difference between the two.


回答1:


explain plan is the statement that is used to display the execution plan.

The two samples you have shown are just formatted differently, that's all.

You did not tell us how exactly you generated those outputs nor which tool you were using.

But if'm not mistaken, one of them is the output of an autotrace inside SQL*Plus the other the output when using of of the procedures of the dbms_xplan package.




回答2:


The explain plan is what the optimizer thinks will happen when you run, the execution plan is actually happened when you ran the query.

See link here.

http://tkyte.blogspot.co.uk/2007/04/when-explanation-doesn-sound-quite.html



来源:https://stackoverflow.com/questions/10572619/difference-between-explain-plan-and-execution-plan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!