Basics of Oracle Explain Plan

download Basics of Oracle Explain Plan

of 13

Transcript of Basics of Oracle Explain Plan

  • 7/29/2019 Basics of Oracle Explain Plan

    1/13

  • 7/29/2019 Basics of Oracle Explain Plan

    2/13

    An execution plan is a list of steps thatOracle will follow in order to execute a SQLstatement.

    Each step is one of a finite number of basicoperations known to the database server. EXPLAIN PLAN is a statement that allows

    you to have Oracle generate the execution

    plan for any SQL statement withoutactually executing it. Query the Plan table to get the explain

    plan.

  • 7/29/2019 Basics of Oracle Explain Plan

    3/13

    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.

  • 7/29/2019 Basics of Oracle Explain Plan

    4/13

    statement_id Unique identifier for eachexecution plan

    timestamp When the execution plan was generated

    operation The operation performed in one step ofthe execution plan, such as table access

    options Additional information about theoperation, such as by index ROWID

    object_name Name of table, index, view, etc.accessed

    optimizer Optimizer goal used when creatingexecution plan

    id Step number in execution plan

    parent_id Step number of parent step

  • 7/29/2019 Basics of Oracle Explain Plan

    5/13

    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

    ;

  • 7/29/2019 Basics of Oracle Explain Plan

    6/13

  • 7/29/2019 Basics of Oracle Explain Plan

    7/13

    The trace file output of a session or SQL can begenerated when the SQL Trace is enabled atsession or database level.

    The trace file will be in a non-readable formatand hence in order to better interpret it, weneed the TKPROF utility. The following is thesyntax:

    tkprof \

    [explain=] \

    [sys=n] [insert=] \[record=] [sort=]

  • 7/29/2019 Basics of Oracle Explain Plan

    8/13

    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

    (, , TRUE)

  • 7/29/2019 Basics of Oracle Explain Plan

    9/13

    trace file The SQL trace file to be formatted

    output file The formatted output to be written by TKPROFexplain= Database login to be used if you want the output to

    include execution planssys=n Omit recursive SQL performed by the SYS user

    insert= Generate SQL script to insert statistical data into a

    database tablerecord= Generate a separate file listing all SQL statements

    tracedsort= List traced SQL statement in the output file in a

    specific order

  • 7/29/2019 Basics of Oracle Explain Plan

    10/13

    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

  • 7/29/2019 Basics of Oracle Explain Plan

    11/13

    TABLE ACCESS FULLPerform a full table scan of the indicated table and retrieve all rows thatmeet criteria from the WHERE clause. Input: no subordinate operations.Output: the necessary columns from the rows meeting all criteria.

    SORT ORDER BYSort 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 SCANLook up a complete key in a unique index. Input: no subordinateoperations. (Key values come from the original query or a parent

    operation.) Output: Zero or one ROWIDs from the index.

    INDEX RANGE SCANLook up a key in a non-unique index, or an incomplete key in a uniqueindex. Input: no subordinate operations. Output: Zero or more ROWIDs

    from the index.

  • 7/29/2019 Basics of Oracle Explain Plan

    12/13

    TABLE ACCESS BY INDEX ROWID

    Look up rows in a table by their ROWIDs. Input: a list of ROWIDs to lookup. 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 loopsalgorithm. Inputs: two separate sets of row data. Output: the results ofthe join.

    Oracle reads each row from the first input one at a time. For each ofthese rows, the operations that make up the second input are executed

    once and matching rows generate output.

  • 7/29/2019 Basics of Oracle Explain Plan

    13/13

    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 fetchcalls, 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)