Table of Contents

Oracle Database - Autotrace

About

Sql Developer Autotrace

Autotrace is:

AUTOTRACE provides you:

Autotrace is fully accessible to each developer while tkprof relies on access to a trace file.

“set autotrace on” doesn’t work with a PL/SQL procedure.

Autotrace Output

Autotrace output has two parts :

The query plan report

Execution Plan
----------------------------------------------------------
Plan hash value: 4015478428

------------------------------------------------------------------------------------------
| Id  | Operation                      | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |         |    15 |  1755 |    13  (16)| 00:00:01 |
|   1 |  VIEW                          |         |    15 |  1755 |    13  (16)| 00:00:01 |
|   2 |   UNION-ALL                    |         |       |       |            |          |
|*  3 |    HASH JOIN OUTER             |         |    14 |   798 |     7  (15)| 00:00:01 |
|   4 |     TABLE ACCESS FULL          | EMP     |    14 |   518 |     3   (0)| 00:00:01 |
|   5 |     TABLE ACCESS FULL          | DEPT    |     4 |    80 |     3   (0)| 00:00:01 |
|   6 |    MERGE JOIN ANTI             |         |     1 |    23 |     6  (17)| 00:00:01 |
|   7 |     TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    80 |     2   (0)| 00:00:01 |
|   8 |      INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00:00:01 |
|*  9 |     SORT UNIQUE                |         |    14 |    42 |     4  (25)| 00:00:01 |
|  10 |      TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 00:00:01 |
------------------------------------------------------------------------------------------

In this query plan output, the optimizer information represents the following :

In 9i and below, if the cost, card and bytes is not present, it's a clear indicator that the query was executed using the RBO and not the CBO.

Statistics

The second part of the autotrace output are the session statistics.

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         24  consistent gets
          0  physical reads
          0  redo size
       1598  bytes sent via SQL*Net to client
        396  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         15  rows processed

How to install autotrace to a user

Below the action to perform in order to set autotrace to a user :

C:\Documents and Settings\Nicolas>sqlplus SYS/password@ORCL as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Nov 10 14:57:48 2008

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> grant PLUSTRACE to scott;
grant PLUSTRACE to scott
      *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist

SQL> @C:\oracle\product\10.2.0\db_1\sqlplus\admin\plustrce.sql

SQL> grant plustrace to scott;

Grant succeeded.

SQL>