Sunteți pe pagina 1din 13

An execution plan is a list of steps that Oracle will follow in order to execute a SQL statement.

Each step is one of a finite number of basic operations known to the database server. EXPLAIN PLAN is a statement that allows you to have Oracle generate the execution plan for any SQL statement without actually executing it. Query the Plan table to get the explain plan.

Generated by the EXPLAIN PLAN statement. Default name is plan_table. User can use any name he likes. Execute $ORACLE_HOME/rdbms/admin/utlxplan.sql to create the Plan table.

statement_id execution plan timestamp operation the options operation, object_name accessed optimizer id parent_id

Unique identifier for each

When the execution plan was generated The operation performed in one step of execution plan, such as table access Additional information about the such as by index ROWID Name of table, index, view, etc.
Optimizer goal used when creating execution plan Step number in execution plan Step number of parent step

INSERT privilege on a plan table SELECT privileges on underlying tables of views, if the statement being explained involves views. The syntax to take the explain plan from command line is as follows:

EXPLAIN PLAN FOR <SQL statement>;

The trace file output of a session or SQL can be generated when the SQL Trace is enabled at session or database level. The trace file will be in a non-readable format and hence in order to better interpret it, we need the TKPROF utility. The following is the syntax:
tkprof <trace file> <output file> \ [explain=<username/password>] \ [sys=n] [insert=<filename>] \ [record=<filename>] [sort=<keyword>]

At the instance level:


sql_trace = true
timed_statistics = true (optional)

In your own session:


ALTER SESSION SET sql_trace = TRUE;
ALTER SESSION SET timed_statistics = TRUE; (optional)

In

another session:
SYS.dbms_system.set_sql_trace_in_session
(<SID>, <serial#>, TRUE)

trace file output file explain=

The SQL trace file to be formatted The formatted output to be written by TKPROF Database login to be used if you want the output to include execution plans sys=n Omit recursive SQL performed by the SYS user insert= Generate SQL script to insert statistical data into a database table record= Generate a separate file listing all SQL statements traced sort= List traced SQL statement in the output file in a specific order

TKPROF: Release 8.1.6.1.0 - Production on Wed Aug 9 19:06:36 2000 (c) Copyright 1999 Oracle Corporation. All rights reserved.

Trace file: example.trc Sort options: default ************************************************************************ count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call

TABLE ACCESS FULL Perform a full table scan of the indicated table and retrieve all rows that meet criteria from the WHERE clause. Input: no subordinate operations. Output: the necessary columns from the rows meeting all criteria. SORT ORDER BY Sort the input rows for the purpose of satisfying an ORDER BY clause. Input: the rows to be sorted. Output: the rows in sorted order.

INDEX UNIQUE SCAN Look up a complete key in a unique index. Input: no subordinate operations. (Key values come from the original query or a parent operation.) Output: Zero or one ROWIDs from the index.
INDEX RANGE SCAN Look up a key in a non-unique index, or an incomplete key in a unique index. Input: no subordinate operations. Output: Zero or more ROWIDs from the index.

TABLE ACCESS BY INDEX ROWID

Look up rows in a table by their ROWIDs. Input: a list of ROWIDs to look up. Output: the necessary columns from the rows with the given ROWIDs.
NESTED LOOPS Perform a join between two sets of row data using the nested loops algorithm. Inputs: two separate sets of row data. Output: the results of the join. Oracle reads each row from the first input one at a time. For each of these rows, the operations that make up the second input are executed once and matching rows generate output.

Report heading
TKPROF version, date run, sort option, trace filename

One entry for each distinct SQL statement in trace file


Listing of SQL statement OCI call statistics: count of parse, execute, and fetch calls, rows processed, and time and I/O used Parse information: parsing user, recursive depth, library cache misses, and optimizer mode Row source operation listing Execution plan listing (optional)

S-ar putea să vă placă și