use explain plan

Upload: riaz-sheikh

Post on 06-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Use Explain Plan

    1/53

    Use EXPLAIN PLAN and TKPROFTo Tune Your Applications

    Roger SchragDatabase Specialists, Inc.www.dbspecialists.com

    NoCOUG November 14, 2000

  • 8/3/2019 Use Explain Plan

    2/53

    Todays Session

    EXPLAIN PLAN overview

    TKPROF overview

    Why???

    Reading execution plans

    Reading TKPROF reports

  • 8/3/2019 Use Explain Plan

    3/53

    White Paper

    Twenty one pages of details I can't possiblycover in a one hour presentation!

    Lots of sample code, execution plans, andTKPROF reports that you will see are probablynot readable when I put them up on PowerPointslidesbut they are readable in the white paper.Available at:www.dbspecialists.com/4dbas/present.html

  • 8/3/2019 Use Explain Plan

    4/53

    Execution Plans and EXPLAIN PLANAn execution plan is a list of steps that Oracle willfollow in order to execute a SQL statement. Each stepis one of a finite number of basic operations known tothe database server. Even the most complex SQLstatement can be broken down into a series of basicoperations.EXPLAIN PLAN is a statement that allows you tohave Oracle generate the execution plan for any SQLstatement without actually executing it. You will beable to examine the execution plan by querying the

    plan table.

  • 8/3/2019 Use Explain Plan

    5/53

    The Plan Table

    A plan table holds execution plans generated by the EXPLAIN PLAN statement.

    The typical name for a plantable is plan_table, but youmay use any name you wish.

    Create the plan table byrunning utlxplan.sql, located

    in $ORACLE_HOME/rdbms/admin.

  • 8/3/2019 Use Explain Plan

    6/53

    Important Columns in the Plan Tablestatement_id Unique identifier for each execution plantimestamp When the execution plan was generatedoperation The operation performed in one step of the

    execution plan, such as table accessoptions Additional information about the operation,

    such as by index ROWIDobject_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

  • 8/3/2019 Use Explain Plan

    7/53

    EXPLAIN PLAN Prerequisites

    INSERT privilege on a plan table

    All necessary privileges to execute thestatement being explained

    SELECT privileges on underlying tables of views, if the statement being explainedinvolves views

  • 8/3/2019 Use Explain Plan

    8/53

    EXPLAIN PLAN Syntax

    EXPLAIN PLAN

    [SET STATEMENT_ID = ]

    [INTO ]FOR

    ;

  • 8/3/2019 Use Explain Plan

    9/53

    Querying an Execution Plan From

    The Plan TableUse a CONNECT BY clause to trace the hierarchyUse LPAD function to indent rows, making the

    hierarchy easier to followPut statement_id in WHERE clause to retrieve only oneexecution plan at a time

    Sample script on next slide shows the most importantinformation

    You can also try utlxpls.sql or utlxplp.sql in$ORACLE_HOME/rdbms/admin

  • 8/3/2019 Use Explain Plan

    10/53

    A Simple Query to Display

    Execution PlansSET VERIFY OFFACCEPT stmt_id CHAR PROMPT "Enter statement_id: "COL id FORMAT 999

    COL parent_id FORMAT 999 HEADING "PARENT"COL operation FORMAT a35 TRUNCATECOL object_name FORMAT a30SELECT id, parent_id, LPAD (' ', LEVEL - 1) ||

    operation || ' ' || options operation,object_name

    FROM plan_tableWHERE statement_id = '&stmt_id'START WITH id = 0AND statement_id = '&stmt_id'CONNECT BY PRIOR id = parent_id

    AND statement_id = '&stmt_id';

  • 8/3/2019 Use Explain Plan

    11/53

    A Sample Execution PlanSQL> EXPLAIN PLAN SET statement_id = 'demo' FOR

    2 SELECT a.customer_name, a.customer_number, b.invoice_number,3 b.invoice_type, b.invoice_date, b.total_amount,4 c.line_number, c.part_number, c.quantity, c.unit_cost5 FROM customers a, invoices b, invoice_items c6 WHERE c.invoice_id = :b17 AND c.line_number = :b28 AND b.invoice_id = c.invoice_id9 AND a.customer_id = b.customer_id;

    Explained.SQL> @explain.sqlEnter statement_id: demo

    ID PARENT OPERATION OBJECT_NAME---- ------ ----------------------------------- -----------------

    0 SELECT STATEMENT1 0 NESTED LOOPS2 1 NESTED LOOPS3 2 TABLE ACCESS BY INDEX ROWID INVOICE_ITEMS4 3 INDEX UNIQUE SCAN INVOICE_ITEMS_PK5 2 TABLE ACCESS BY INDEX ROWID INVOICES6 5 INDEX UNIQUE SCAN INVOICES_PK7 1 TABLE ACCESS BY INDEX ROWID CUSTOMERS8 7 INDEX UNIQUE SCAN CUSTOMERS_PK

  • 8/3/2019 Use Explain Plan

    12/53

    Other Ways to View Execution Plans

    The autotrace feature in SQL*Plus

    Performance tuning tools

    Check out TOAD from Quest Software at:http://www.toadsoft.com/downld.html

    SET AUTOTRACE OFF|ON|TRACEONLY [EXPLAIN] [STATISTICS]

  • 8/3/2019 Use Explain Plan

    13/53

    Sample Autotrace Output in SQL*PlusExecution Plan----------------------------------------------------------

    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1 Bytes=39)1 0 NESTED LOOPS (Cost=4 Card=1 Bytes=39)2 1 NESTED LOOPS (Cost=3 Card=1 Bytes=27)3 2 TABLE ACCESS (BY INDEX ROWID) OF 'INVOICE_ITEMS' (Cost

    =2 Card=1 Bytes=15)

    4 3 INDEX (UNIQUE SCAN) OF 'INVOICE_ITEMS_PK' (UNIQUE) (Cost=1 Card=2)

    5 2 TABLE ACCESS (BY INDEX ROWID) OF 'INVOICES' (Cost=1 Card=2 Bytes=24)

    6 5 INDEX (UNIQUE SCAN) OF 'INVOICES_PK' (UNIQUE)7 1 TABLE ACCESS (BY INDEX ROWID) OF 'CUSTOMERS' (Cost=1 Car

    d=100 Bytes=1200)

    8 7 INDEX (UNIQUE SCAN) OF 'CUSTOMERS_PK' (UNIQUE)

  • 8/3/2019 Use Explain Plan

    14/53

    Sample Execution Plan Display in

    TOAD

  • 8/3/2019 Use Explain Plan

    15/53

    Trace Files and TKPROFThe Oracle server process managing a database sessionwrites a verbose trace file when SQL trace is enabledfor the session. (Dont confuse SQL trace files withOracle Trace Collection Services or Net8 trace files!)

    TKPROF is a utility provided by Oracle that formatsSQL trace files into very helpful and readable reports.

    TKPROF is installed automatically when the databaseserver software is installed. You invoke TKPROF fromthe operating system command line; there is nographical interface for TKPROF.

  • 8/3/2019 Use Explain Plan

    16/53

    Enabling SQL TraceAt 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)

  • 8/3/2019 Use Explain Plan

    17/53

    Finding the Trace FileLook in the user dump destination. On OFAcompliant systems this will be$ORACLE_BASE/admin/$ORACLE_SID/udump

    Check timestamps and file contents to see whichtrace file is yoursIf non-DBAs need access to trace files, add_trace_files_public = true to theinstance parameter file to avoid permissions

    problems on Unix platformsDo not use multi-threaded server (MTS) when

    tracing

  • 8/3/2019 Use Explain Plan

    18/53

    Formatting a Trace File

    With TKPROFInvoke TKPROF from the operating system

    prompt like this:

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

  • 8/3/2019 Use Explain Plan

    19/53

    TKPROF Command-line Arguments

    trace file The SQL trace file to be formattedoutput 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

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

  • 8/3/2019 Use Explain Plan

    20/53

    TKPROF Sample OutputSELECT a.customer_name, a.customer_number, b.invoice_number,

    b.invoice_type, b.invoice_date, b.total_amount, c.line_number,c.part_number, c.quantity, c.unit_cost

    FROM customers a, invoices b, invoice_items cWHERE c.invoice_id = :b1AND c.line_number = :b2AND b.invoice_id = c.invoice_idAND a.customer_id = b.customer_id

    call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.05 0.02 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 2 0.00 0.00 8 8 0 1------- ------ -------- ---------- ---------- ---------- ---------- ----------

    total 4 0.05 0.02 8 8 0 1

    Misses in library cache during parse: 1Optimizer goal: CHOOSEParsing user id: 34 (RSCHRAG)

  • 8/3/2019 Use Explain Plan

    21/53

    Why Use EXPLAIN PLAN

    And TKPROF?

    Proactively tune applications that are in developmentReactively tune production systems that are experiencing

    performance problems

    Estimate resource requirements or feasibility of ad-hocqueries

    Quantify resource requirements for specific applications

    These tools are critical to the application tuning process, andtuning at the application level is necessary for high performancesystems. With EXPLAIN PLAN and TKPROF, you can:

  • 8/3/2019 Use Explain Plan

    22/53

    Reading Execution Plans

    Read from the most indented step outward.

    This is not exactly correct!

    Instead, take this approach:

    a) Start at the least indented step

    b) Find the step or steps that provide direct input to the step noted in(a).

    c) Evaluate each of the steps found in (b). This may involverecursively finding steps that provide input and evaluating them.

    An execution plan is a hierarchical listing of steps. Each step is one of a few basic data access operations known to the database server. The most complexSQL statement can be broken down into a series of basic operations.

  • 8/3/2019 Use Explain Plan

    23/53

    Execution Plan Example #1

    SELECT customer_id, customer_nameFROM customersWHERE UPPER (customer_name) LIKE 'ACME%'

    ORDER BY customer_name;

    OPERATION OBJECT_NAME------------------------------ --------------SELECT STATEMENT

    SORT ORDER BYTABLE ACCESS FULL CUSTOMERS

  • 8/3/2019 Use Explain Plan

    24/53

    Execution Plan Operations

    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 subordinateoperations. Output: the necessary columns from the rows meeting allcriteria.

    SORT ORDER BY

    Sort the input rows for the purpose of satisfying an ORDER BYclause. Input: the rows to be sorted. Output: the rows in sorted order.

  • 8/3/2019 Use Explain Plan

    25/53

    Execution Plan Example #2

    SELECT a.customer_name, b.invoice_number,b.invoice_date

    FROM customers a, invoices bWHERE b.invoice_date > TRUNC (SYSDATE - 1)AND a.customer_id = b.customer_id;

    OPERATION OBJECT_NAME------------------------------ --------------SELECT STATEMENT

    NESTED LOOPSTABLE ACCESS BY INDEX ROWID INVOICESINDEX RANGE SCAN INVOICES_DATE

    TABLE ACCESS BY INDEX ROWID CUSTOMERSINDEX UNIQUE SCAN CUSTOMERS_PK

  • 8/3/2019 Use Explain Plan

    26/53

    Execution Plan OperationsINDEX UNIQUE SCAN

    Look up a complete key in a unique index. Input: no subordinateoperations. (Key values come from the original query or a parentoperation.) 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 aunique index. Input: no subordinate operations. Output: Zero or more ROWIDs from the index .

  • 8/3/2019 Use Explain Plan

    27/53

    Execution Plan OperationsTABLE 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 resultsof the join.

    Oracle reads each row from the first input one at a time. For eachof these rows, the operations that make up the second input areexecuted once and matching rows generate output.

  • 8/3/2019 Use Explain Plan

    28/53

    Execution Plan Example #3SELECT a.customer_name,

    COUNT (DISTINCT b.invoice_id) open_invs,COUNT (c.invoice_id) open_inv_items

    FROM customers a, invoices b, invoice_items cWHERE b.invoice_status = 'OPEN'AND a.customer_id = b.customer_id

    AND c.invoice_id (+) = b.invoice_idGROUP BY a.customer_name;

    OPERATION OBJECT_NAME-------------------------------- ----------------SELECT STATEMENT

    SORT GROUP BYNESTED LOOPS OUTERHASH JOIN

    TABLE ACCESS BY INDEX ROWID INVOICESINDEX RANGE SCAN INVOICES_STATUS

    TABLE ACCESS FULL CUSTOMERS

    INDEX RANGE SCAN INVOICE_ITEMS_PK

  • 8/3/2019 Use Explain Plan

    29/53

    Execution Plan Operations

    HASH JOIN

    Perform a join between two sets of row data using thehash join algorithm. Inputs: two separate sets of row data.Output: the results of the join.

    Oracle reads all rows from the second

    input and builds a hash structure,before reading each row from the firstinput one at a time. For each row fromthe first input, the hash structure is

    probed and matching rows generateout ut.

  • 8/3/2019 Use Explain Plan

    30/53

    Execution Plan Operations

    NESTED LOOPS OUTER

    Same as the NESTED LOOPS operation, except thatan outer join is performed.

    SORT GROUP BY

    Same as the SORT ORDER BY operation, except thatthe rows are sorted and grouped to satisfy a GROUPBY clause.

  • 8/3/2019 Use Explain Plan

    31/53

    Execution Plan Example #4SELECT customer_nameFROM customers aWHERE EXISTS

    (SELECT 1

    FROM invoices_view bWHERE b.customer_id = a.customer_idAND number_of_lines > 100)

    ORDER BY customer_name;

    CREATE OR REPLACE VIEW invoices_view AS

    SELECT a.invoice_id, a.customer_id,COUNT(*) number_of_lines

    FROM invoices a, invoice_items bWHERE b.invoice_id = a.invoice_idGROUP BY a.invoice_id, a.customer_id;

  • 8/3/2019 Use Explain Plan

    32/53

    Execution Plan Example #4

    (continued )OPERATION OBJECT_NAME----------------------------------- -------------SELECT STATEMENT

    SORT ORDER BYFILTER

    TABLE ACCESS FULL CUSTOMERSVIEW INVOICES_VIEW

    FILTER

    SORT GROUP BYNESTED LOOPSTABLE ACCESS BY INDEX ROWID INVOICES

    INDEX RANGE SCAN INVS_CUST_IDINDEX RANGE SCAN INV_ITEMS_PK

  • 8/3/2019 Use Explain Plan

    33/53

    Execution Plan OperationsFILTER

    Read a set of row data and discard some rows based on

    various criteria. To determine the criteria, operations from asecond input may need to be performed. Input: rows to beexamined and, sometimes, an additional subordinateoperation that must be performed for each row from thefirst input in order to evaluate criteria. Output: the rowsfrom the first input that met the criteria.

  • 8/3/2019 Use Explain Plan

    34/53

    Execution Plan Operations

    VIEW

    Build a physical representation of a database view or subset of a database view. Input: set of row data.Output: set of row data that implements the view or subset of the view.

  • 8/3/2019 Use Explain Plan

    35/53

    Notes on Execution Plan Operations

    The optimizer rewrites subqueries as joins and mergesthem into the main query whenever possible.If a subquery is completely independent of the main

    query and cannot be merged into the main query, theoptimizer may treat the subquery as a separatestatement and leave it out of the execution plan for themain query.

    The optimizer expands view definitions and mergesthem into the main query wherever possible. A VIEWoperation will only appear in an execution plan whenthe view definition could not be merged.

  • 8/3/2019 Use Explain Plan

    36/53

    Execution Plan Example #5SELECT /*+ RULE */ a.cust_name, b.contact_nameFROM customers a, [email protected] bWHERE UPPER(b.contact_name) = UPPER(a.cust_name);

    Execution Plan------------------------------------------------0 SELECT STATEMENT Optimizer=HINT: RULE1 0 MERGE JOIN2 1 SORT (JOIN)3 2 REMOTE* SALES.ACME.COM4 1 SORT (JOIN)5 4 TABLE ACCESS (FULL) OF 'CUSTOMERS'

    3 SERIAL_FROM_REMOTE SELECT "CONTACT_NAME"FROM "CONTACTS" "B

  • 8/3/2019 Use Explain Plan

    37/53

    Execution Plan Operations

    REMOTE

    Submit a SQL statement to a remote database via Net8. Input:typically no subordinate operations. Output: the results of thequery from the remote database. Note that the database link used to access the remote database and the actual SQLsubmitted to the remote database will be accessible from theexecution plan.

  • 8/3/2019 Use Explain Plan

    38/53

    Execution Plan Operations

    SORT JOIN

    Same as the SORT GROUP BY operation, except that theinput is sorted by the join column or columns in

    preparation for a join using the merge join algorithm.

  • 8/3/2019 Use Explain Plan

    39/53

    Execution Plan Operations

    MERGE JOIN

    Perform a join between two sets of row data using themerge join algorithm. Inputs: two separate sets of rowdata. Output: the results of the join.

    Oracle reads rows from both inputs in an alternating

    fashion and merges together matching rows in order togenerate output. The two inputs are assumed to besorted on the join column or columns.

  • 8/3/2019 Use Explain Plan

    40/53

    Summary of Operations

    - TABLE ACCESS FULL- TABLE ACCESS BY INDEX ROWID- INDEX UNIQUE SCAN

    - INDEX RANGE SCAN- NESTED LOOPS- NESTED LOOPS OUTER - HASH JOIN- MERGE JOIN

    - FILTER - VIEW- REMOTE- SORT ORDER BY- SORT GROUP BY

    - SORT JOIN

    We have not covered all of the execution plan operations, but we have coveredthe most common ones:

  • 8/3/2019 Use Explain Plan

    41/53

    Elements of a TKPROF Report

    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)

  • 8/3/2019 Use Explain Plan

    42/53

    Elements of a TKPROF Report

    (continued )Report Summary

    OCI call statistics totals Counts of how many statements were found in the trace file,how many were distinct, and how many were explained inthe report.

  • 8/3/2019 Use Explain Plan

    43/53

    Sample TKPROF Report Heading

    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.trcSort options: default************************************************************************count = number of times OCI procedure was executedcpu = cpu time in seconds executingelapsed = elapsed time in seconds executing

    disk = number of physical reads of buffers from diskquery = number of buffers gotten for consistent readcurrent = number of buffers gotten in current mode (usually for update)rows = number of rows processed by the fetch or execute call

  • 8/3/2019 Use Explain Plan

    44/53

    Sample OCI Call Statistics

    SELECT table_nameFROM user_tablesORDER BY table_name

    call count cpu elapsed disk query current rows------- ------ -------- ---------- --------- --------- --------- ---------Parse 1 0.01 0.02 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 14 0.59 0.99 0 33633 0 194------- ------ -------- ---------- --------- --------- --------- ---------total 16 0.60 1.01 0 33633 0 194

    Misses in library cache during parse: 1Optimizer goal: CHOOSEParsing user id: RSCHRAG [recursive depth: 0]

  • 8/3/2019 Use Explain Plan

    45/53

    What the TKPROF Sample on the

    Previous Slide Tells UsThe application called on Oracle to parse this statement oncewhile SQL trace was enabled.The parse took 0.01 CPU seconds, 0.02 seconds of elapsed time.

    No disk I/Os or buffer gets took place during the parse,suggesting that there were no misses in the dictionary cache.Oracle was called on to execute this statement once.The execution took under 0.01 CPU seconds.

    No disk I/Os or buffer gets took place during the execution.(Note that Oracle defers the work on queries to the fetch phase.)Oracle was called on 14 times to perform a fetch, and a total of 194 rows were returned. This implies that the application usedan array interface to fetch multiple rows at once.

  • 8/3/2019 Use Explain Plan

    46/53

    What More the TKPROF Sample on

    the Previous Slide Tells UsFetching took 0.59 CPU seconds, 0.99 elapsed seconds.Fetching required 33,633 buffer gets in consistent mode, but no

    physical reads were required.

    The statement was not in the library cache (shared pool) whenthe parse call came in.The cost-based optimizer and a goal of choose were used to

    parse the statement.

    The RSCHRAG user was connected to the database when the parse occurred.This statement was executed directly by the application; it wasnot invoked recursively by the SYS user or a database trigger.

  • 8/3/2019 Use Explain Plan

    47/53

    Sample Row Source Operation

    ListingRows Row Source Operation------- ---------------------------------------------------

    194 SORT ORDER BY194 NESTED LOOPS195 NESTED LOOPS OUTER195 NESTED LOOPS OUTER195 NESTED LOOPS

    11146 TABLE ACCESS BY INDEX ROWID OBJ$11146 INDEX RANGE SCAN (object id 34)11339 TABLE ACCESS CLUSTER TAB$

    12665 INDEX UNIQUE SCAN (object id 3)33 INDEX UNIQUE SCAN (object id 33)

    193 TABLE ACCESS CLUSTER SEG$387 INDEX UNIQUE SCAN (object id 9)194 TABLE ACCESS CLUSTER TS$388 INDEX UNIQUE SCAN (object id 7)

  • 8/3/2019 Use Explain Plan

    48/53

    Sample Execution Plan Listing

    Rows Execution Plan------- ---------------------------------------------------

    0 SELECT STATEMENT GOAL: CHOOSE194 SORT (ORDER BY)194 NESTED LOOPS195 NESTED LOOPS (OUTER)195 NESTED LOOPS (OUTER)195 NESTED LOOPS

    11146 TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'11146 INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)11339 TABLE ACCESS (CLUSTER) OF 'TAB$'12665 INDEX (UNIQUE SCAN) OF 'I_OBJ#' (NON-UNIQUE)

    33 INDEX (UNIQUE SCAN) OF 'I_OBJ1' (UNIQUE)193 TABLE ACCESS (CLUSTER) OF 'SEG$'387 INDEX (UNIQUE SCAN) OF 'I_FILE#_BLOCK#' (NON-UNIQUE)194 TABLE ACCESS (CLUSTER) OF 'TS$'388 INDEX (UNIQUE SCAN) OF 'I_TS#' (NON-UNIQUE)

  • 8/3/2019 Use Explain Plan

    49/53

    Notes About TKPROF

    Execution Plan ListingsExecution plans are only included in TKPROFreports if the explain= parameter is specifiedwhen TKPROF is invokedTKPROF will create and drop its own plan tableif one does not already exist

    The row counts on each step are actualsnotestimates. This can be very helpful whentroubleshooting queries that perform poorly.

  • 8/3/2019 Use Explain Plan

    50/53

    TKPROF Reports: More Than Just

    Execution PlansListing of SQL statements and library cache missinformation helps you determine if applications areusing Oracles shared SQL facility effectively.Parse, execute, and fetch call counts help youdetermine if applications are using Oracle APIseffectively.

    CPU and I/O statistics help you zero in on resource-intensive SQL statements.Row counts on individual steps of the execution planshelp you rework inefficient execution plans.

  • 8/3/2019 Use Explain Plan

    51/53

    Wrapping Up

    Use EXPLAIN PLAN, the autotrace facility in SQL*Plus,or GUI tools to generate execution plans.Use TKPROF to format SQL trace files for humanreadability.Execution plans and TKPROF reports give the DBA andapplication developer a wealth of information that can beused to make applications efficient and perform well.The catch: you need to know how to interpret execution

    plans and TKPROF reports in order to get any benefit fromthem.

  • 8/3/2019 Use Explain Plan

    52/53

    ReferencesWhite paper with code samples that are legible:http://www.dbspecialists.com/4dbas/present.html

    Reference material on EXPLAIN PLAN and TKPROF:

    Oracle8i Designing and Tuning for Performancein the Oracle 8i documentation set

    A good book on Oracle performance tuning:Oracle Performance Tuning Tips & Techniques

    by Richard Niemiec, available from Oracle Press

    Download TOAD from Quest Software:http://www.toadsoft.com/downld.html

  • 8/3/2019 Use Explain Plan

    53/53

    Contact Information

    Roger [email protected]

    http://www.dbspecialists.com

    Database Specialists, Inc.388 Market Street, Suite 400

    San Francisco, CA 94111415-344-0500