You are on page 1of 12

Using TKPROF and Explain Plan with Oracle -- Contents

Oracle TRACE Utility


Simple Steps for TRACE with a Simple Query
The Sections of a TRACE Output
o The SQL Statement
o The Statistics Section
o Information Section
o The EXPLAI PLA
A !ore Comple" T#PRO$ Output
Usin% EXPLAI PLA Alone
o An A&&itional EXPLAI PLA E"ample for a Simple Query
EXPLAI PLA''Rea& It Top to (ottom or (ottom to Top)
Rea&in% the EXPLAI PLA
Settin% AUTOTRACE On
Oracle TRACE Utility
The Oracle TRACE utility is use& to measure timin% statistics for a %i*en +uery, a -atch process,
or an entire system. It is a fast metho& of fin&in% where potential -ottlenec/s on the system
resi&e. TRACE has the followin% functionality0
TRACE runs the +uery an& %enerates statistics a-out an Oracle +uery that is e"ecute&.
TRACE helps &e*elopers analy1e e*ery section of a +uery.
Simple Steps or TRACE with a Simple !"ery
The steps for settin% up an& runnin% Oracle2s TRACE utility are as follows0
3. Set the followin% init.ora parameters0
2. TIMED.STATISTICS = TRUE
3. MAX_DUMP_FILE_SIZE = 2000000 (Not 2M)
4. USER_DUMP_DEST = /ora!"#/r$%_tr

In Oracle4, the &ata-ase must -e shut &own an& restarte& for these parameters to ta/e
effect. In Oracle5, the TI!E67STATISTICS parameter may -e set *ia an ALTER
SESSIO 8for an in&i*i&ual session9 or ALTER S:STE! 8for the entire system9
comman&. The USER76U!P76EST specifies the location to put the files an& the
!AX76U!P7$ILE7SI;E specifies the ma"imum file si1e.
<. Ena-le TRACE for a SQL=Plus session 8this starts TRACin% for an in&i*i&ual session90
&. a!t"r '"''$o( '"t S)L_TRACE tr*"+

4. Run the +uery to -e TRACE&0
#. '"!"t ta,!"_(a-".
/. o0("r.
10. $($t$a!_"2t"(t.
11. *($3*"("''
12. 4ro- $(52
13. 0%"r" o0("r 66 77 = 7SC8TT7+
14. 99 (Not": A( $(5"2 o( ;8<NER; $' '*==r"''"5)

3<. 6isa-le TRACE for the SQL=Plus session0
1&. a!t"r '"''$o( '"t S)L_TRACE 4a!'"+

34. :ou can also ena-le TRACE for all sessions -y settin% the SQLTRACE parameter in the
init.ora. :ou must shut &own an& restart the &ata-ase for this to ta/e effect. This is not
su%%este&>
1#. S)L_TRACE = TRUE

After runnin% TRACE, your output file will loo/ somethin% li/e the followin%0
>_1/>>4.tr

T#P Setting TIMED_STATISTICS=TRUE in the init.ora will begin TRACing upon the
user's coan!. "ut# $e care"l? setting S$%TRACE=TRUE in the init.ora will cause
the entire s&ste an! all 'ueries to be TRACE! an! coul! cause per(orance
!egra!ations.
3@. Run T#PRO$ to put the TRACE file into rea&a-le format0
20. t?=ro4 >_1/>>4.tr r$%2.=r4 "2=!a$(='@'t"-/-a(aA"r

The T#PRO$ utility translates the TRACE file %enerate& -y the SQLTRACE facility to a
rea&a-le format. :ou can run T#PRO$ a%ainst a TRACE file that you ha*e pre*iously
create&, or you can run it while the pro%ram that is creatin% the TRACE file is still
runnin%. Options for T#PRO$ are liste& ne"t.
t?=ro4 tra"4$!" o*t=*t_4$!" B'ort = =ara-"t"r'C
B=r$(t =(*-,"rC B"2=!a$(=*'"r(a-"/=a''0or5D'$5C

Command-%ine Options&
TRACEfile
The name of the TRACE file containin% the statistics -y SQL7TRACE.
output7file
The name of the file where T#PRO$ writes its output.
SORTA parameters
The or&er in which to &isplay the statements in the output. There are a-out BC &ifferent
options for sortin% the output'you can e*en com-ine these options.
PRITAnum-er
The num-er of statements to inclu&e in the output. inclu&e&, T#PRO$ will list all
statements in the output.
EXPLAIAusernameDpasswor&Esi&
Run the EXPLAI PLA on the user2s SQL statements in the TRACE file. This option
will create a PLA7TA(LE of its own, so the user will nee& to ha*e pri*ile%es to create
the ta-le an& space in which to create it. Fhen T#PRO$ is finishe&, this ta-le is &roppe&.
'ew options in ()*+&
ISERTA filename
This option creates a script to create a ta-le an& store the TRACE file statistics for each
SQL statement TRACE&.
RECOR6A filename
This option will pro&uce a file of all the user2s SQL statements.
S:SA :ESDO
This option allows the user to re+uest the recursi*e SQL statements not -e &isplaye& in
the output. The &efault is set to :ES.
SORTA parameters
There is a tremen&ous num-er of sortin% options that are a*aila-le. !y fa*orites are
$CGCPU 8CPU time of fetch9, $CG6S# 8&is/ rea&s for fetch9, $CGCU an& $CGQR:
8memory rea&s for fetch9, $CG ROF 8num-er of rows fetche&9, EXE6S# 8&is/ rea&s
&urin% e"ecute9, EXECU an& EXEQR: 8memory rea&s &urin% e"ecute9, EXEROF
8rows processe& &urin% e"ecute9, EXECPU 8e"ecute CPU time9, an& PRSCT 8times
parse&9.
T#P
The T)*R+, utilit& puts a TRACE! output into a rea!able (orat. -ithout running
T)*R+,# it woul! be !i((icult to rea! the output o( a TRACE. "& speci(&ing
.e/plain=usernae0passwor!. 1note! earlier2# we are able to get the E3*%AI4 *%A4
e/ecution path in a!!ition to the e/ecution statistics o( the 'uer&.
B3. The output of the file richB.prf 8+uery with the in&e" suppresse&90
'"!"t ta,!"_(a-".
o0("r.
$($t$a!_"2t"(t.
*($3*"("''
4ro- $(52
0%"r" o0("r = 7SC8TT7+
o*(t =* "!a= 5$'? 3*"r@ *rr"(t ro0'
Par'": 1 1 2 0 0 0
E2"*t": 1 0 0 0 0 2 0
F"t%: 2 &/ 113 142 430 0 3&

Exec"tion Plan ,no index "sed-&
TAELE ACCESS (FULL) 8F 7IND27

The output shows 3HB &is/ rea&s an& HIC memory rea&s 8+uery J current9. Ga*in% such a
hi%h num-er of &is/ rea&s compare& to physical rea&s is certainly a potential pro-lem.
The e"ecution path shows a full ta-le scan confirmin% that we may ha*e a potential
pro-lem.
T#P A TRACE! 'uer& with a large nuber o( ph&sical rea!s usuall& in!icates a issing
in!e/. The !is5 colun in!icates the ph&sical rea!s 1usuall& where an in!e/ is not use!2
an! the 'uer& a!!e! to the current coluns in!icates the eor& rea!s 1usuall& rea!s
where an in!e/ is being use!2.
BB. Gere2s what happens when I rerun the +uery 8after restartin% the system9 to -e TRACE&,
now usin% an in&e" on the owner ta-le0
23. '"!"t ta,!"_(a-".
24. o0("r.
2>. $($t$a!_"2t"(t.
2&. *($3*"("''
2F. 4ro- $(52
2#. 0%"r" o0("r = 7SC8TT7+
2/. (T%" $(5"2 o( ;8<NER; $' (ot '*==r"''"5)
30.
31. o*(t =* "!a= 5$'? 3*"r@ *rr"(t ro0'
32.
33. Par'": 2 0 0 0 0 0
34. E2"*t": 2 0 0 0 0 0 0
3>. F"t%: 4 & & 0 14# 0 F2

Exec"tion Plan ,index "sed-&
TAELE ACCESS (EG R8<ID) 8F 7IND27
INDEX (RANHE SCAN) 8F 7IND2_17 (N8N9UNI)UE)

T#P
A TRACE! 'uer& output with onl& eor& rea!s 1'uer&6consistent rea!s2 in!icates that
an in!e/ is being use!.
The Sections o a TRACE O"tp"t
The TRACE utility has multiple sections inclu&in% the SQL statements, statistics, information,
an& the EXPLAI PLA. Each of these &ifferent topics are &iscusse& in the followin% sections.
The S!% Statement
The first section of a T#PRO$ statement is the SQL statement. This statement will -e the e"act
same as the statement that was e"ecute&. If there were any hints or comments in the statement,
they woul& -e retaine& in this output. This can -e helpful when you are re*iewin% the output
from multiple sessions. If you fin& a statement causin% pro-lems, you woul& -e a-le to search for
the e"act statement. Remem-er, some of the statements from Oracle forms are %enerate&
&ynamically.
The Statistics Section
This section contains all the statistics for this SQL statement an& all the recursi*e SQL
statements %enerate& to satisfy this statement. In this section there are ei%ht columns, the first
-ein% the type of call to the &ata-ase. There are three types of calls, parse, e"ecute, an& fetch.
Each type of call will %enerate a separate line of statistics. The other se*en columns are the
statistics for each type of call.
count
The num-er of times this type of call was ma&e.
cpu
The total CPU time for all of the calls of this type for this statement. If the
TI!E67STATISTICS parameter in the init.ora is not set to TRUE, this statistic an& the
elapse& statistic will -e C.
elapse&
The total elapse& time for this call.
&is/
The total num-er of &ata -loc/s retrie*e& from &is/ to satisfy this call.
+uery
The total num-er of &ata -uffers retrie*e& from memory for this type SELECT
statements usually retrie*e -uffers in this mo&e.
current
The total num-er of &ata -uffers retrie*e& from memory for this type of call. UP6ATE,
ISERT, or 6ELETE the usual access -uffers in this mo&e.
rows
The total num-er of rows processe& -y this statement. The rows statements will appear in
the row of $etch statistics. ISERTS, UP6ATES, an& 6ELETES will appear in the
e"ecute row.
#normation Section
This section contains information a-out the num-er of misses in the li-rary cache from parse an&
e"ecute calls. If the num-er of misses is hi%h, there may -e a pro-lem with the si1e of the Share&
Pool. :ou shoul& chec/ the hit ratio an& the reloa& rate of the li-rary cache. There is also
information a-out the current optimi1er mo&e settin%. This section shows the username of the
last user to parse this statement.
The E.P%A#' P%A'
This is the section of the T#PRO$ I fin& to -e the most useful. The first column of this section
of the TRPRO$ output listin% -elow, is the num-er of rows processe& -y each line of the
e"ecution plan. Gere, you will -e a-le to see how -a& a statement is. If the total num-er of rows
in the $etch statistics is low compare& to the num-er of rows -ein% processe& -y each line of the
EXPLAI PLA, you may want to re*iew the statement.
It is also possi-le that there is only one line of the e"ecution plan that is processin% a lar%e
num-er of rows compare& to the rest of the statement. This can -e cause& -y full ta-le scans or
the use of a -a& in&e".
A /ore Complex TKPROF O"tp"t
The followin% e"ample illustrates a TRACE& +uery with a sli%htly hi%her comple"ity.
'"!"t It"-_It"-_I5. I($tCa=( It"-_D"'r$=t$o( )
4ro- It"-
0%"r" It"-_C!a''$4$at$o( = 1
a(5 It"-_It"-_I5 E"t0""( 1000000 A(5 2F00000
a(5 It"-_It"-_I5 Not I( ( S"!"t I(I$t"-_It"-_I5
4ro- I(I"(tor@_It"-
0%"r" I(I$t"-_Loat$o(_I5 = 740>7)
a!! o*(t =* "!a='"5 5$'? 3*"r@ *rr"(t ro0'
Par'" 1 0.00 0.00 0 0 0 0
E2"*t" 1 0.00 0.00 0 0 0 0
F"t% 2F 20.#F 21.24 0 440# 0 3//
Tota!' 2/ 20.#F 21.24 0 440# 0 3//
M$''"' $( !$,rar@ a%" 5*r$(A =ar'": 0
8=t$-$J"r %$(t: CK88SE
Par'$(A *'"r $5: 10& (C124&2)
Ro0' E2"*t$o( P!a(
0 SELECT STATEMENT 8PTIMIZER KINT: CK88SE
>F2 FILTER
>/# TAELE ACCESS (EG R8<ID) 8F 7ITEM7
>// INDEX (RANHE SCAN) 8F 7ITEM_PL7 (UNI)UE)
2F#F/0 INDEX (RANHE SCAN) 8F 7INMITEM_PL7 (UNI)UE)
Some of the thin%s to loo/ for in the T#PRO$ output are liste& in this ta-le0
Pro$lems Sol"tions
Gi%h num-ers for the parsin% The SGARE67POOL7SI;E may nee& to -e increase&.
The &is/ rea&s are *ery hi%h In&e"es are not use& or may not e"ist.
The K+ueryK an&Dor KcurrentK
8memory rea&s9 are *ery hi%h
In&e"es may -e on columns with hi%h car&inality 8columns
where an in&i*i&ual *alue %enerally ma/es up a lar%e percenta%e
of the ta-le9. Remo*in% or suppressin% the in&e" may increase
performance.
The parse elapse time is hi%h There may -e a pro-lem with the num-er of open cursors.
The num-er of rows processe&
-y a row in the EXPLAI
PLA is hi%h compare& to the
other rows
This coul& -e a si%n of an in&e" with a poor &istri-ution &istinct
/eys 8uni+ue *alues for a column9. Or this coul& also -e a si%n of
a poorly written statement.
If the num-er of misses in the
li-rary cache &urin% parse is
%reater than 3
This is an in&ication that the statement ha& to -e reloa&e&. :ou
may nee& to increase the SGARE67POOL7SI;E in the init.ora.
Using E.P%A#' P%A' Alone
The EXPLAI PLA comman& allows a &e*eloper to *iew the +uery e"ecution plan that the
Oracle optimi1er will use to e"ecute a SQL statement. This comman& is *ery helpful in
impro*in% performance of SQL statements, since it &oes not actually e"ecute the SQL
statement''it only outlines the plan to use an& inserts this e"ecution plan in an Oracle ta-le. Prior
to usin% the EXPLAI PLA comman&, a file calle& UTLXPLA.s+l 8locate& in the same
&irectory as CATALOL.s+l9 must -e e"ecute& un&er the Oracle account that will -e e"ecutin%
the EXPLAI PLA comman&. The script creates a ta-le calle& PLA7TA(LE that is use& -y
the EXPLAI PLA comman& to insert the +uery e"ecution plan in the form of recor&s. This
ta-le can then -e +uerie& an& *iewe& to &etermine if there nee&s to -e any mo&ifications to the
SQL statement to force a &ifferent e"ecution plan. An EXPLAI PLA e"ample is shown ne"t
8e"ecute& in SQL=Plus9.
!) Fhy use EXPLAI PLA without TRACE)
A) The statement is not e"ecute&? it only shows what will happen if the statement is e"ecute&.
!) Fhen &o you use EXPLAI PLA without TRACE)
A) Fhen the +uery will ta/e e"ceptionally lon% to run.
The followin% &ia%ram &emonstrates the proce&ures for runnin% TRACE *ersus EXPLAI
PLA0
TRACE
It ta/es four hours to TRACE a +uery that ta/es
four hours to run.
Set up Init.ora Parameters
Create PLA7TA(LE ta-le
Run Query
Statement is e"ecute& PLA7TA(LE is
populate&
Run T#PRO$
Output shows &is/ an& memory rea&s in
a&&ition to EXPLAI PLA output
EXPLAI PLA
It ta/es less than a inute to EXPLAI PLA a
+uery that ta/es four hours to run.
Create PLA7TA(LE ta-le
E"plain Query
PLA7TA(LE is populate&
Query PLA7TA(LE
Output shows EXPLAI PLA
!)
Gow &o I use EXPLAI PLA -y itself
A)
3. $in& the script? it is usually in the ORACLE7GO!EDr&-msDa&min0
;*t!2=!a(.'3!;
B. E"ecute the script XPLAIPL.s+l in SQL=Plus0
3. D*t!2=!a(

This creates the PLA7TA(LE for the user e"ecutin% the script. :ou may create
your own PLA7TA(LE, -ut use OracleKs synta" or else>>>
H. Run EXPLAI PLA for the +uery to -e optimi1e&0
>. "2=!a$( =!a( 4or
&. '"!"t CUST8MER_NUMEER
F. 4ro- CUST8MER
#. 0%"r" CUST8MER_NUMEER = 111+
/.
10. E2=!a$("5.

33. EXPLAI PLA for the +uery to -e optimi1e& 8usin% a ta% for the statement90
12. "2=!a$( =!a(
13. '"t 'tat"-"(t_$5 = 7CUST8MER7 4or
14. '"!"t CUST8MER_NUMEER
1>. 4ro- CUST8MER
1&. 0%"r" CUST8MER_NUMEER = 111+
T#P Use the SET STATEME4T_ID = .&our i!enti(ier. when the *%A4_TA"%E
will be populate! b& an& !i((erent !e7elopers. I rarel& use the SET
STATEME4T_ID stateent. Instea!# I E3*%AI4 *%A4 a 'uer&# loo5 at the
output# an! then !elete (ro the *%A4_TA"%E table. I continue to !o this
1a5ing changes to the 'uer&2# until I see an e/ecution plan that I thin5 will be
(a7orable. I then run the 'uer& to see i( the per(orance has been ipro7e!. I(
ultiple !e7elopers0D"As are using the sae *%A4_TA"%E# then the SET
STATEME4T_ID will be essential to i!enti(&ing a stateent.
34. Select the output from the PLA7TA(LE ta-le0
1#. '"!"t o="rat$o(.
1/. o=t$o('.
20. o,N"t_(a-".
21. $5.
22. =ar"(t_$5
23. 4ro- =!a(_ta,!"
24. 0%"r" 'tat"-"(t_$5 = 7CUST8MER7+
2>.
2&. 8="rat$o( 8=t$o(' 8,N"t Na-" ID
Par"(t
2F. '"!"t 'tat"-"(t 0
2#. Ta,!" A"'' E@ R8<ID C*'to-"r 1
2/. I(5"2 Ra(A" Sa( CUST_IDX 2
1

T#P Use E3*%AI4 *%A4 instea! o( TRACE so that &ou !on't ha7e to wait (or the
'uer& to run. E3*%AI4 *%A4 will show the path o( a 'uer& without actuall&
running the 'uer&. Use TRACE onl& (or ulti6'uer& batch 8obs to (in! out which
o( the an& 'ueries in the batch 8ob are slow.
An Additional E.P%A#' P%A' Example or a Simple !"ery
3. Run the +uery with the EXPLAI synta" em-e&&e& prior to the +uery0
2. "2=!a$( =!a(
3. '"t 'tat"-"(t_$5 =73*"r@ 17 4or
4. '"!"t *'to-"r_(*-,"r.
>. (a-"
&. *'to-"r
F. 4ro- *'to-"r
#. 0%"r" *'to-"r_(*-,"r = 71117+

@. Retrie*e the output of EXPLAI PLA -y +ueryin% the PLA7TA(LE0
To retrie*e the information for *iewin%, a SQL statement must -e e"ecute&. Two scripts
pro*i&e& in the Oracle &ocumentation are &isplaye& in this step an& in step I, alon% with
the results of each -ase& on the pre*ious EXPLAI PLA comman&. ote that this
e"ample *aries from the last e"ample. The customer7num-er column is an in&e"e&
num-er fiel&, which in the secon& e"ample is suppresse& 8-y forcin% a to7char9 -ecause
of a &ata type mismatch 823332 is in +uotes9. In the first e"ample, I treate& the
customer7num-er column correctly as a num-er fiel& 8333 is not in +uotes9.
'"!"t o="rat$o(.
o=t$o('.
o,N"t_(a-".
$5.
=ar"(t_$5.
=o'$t$o(
4ro- =!a(_ta,!"
0%"r" 'tat"-"(t_$5 = 73*"r@ 17
or5"r ,@ $5+
8="rat$o( 8=t$o(' 8,N"t Na-" ID Par"(t
'"!"t 'tat"-"(t 0
Ta,!" A"'' F*!! C*'to-"r_I(4or-at$o( 1

3C. Retrie*in% a more intuiti*e an& easy to rea& output of EXPLAI PLA0
11. '"!"t !=a5(7 7. 2O(!"I"!91)) 66 o="rat$o( 66 7 7 66 o=t$o(' 66 7 7
66
12. o,N"t_(a-" 66 7 7 66 5"o5"($5. 0. 7Co't = 7 66 =o'$t$o()
7)*"r@ P!a(7
13. 4ro- =!a(_ta,!"
14. 'tart 0$t% $5 = 0
1>. a(5 'tat"-"(t_$5 = 73*"r@ 17
1&. o(("t ,@ =r$or $5 = =ar"(t_$5
1F. a(5 'tat"-"(t_$5 = 73*"r@ 17+

O"tp"t&
)*"r@ P!a(
'"!"t 'tat"-"(t Co't=220
Ta,!" A"'' F*!! C*'to-"r

E.P%A#' P%A'--Read #t Top to 0ottom or 0ottom to Top1
Actually, it &epen&s on how you write the +uery that retrie*es the information from the
PLA7TA(LE ta-le. That is pro-a-ly why many people &iffer on which way to rea& the result
8all of them may -e correct9. e"t, I %i*e an e"ample with the or&er of e"ecution -ase& on the
+uery that retrie*es the information. In this e"ample, the output is rea& top to -ottom with one
ca*eat...you must rea& from the innermost to the outermost. The e"ample here shows a metho&
that shoul& clear up any +uestions.
The SQL statement shoul& -e place& after the $OR clause of the EXPLAI PLA0
5"!"t" 4ro- =!a(_ta,!"+
"2=!a$( =!a(
'"t 'tat"-"(t_$5 = 7S)L17 4or
'"!"t to_%ar('@'5at". 7MM/DD/GG KK:MM AM7).
to_%ar((tr*((('@'5at" 94. 91). 75a@7) P1). 7DD9M8N9GG7).
4ro- ,?. ""
0%"r" ,?_'%$4t_5at" Q= to_%ar((tr*((( '@'5at" 9 4 9 1). 75a@7 P 1).
7DD9M8N9GG7)
a(5 ,?_'%$4t_5at" R= to_%ar(('@'5at" 9 4). 7DD9M8N9GG7)
a(5 ,?_"-=(o = ""_"-=(o (P)
a(5 '*,'tr( ""_%$"rar%@_o5". 1. 3) $( (7PNA7. 7PNE7. 7PNC7.
7PND7. 7PNE7. 7PNF7)
or5"r ,@ ""_No,_Aro*=.
,?_"-=(o.
,?_'%$4t_5at"
/
'"!"t LPa5(7 7. 2O(L"I"!91)) 66 L"I"! 66 7.7 66 (I!(Po'$t$o(.0) 66
7 7 66 8="rat$o( 66 7 7 66 8=t$o(' 66 7 7 66 8,N"t_Na-" 66
7 7 66 8,N"t_T@=" 66 7 7 66 D"o5"($5. 0. Stat"-"(t_$5 66
7Co't = 7 66 Po'$t$o() 66 8t%"r 66 7 7 66
8,N"t_No5" ;)*"r@ P!a(;
4ro- =!a(_ta,!"
'tart 0$t% $5 = 0
a(5 'tat"-"(t_$5 = 7S)L17
o(("t ,@ =r$or $5 = =ar"(t_$5
a(5 'tat"-"(t_$5 = 7S)L17
/
)*"r@ P!a(
1.0 SELECT STATEMENT S)L1 Co't =
2.1 S8RT 8RDER EG
3.1 FILTER
4.1 NESTED L88PS 8UTER
>.1 TAELE ACCESS EG R8<ID EL
&.1 INDEX RANHE SCAN I_EL_0& N8N9UNI)UE
>.2 TAELE ACCESS EG R8<ID EE
&.1 INDEX UNI)UE SCAN I_EE_01 UNI)UE
Reading the E.P%A#' P%A'
Usin% the pre*ious EXPLAI PLA, I will e"plain the steps -elow. A locate& in the left column
in the followin% ta-le i&entifies each step. or&er in which they were e"ecute&.
Step Action
M.3
This is the in&e" ran%e scan of I7(#7CM. This is the first step. This in&e" is on the
-/7shift7&t column. This step performs a scan of this in&e" to pro&uce a list of ROFI6s
that fall -etween the two &ates.
<.3 Retrie*e the rows from the (# ta-le.
M.3
Scan of the I7EE7C3 in&e". This in&e" is on the ee7empno column. Usin% the -/7empno
retrie*e& from the pre*ious step, this in&e" is scanne& to retrie*e the ROFI6s to pro&uce a
list of the ee7empnos that match the -/7empnos.
<.B Retrie*e the rows from the EE ta-le.
H.3 ESTE6 LOOP. The two lists are Noine&, pro&ucin% one list.
I.3 $ILTER. The rest of the con&itions of the FGERE clause are applie&.
B.3 SORT OR6ER (:. The remainin% rows are sorte& accor&in% to the OR6ER (: clause.
3.C This tells what type of statement it is.
T#P -hether the E3*%AI4 *%A4 is rea! (ro top to botto or (ro the botto to the top is
!epen!ent entirel& on the 'uer& use! to select in(oration (ro the *%A4_TA"%E table. "oth
etho!s o( rea!ing the 'uer& a& be correct# gi7en the 'uer& selecting the in(oration is
correctl& structure!.
Setting AUTOTRACE On
There is also an easier metho& with SQL=Plus for %eneratin% an EXPLAI PLA an& statistics
a-out the performance of a +uery. The AUTOTRACE comman& 8a*aila-le in SQL=Plus I.I an&
later9 %enerates similar information, as shown in this e"ample0
SET AUT8TRACE 8N
'"!"t o*(t((a-")
4ro- "-=F
0%"r" (a-" = 7,ra(%"'7+
O"tp"t
C8UNT(NAME)
100
)*"r@ P!a(
0 SELECT STATEMENT 8=t$-$J"r=CK88SE
1 0 S8RT (AHHREDATE)
2 1 INDEX (RANHE SCAN) 8F 7EMPF_I17 (N8N9UNI)UE)
Stat$'t$'
0 r"*r'$I" a!!'
0 5, ,!o? A"t'
1 o('$'t"(t A"t'
1 =%@'$a! r"a5'
0 r"5o '$J"
223 ,@t"' '"(t I$a S)LON"t to !$"(t
2F4 ,@t"' r"5 I$a S)LON"t 4ro- !$"(t
2 S)LON"t ro*(5tr$=' to/4ro- !$"(t
1 'ort' (-"-or@)
0 'ort' (5$'?)
1 ro0' =ro"''"5
T#P The AUT+TRACE option pro7i!es an E3*%AI4 *%A4 an! statistics (or a 'uer&. The
AUT+TRACE pro7i!es an& o( the TRACE an! T)*R+, statistics such as !is5 rea!s 1ph&sical
rea!s2 an! eor& rea!s 1consistent rea!s 9 !b bloc5 gets2.

You might also like