Thursday, March 13, 2008

Oracle Auto Trace

1]ORACLE

SQL> set timing on
SQL> set autotrace on explain
SQL> Select * from scott.emp where (1=0);
no rows selected
Elapsed: 00:00:00.84
Execution Plan
----------------------------------------------------------
Plan hash value: 820423529
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1126 | 0 (0)| |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL| emp | 1444 | 1587K| 56 (2)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(NULL IS NOT NULL)

Finally once you are done
SQL> set timing off
SQL> set autotrace off

Notes:
Autotrace supports various options including ON, ON EXPLAIN, ON STATISTICS, TRACE EXPLAIN, TRACEONLY which are explained below.

1]ON – Enables all options.
2]ON explain – Displays returned rows and the explain plan.
3]on statistics – Displays returned rows and statistics.
4]trace explain – Displays the execution plan for a select statement without actually executing it. (set autotrace trace explain).This will be particularly useful when you have blob items that cannot be displayed on sqlplus.
5]Traceonly – Displays execution plan and statistics without displaying the returned rows. This option should be used when a large result set is expected.

No comments: