Escolar Documentos
Profissional Documentos
Cultura Documentos
Todays Session
EXPLAIN PLAN overview
TKPROF overview
Why???
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. Download: www.dbspecialists.com/presentations
SELECT privileges on underlying tables of views, if the statement being explained involves views
<SQL statement>;
10
11
12
13
14
In another session:
SYS.dbms_system.set_sql_trace_in_session
(<SID>, <serial#>, TRUE)
19
21
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 List traced SQL statement in the output file in a specific order
22
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 34 (RSCHRAG)
23
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. 25
OPERATION OBJECT_NAME ------------------------------ -------------SELECT STATEMENT SORT ORDER BY TABLE ACCESS FULL CUSTOMERS
26
OPERATION -----------------------------SELECT STATEMENT NESTED LOOPS TABLE ACCESS BY INDEX ROWID INDEX RANGE SCAN TABLE ACCESS BY INDEX ROWID INDEX UNIQUE SCAN
Look up a key in a non-unique index, or an incomplete key in a unique index. Input: usually no subordinate operations. Output: zero or more ROWIDs from the index.
29
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. For each row Oracle reads from the first input, the operations that make up the second input are executed once and matching rows generate output. 30
33
CUSTOMERS INVOICES_VIEW
36
37
40
Same as the SORT GROUP BY operation, except that the input is sorted by the join column or columns in preparation for a join using the merge join algorithm.
41
Summary of Operations
We have not covered all of the execution plan operations, but we have covered some of 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
43
45
46
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: RSCHRAG [recursive depth: 0]
47
50
51
Wrapping Up
Use EXPLAIN PLAN, queries against v$sql_plan, the autotrace facility in SQL*Plus, or GUI tools to view 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. You also ought to know when to use EXPLAIN PLAN versus when to query v$sql_plan.
54
Resources
Download this slide show, the accompanying white paper, and many other useful presentations at:
www.dbspecialists.com/presentations
55
Contact Information
Roger Schrag
Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA 94111 Tel: 415/344-0500 Email: rschrag@dbspecialists.com Web: www.dbspecialists.com
56