DBA Tips Archive for Oracle

  


Automatic EXPLAIN PLANS and TKPROF

by Jeff Hunter, Sr. Database Administrator

As of SQL*Plus 3.3, it is easier than ever to perform EXPLAIN PLANS and TKPROF reports on the fly. Intead of worrying about getting the SQL statement working and then adding the 'EXPLAN PLAN SET...' commands to the query, you only need to remember the command 'SET AUTOTRACE ON'.

The SET AUTOTRACE Command

In SQL*Plus 3.3 there is a command called SET AUTOTRACE. It is documented in the newest SQL*Plus document set. In a SQL*Plus session, simply type:

 SET AUTOTRACE ON
And then run your select statement. Example:
    SQL> set autotrace on
    SQL> select name Name, count(*) Count
      2  from user_names
      3  group by name;

    NAME                COUNT
    --------------- ---------
    Abe Smith             999
    Amy Brown               1
    Default User        16579
    John Smith           2922


    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (GROUP BY)
       2    1     TABLE ACCESS (FULL) OF 'USER_NAMES'




    Statistics
    ----------------------------------------------------------
            201  recursive calls
              4  db block gets
            312  consistent gets
            281  physical reads
              0  redo size
            707  bytes sent via SQL*Net to client
            690  bytes received via SQL*Net from client
              4  SQL*Net roundtrips to/from client
              5  sorts (memory)
              0  sorts (disk)
              4  rows processed
    
There are also some other options, for example there is a TRACEONLY option which supresses the SQL output. See the SQL*Plus 3.3 manual for a full description.

Some setup issues:

Before a user can access the AUTOTRACE service, there are a few setup issues for the DBA:

  1. Make sure you have access to PLAN_TABLE. If you don't, create it using utlxplan.sql (The script should be in the directory: $ORACLE_HOME/rdbms73/admin/) and make sure you have access to it from the user you are using to run the SQL.

  2. You also need to create the PLUSTRACE role, and grant it to the desired users. The script to create this role is in:

    $ORACLE_HOME/plus33/Plustrce.sql

    It has to be run from SYS in order to have the correct security access. Then grant the role to the desired users or ROLEs.



Copyright (c) 1998-2017 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Monday, 17-Jul-2000 00:00:00 EDT
Page Count: 14040