Documente Academic
Documente Profesional
Documente Cultură
Roger Schrag Database Specialists, Inc. www.dbspecialists.com NoCOUG November 14, 2000
Todays Session
EXPLAIN PLAN overview TKPROF overview Why??? Reading execution plans Reading TKPROF reports
White Paper
Twenty one pages of details I can't possibly cover in a one hour presentation! Lots of sample code, execution plans, and TKPROF reports that you will see are probably not readable when I put them up on PowerPoint slidesbut they are readable in the white paper. Available at: www.dbspecialists.com/4dbas/present.html
6 7
5 1
In another session:
SYS.dbms_system.set_sql_trace_in_session (<SID>, <serial#>, TRUE)
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 Omit recursive SQL performed by the SYS user Generate SQL script to insert statistical data into a database table Generate a separate file listing all SQL statements traced List traced SQL statement in the output file in a specific order
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 34 (RSCHRAG)
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 involve recursively finding steps that provide input and evaluating them.
OPERATION OBJECT_NAME ------------------------------ -------------SELECT STATEMENT SORT ORDER BY TABLE ACCESS FULL CUSTOMERS
OPERATION -----------------------------SELECT STATEMENT NESTED LOOPS TABLE ACCESS BY INDEX ROWID INDEX RANGE SCAN TABLE ACCESS BY INDEX ROWID INDEX UNIQUE SCAN
CUSTOMERS INVOICES_VIEW
Summary of Operations
We have not covered all of the execution plan operations, but we have covered the most common ones:
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
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
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: RSCHRAG [recursive depth: 0]
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 human readability. Execution plans and TKPROF reports give the DBA and application developer a wealth of information that can be used 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 from them.
References
White paper with code samples that are legible:
http://www.dbspecialists.com/4dbas/present.html
Contact Information
Roger Schrag rschrag@dbspecialists.com http://www.dbspecialists.com Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA 94111 415-344-0500