Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between explain plan and execution plan

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.

like image 939
Gaurav Soni Avatar asked May 13 '12 14:05

Gaurav Soni


People also ask

What is the execution plan?

An execution plan is generated when you execute any query which necessarily includes the query along with the plan. Running an execution plan for a particular query provides insights into the SQL Server query optimizer and query engine.

How do you use explain plan?

To explain a SQL statement, use the EXPLAIN PLAN FOR clause immediately before the statement. For example: EXPLAIN PLAN FOR SELECT last_name FROM employees; This explains the plan into the PLAN_TABLE table.

What is the difference between actual and estimated execution plan?

The major difference between Estimated vs Actual Execution Plan is that the Actual Execution plan contains additional details about the operator execution time as well as the row read from the database.

Is query plan same as execution plan?

The input to the Query Optimizer consists of the query, the database schema (table and index definitions), and the database statistics. The output of the Query Optimizer is a query execution plan, sometimes referred to as a query plan, or execution plan.


2 Answers

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

like image 194
steve godfrey Avatar answered Nov 24 '22 06:11

steve godfrey


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.

like image 30
a_horse_with_no_name Avatar answered Nov 24 '22 05:11

a_horse_with_no_name