Query tuning using TKprof

Hi all,
I have one procedure which takes normally more time to finish, cpu is normal at that time still the procedure takes more time. TKPROF has been generated and find the output below. As i am new with tkprof, what are the points need to noted and with the tkprof how we can impove the response of the query.
TKPROF: Release 10.2.0.1.0 - Production on Tue Jan 8 17:03:09 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: odsprod_ora_27486.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
SELECT B.CITY_CODE||'-'||B.STORE_NO||'-'||B.STORE_SHORT_NAME CITY_STORE,
RPAD(K1.TDATE,14,' ') TDATE, RPAD(K1.TAMT,14,' ') TAMT, RPAD(K1.NTKT ,9,' ')
NTKT, K1.POS POS
FROM
( SELECT SUBSTR(STORE_NO,3,6) STNO, TRANS_DATE TDATE, TICKET_AMOUNT TAMT,
TICKET_NO NTKT, POS_NO POS FROM DEVDBA.S_RET_TICKET_END_REJ WHERE
TRUNC(RECORD_DATE)=TRUNC(SYSDATE) AND TRAINING_MODE_FLAG=0 AND
VOID_TICKET_FLAG=0 AND (TICKET_AMOUNT>1000000 OR TICKET_AMOUNT<-1000000 ) )
K1,DEVDBA.S_SITE_MASTER B WHERE STNO=B.STORE_NO
call count cpu elapsed disk query current rows
Parse 1 0.02 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.39 2.51 4641 4648 0 0
total 3 0.41 2.52 4641 4648 0 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN) (recursive depth: 1)
Rows Row Source Operation
0 NESTED LOOPS (cr=4648 pr=4641 pw=0 time=2518383 us)
0 TABLE ACCESS FULL S_RET_TICKET_END_REJ (cr=4648 pr=4641 pw=0 time=2518377 us)
0 TABLE ACCESS BY INDEX ROWID S_SITE_MASTER (cr=0 pr=0 pw=0 time=0 us)
0 INDEX UNIQUE SCAN PK_SITE_NUM (cr=0 pr=0 pw=0 time=0 us)(object id 98999)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 NESTED LOOPS
0 TABLE ACCESS MODE: ANALYZED (FULL) OF 'S_RET_TICKET_END_REJ'
(TABLE)
0 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF
'S_SITE_MASTER' (TABLE)
0 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'PK_SITE_NUM' (INDEX
(UNIQUE))
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 3 0.02 0.04
db file scattered read 89 0.07 2.19
BEGIN PROC_RET_REPORT_TEST; END;
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 407.03 714.35 1306018 2069759 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 1 407.03 714.35 1306018 2069759 0 1
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
TCP Socket (KGAS) 43 0.11 0.12
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.20 0.20
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 3 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 3 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.03 0.03
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 2 407.03 714.35 1306018 2069762 0 2
Fetch 0 0.00 0.00 0 0 0 0
total 3 407.03 714.35 1306018 2069762 0 2
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file scattered read 7444 0.51 106.03
db file sequential read 9311 0.25 13.64
TCP Socket (KGAS) 43 0.11 0.12
SQL*Net message to client 4 0.00 0.00
SQL*Net message from client 4 201.99 202.27
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 22 0.05 0.04 0 0 0 0
Execute 30 0.03 0.02 0 0 0 0
Fetch 40 0.40 2.57 4646 4883 0 34
total 92 0.48 2.64 4646 4883 0 34
Misses in library cache during parse: 10
Misses in library cache during execute: 5
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file scattered read 89 0.07 2.19
db file sequential read 8 0.02 0.08
3 user SQL statements in session.
31 internal SQL statements in session.
34 SQL statements in session.
1 statement EXPLAINed in this session.
Trace file: odsprod_ora_27486.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
3 user SQL statements in trace file.
31 internal SQL statements in trace file.
34 SQL statements in trace file.
13 unique SQL statements in trace file.
1 SQL statements EXPLAINed using schema:
ORADMIN.prof$plan_table
Default table was used.
Table was created.
Table was dropped.
17240 lines in trace file.
2 elapsed seconds in trace file.
Sorry for the formatting,
Now i have enabled certain event generated trace files for the same procedure, please find the part of o/p below. Now what is the actual problem stating in the trace file.Now this trace file is very big. So only find the particular points
WAIT #23: nam='db file scattered read' ela= 15889 file#=8 block#=513995 blocks=62 obj#=102475 tim=5857651746404
WAIT #23: nam='db file sequential read' ela= 52 file#=12 block#=518683 blocks=1 obj#=102476 tim=5857651755104
ARSING IN CURSOR #25 len=69 dep=2 uid=0 oct=3 lid=0 tim=5857874309691 hv=1471956217 ad='2af8ea78'
select con#,obj#,rcon#,enabled,nvl(defer,0) from cdef$ where robj#=:1
END OF STMT
PARSE #25:c=10000,e=6668,p=0,cr=0,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874309683
EXEC #25:c=0,e=3780,p=0,cr=0,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874313677
FETCH #25:c=0,e=22,p=0,cr=1,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874313766
STAT #25 id=1 cnt=0 pid=0 pos=1 obj=31 op='TABLE ACCESS BY INDEX ROWID CDEF$ (cr=1 pr=0 pw=0 time=25 us)'
STAT #25 id=2 cnt=0 pid=1 pos=1 obj=52 op='INDEX RANGE SCAN I_CDEF3 (cr=1 pr=0 pw=0 time=18 us)'
=====================
PARSING IN CURSOR #25 len=146 dep=2 uid=0 oct=3 lid=0 tim=5857874316480 hv=2107929772 ad='2bedcd80'
select con#,type#,condlength,intcols,robj#,rcon#,match#,refact,nvl(enabled,0),rowid,cols,nvl(defer,0),mtime,nvl(spare1,0) from cdef$ where obj#=:1
END OF STMT
PARSE #25:c=0,e=2534,p=0,cr=0,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874316476
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874317518 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
PARSE #26:c=0,e=63,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874317514
EXEC #26:c=0,e=64,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874317818
WAIT #26: nam='db file sequential read' ela= 10371 file#=1 block#=1778 blocks=1 obj#=266662 tim=5857874328282
FETCH #26:c=0,e=10527,p=1,cr=4,cu=0,mis=0,r=1,dep=3,og=3,tim=5857874328383
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=4 pr=1 pw=0 time=10521 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=3 pr=0 pw=0 time=30 us)'
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874328696 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #26:c=0,e=31,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874328692
FETCH #26:c=0,e=26,p=0,cr=4,cu=0,mis=0,r=1,dep=3,og=3,tim=5857874328815
STAT #26 id=1 cnt=2 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=8 pr=1 pw=0 time=10545 us)'
STAT #26 id=2 cnt=2 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=6 pr=0 pw=0 time=44 us)'
=====================
PARSING IN CURSOR #26 len=121 dep=3 uid=0 oct=3 lid=0 tim=5857874332429 hv=3150898423 ad='2beb0588'
select /*+ rule */ bucket, endpoint, col#, epvalue from histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket
END OF STMT
PARSE #26:c=0,e=3475,p=0,cr=0,cu=0,mis=1,r=0,dep=3,og=3,tim=5857874332424
EXEC #26:c=0,e=2945,p=0,cr=0,cu=0,mis=1,r=0,dep=3,og=3,tim=5857874335562
WAIT #26: nam='db file sequential read' ela= 8681 file#=1 block#=1819 blocks=1 obj#=266662 tim=5857874344365
FETCH #26:c=0,e=9040,p=1,cr=3,cu=0,mis=0,r=10,dep=3,og=3,tim=5857874344669
STAT #26 id=1 cnt=10 pid=0 pos=1 obj=0 op='SORT ORDER BY (cr=3 pr=1 pw=0 time=8996 us)'
STAT #26 id=2 cnt=10 pid=1 pos=1 obj=253 op='TABLE ACCESS CLUSTER HISTGRM$ (cr=3 pr=1 pw=0 time=8896 us)'
STAT #26 id=3 cnt=1 pid=2 pos=1 obj=252 op='INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=23 us)'
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874345413 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #26:c=0,e=111,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874345408
FETCH #26:c=0,e=58,p=0,cr=4,cu=0,mis=0,r=1,dep=3,og=3,tim=5857874345580
STAT #26 id=1 cnt=3 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=12 pr=1 pw=0 time=10604 us)'
STAT #26 id=2 cnt=3 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=9 pr=0 pw=0 time=84 us)'
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874345898 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #26:c=0,e=26,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874345894
FETCH #26:c=0,e=16,p=0,cr=3,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874346046
STAT #26 id=1 cnt=3 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=15 pr=1 pw=0 time=10623 us)'
STAT #26 id=2 cnt=3 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=12 pr=0 pw=0 time=100 us)'
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874346370 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #26:c=0,e=26,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874346366
FETCH #26:c=0,e=27,p=0,cr=4,cu=0,mis=0,r=1,dep=3,og=3,tim=5857874346494
STAT #26 id=1 cnt=4 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=19 pr=1 pw=0 time=10645 us)'
STAT #26 id=2 cnt=4 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=15 pr=0 pw=0 time=113 us)'
=====================
PARSING IN CURSOR #26 len=210 dep=3 uid=0 oct=3 lid=0 tim=5857874346747 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #26:c=0,e=21,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874346744
FETCH #26:c=0,e=24,p=0,cr=4,cu=0,mis=0,r=1,dep=3,og=3,tim=5857874346859
STAT #26 id=1 cnt=5 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=23 pr=1 pw=0 time=10666 us)'
STAT #26 id=2 cnt=5 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=18 pr=0 pw=0 time=126 us)'
=====================
PARSING IN CURSOR #26 len=121 dep=3 uid=0 oct=3 lid=0 tim=5857874347077 hv=3150898423 ad='2beb0588'
select /*+ rule */ bucket, endpoint, col#, epvalue from histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket
END OF STMT
EXEC #26:c=0,e=50,p=0,cr=0,cu=0,mis=0,r=0,dep=3,og=3,tim=5857874347073
WAIT #26: nam='db file sequential read' ela= 10038 file#=1 block#=62670 blocks=1 obj#=266662 tim=5857874357272
FETCH #26:c=0,e=10206,p=1,cr=3,cu=0,mis=0,r=3,dep=3,og=3,tim=5857874357373
STAT #26 id=1 cnt=13 pid=0 pos=1 obj=0 op='SORT ORDER BY (cr=6 pr=2 pw=0 time=19206 us)'
STAT #26 id=2 cnt=13 pid=1 pos=1 obj=253 op='TABLE ACCESS CLUSTER HISTGRM$ (cr=6 pr=2 pw=0 time=19073 us)'
STAT #26 id=3 cnt=2 pid=2 pos=1 obj=252 op='INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=4 pr=0 pw=0 time=47 us)'
EXEC #25:c=20000,e=47991,p=3,cr=29,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874364704
FETCH #25:c=0,e=28,p=0,cr=2,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874364807
STAT #25 id=1 cnt=0 pid=0 pos=1 obj=31 op='TABLE ACCESS BY INDEX ROWID CDEF$ (cr=2 pr=0 pw=0 time=31 us)'
STAT #25 id=2 cnt=0 pid=1 pos=1 obj=51 op='INDEX RANGE SCAN I_CDEF2 (cr=2 pr=0 pw=0 time=26 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857874369296 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=10000,e=2920,p=0,cr=0,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874369291
EXEC #26:c=0,e=3231,p=0,cr=0,cu=0,mis=1,r=0,dep=2,og=4,tim=5857874372683
FETCH #26:c=0,e=177,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857874372914
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857874372967
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=189 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=167 us)'
=====================
PARSING IN CURSOR #25 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857874373282 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #25:c=0,e=44,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874373279
EXEC #25:c=0,e=29,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874373433
FETCH #25:c=0,e=100,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857874373569
FETCH #25:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857874373617
STAT #25 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=106 us)'
STAT #25 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=95 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857874373766 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874373763
EXEC #26:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857874373902
FETCH #26:c=0,e=92,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857874374030
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857874374078
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=96 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=87 us)'
=====================
PARSING IN CURSOR #24 len=496 dep=1 uid=86 oct=3 lid=86 tim=5857874377134 hv=2953360709 ad='f2a17790'
SELECT B.CITY_CODE||'-'||B.STORE_NO||'-'||B.STORE_SHORT_NAME CITY_STORE, RPAD(K1.TDATE,14,' ') TDATE, RPAD(K1.TAMT,14,' ') TAMT, RPAD(K1.NTKT ,9,' ')NTKT, K1.POS POS FROM ( SELECT SUBSTR(STORE_NO,3,6) STNO, TRANS_DATE TDATE, TICKET_AMOUNT TAMT, TICKET_NO NTKT, POS_NO POS FROM DEVDBA.S_RET_TICKET_END_REJ WHERE TRUNC(RECORD_DATE)=TRUNC(SYSDATE) AND TRAINING_MODE_FLAG=0 AND VOID_TICKET_FLAG=0 AND (TICKET_AMOUNT>1000000 OR TICKET_AMOUNT<-1000000 ) )K1,DEVDBA.S_SITE_MASTER B WHERE STNO=B.STORE_NO
END OF STMT
PARSE #24:c=60000,e=75793,p=3,cr=86,cu=0,mis=1,r=0,dep=1,og=1,tim=5857874377128
EXEC #24:c=0,e=53,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=5857874377294
WAIT #24: nam='db file sequential read' ela= 11063 file#=28 block#=502155 blocks=1 obj#=108859 tim=5857874388592
WAIT #24: nam='db file scattered read' ela= 12272 file#=28 block#=502156 blocks=5 obj#=108859 tim=5857874401123
FETCH #24:c=390000,e=2518389,p=4641,cr=4648,cu=0,mis=0,r=0,dep=1,og=1,tim=5857876895883
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876898889 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=45,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876898885
EXEC #26:c=0,e=108,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876899153
FETCH #26:c=0,e=186,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876899385
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876899435
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=201 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=171 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876899687 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=15,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876899683
EXEC #26:c=0,e=30,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876899829
FETCH #26:c=0,e=93,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876899958
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876900005
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=98 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=89 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876900141 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=14,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876900138
EXEC #26:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876900276
FETCH #26:c=0,e=92,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876900404
FETCH #26:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876900449
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=96 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=86 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876900794 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=14,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876900790
EXEC #26:c=0,e=25,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876900933
FETCH #26:c=0,e=96,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876901066
FETCH #26:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876901114
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=102 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=92 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876901304 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=14,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876901300
EXEC #26:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876901441
FETCH #26:c=0,e=93,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876901570
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876901617
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=99 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=88 us)'
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876901750 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=14,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876901747
EXEC #26:c=0,e=23,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876901885
FETCH #26:c=0,e=93,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876902013
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876902059
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=98 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=87 us)'
=====================
PARSING IN CURSOR #25 len=72 dep=1 uid=0 oct=3 lid=0 tim=5857876908751 hv=2397574443 ad='2c965cf0'
SELECT RTRIM(VALUE) FROM V$PARAMETER WHERE UPPER(NAME)='SMTP_OUT_SERVER'
END OF STMT
PARSE #25:c=10000,e=12247,p=0,cr=108,cu=0,mis=1,r=0,dep=1,og=1,tim=5857876908746
EXEC #25:c=0,e=50,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=5857876908896
=====================
PARSING IN CURSOR #26 len=79 dep=2 uid=0 oct=3 lid=0 tim=5857876909030 hv=1782622679 ad='29ccc320'
select min(bitmapped) from ts$ where dflmaxext =:1 and bitand(flags,1024) =1024
END OF STMT
PARSE #26:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876909026
EXEC #26:c=0,e=40,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=5857876909183
FETCH #26:c=0,e=113,p=0,cr=18,cu=0,mis=0,r=1,dep=2,og=4,tim=5857876909331
FETCH #26:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=0,tim=5857876909378
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=18 pr=0 pw=0 time=118 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=18 pr=0 pw=0 time=107 us)'
FETCH #25:c=10000,e=7851,p=0,cr=18,cu=0,mis=0,r=1,dep=1,og=1,tim=5857876916780
=====================
PARSING IN CURSOR #28 len=53 dep=3 uid=0 oct=3 lid=0 tim=5857876920266 hv=2195068792 ad='2af8a840'
select timestamp, flags from fixed_obj$ where obj#=:1
END OF STMT
PARSE #28:c=0,e=2515,p=0,cr=0,cu=0,mis=1,r=0,dep=3,og=4,tim=5857876920261
=====================
PARSING IN CURSOR #29 len=210 dep=4 uid=0 oct=3 lid=0 tim=5857876920858 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
PARSE #29:c=0,e=116,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876920853
EXEC #29:c=0,e=55,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876921133
FETCH #29:c=0,e=57,p=0,cr=4,cu=0,mis=0,r=1,dep=4,og=3,tim=5857876921228
STAT #29 id=1 cnt=1 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=4 pr=0 pw=0 time=56 us)'
STAT #29 id=2 cnt=1 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=3 pr=0 pw=0 time=38 us)'
=====================
PARSING IN CURSOR #29 len=210 dep=4 uid=0 oct=3 lid=0 tim=5857876921615 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #29:c=0,e=22,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876921611
FETCH #29:c=0,e=24,p=0,cr=4,cu=0,mis=0,r=1,dep=4,og=3,tim=5857876921728
STAT #29 id=1 cnt=2 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=8 pr=0 pw=0 time=77 us)'
STAT #29 id=2 cnt=2 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=6 pr=0 pw=0 time=52 us)'
=====================
PARSING IN CURSOR #29 len=210 dep=4 uid=0 oct=3 lid=0 tim=5857876921979 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #29:c=0,e=20,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876921975
FETCH #29:c=0,e=22,p=0,cr=4,cu=0,mis=0,r=1,dep=4,og=3,tim=5857876922089
STAT #29 id=1 cnt=3 pid=0 pos=1 obj=255 op='TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=12 pr=0 pw=0 time=95 us)'
STAT #29 id=2 cnt=3 pid=1 pos=1 obj=257 op='INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=9 pr=0 pw=0 time=65 us)'
=====================
PARSING IN CURSOR #29 len=121 dep=4 uid=0 oct=3 lid=0 tim=5857876922285 hv=3150898423 ad='2beb0588'
select /*+ rule */ bucket, endpoint, col#, epvalue from histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket
END OF STMT
PARSE #29:c=0,e=64,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876922282
EXEC #29:c=0,e=48,p=0,cr=0,cu=0,mis=0,r=0,dep=4,og=3,tim=5857876922479
WAIT #29: nam='db file sequential read' ela= 10352 file#=1 block#=126071 blocks=1 obj#=108859 tim=5857876932944
WAIT #29: nam='db file sequential read' ela= 6111 file#=1 block#=1844 blocks=1 obj#=108859 tim=5857876939152
FETCH #29:c=0,e=16726,p=2,cr=3,cu=0,mis=0,r=1,dep=4,og=3,tim=5857876939276
STAT #29 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT ORDER BY (cr=3 pr=2 pw=0 time=16738 us)'
STAT #29 id=2 cnt=1 pid=1 pos=1 obj=253 op='TABLE ACCESS CLUSTER HISTGRM$ (cr=3 pr=2 pw=0 time=16685 us)'
STAT #29 id=3 cnt=1 pid=2 pos=1 obj=252 op='INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=2 pr=1 pw=0 time=10473 us)'
EXEC #28:c=10000,e=21483,p=2,cr=15,cu=0,mis=1,r=0,dep=3,og=4,tim=5857876941861
FETCH #28:c=0,e=17,p=0,cr=2,cu=0,mis=0,r=0,dep=3,og=4,tim=5857876941920
STAT #28 id=1 cnt=0 pid=0 pos=1 obj=706 op='TABLE ACCESS BY INDEX ROWID FIXED_OBJ$ (cr=2 pr=0 pw=0 time=20 us)'
STAT #28 id=2 cnt=0 pid=1 pos=1 obj=707 op='INDEX UNIQUE SCAN I_FIXED_OBJ$_OBJ# (cr=2 pr=0 pw=0 time=16 us)'
=====================
PARSING IN CURSOR #29 len=37 dep=3 uid=0 oct=3 lid=0 tim=5857876944818 hv=1983168772 ad='db809f00'
select inst_id, banner from x$version
END OF STMT
PARSE #29:c=0,e=2672,p=0,cr=0,cu=0,mis=1,r=0,dep=3,og=4,tim=5857876944814
=====================
PARSING IN CURSOR #27 len=66 dep=2 uid=0 oct=3 lid=0 tim=5857876947353 hv=3446116166 ad='e5345238'
select BANNER from GV$VERSION where inst_id = USERENV('Instance')
END OF STMT
PARSE #27:c=10000,e=30018,p=2,cr=17,cu=0,mis=1,r=0,dep=2,og=4,tim=5857876947348
=====================
PARSING IN CURSOR #28 len=210 dep=2 uid=0 oct=3 lid=0 tim=5857876948195 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #28:c=0,e=34,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=3,tim=5857876948191
FETCH #28:c=0,e=28,p=0,cr=3,cu=0,mis=0,r=0,dep=2,og=3,tim=5857876948315
=====================
PARSING IN CURSOR #29 len=210 dep=2 uid=0 oct=3 lid=0 tim=5857876948528 hv=864012087 ad='2beb15a0'
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#, sample_size, minimum, maximum, distcnt, lowval, hival, density, col#, spare1, spare2, avgcln from hist_head$ where obj#=:1 and intcol#=:2
END OF STMT
EXEC #29:c=0,e=22,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=3,tim=5857876948525
FETCH #29:c=0,e=13,p=0,cr=3,cu=0,mis=0,r=0,dep=2,og=3,tim=5857876948630
=====================
PARSING IN CURSOR #26 len=102 dep=1 uid=0 oct=3 lid=0 tim=5857876951095 hv=2007878721 ad='2a7035f0'
SELECT 'Mailer by '|| SUBSTR(BANNER,1,INSTR(BANNER,' ')-1)|| ' UTL_MAIL' FROM V$VERSION WHERE ROWNUM<2
END OF STMT
PARSE #26:c=10000,e=34172,p=2,cr=23,cu=0,mis=1,r=0,dep=1,og=1,tim=5857876951090
EXEC #26:c=0,e=46,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=5857876951235
FETCH #26:c=0,e=31,p=0,cr=0,cu=0,mis=0,r=1,dep=1,og=1,tim=5857876951296
WAIT #4: nam='TCP Socket (KGAS)' ela= 1812 =2 =0 =0 obj#=108859 tim=5857876957511
PARSING IN CURSOR #4 len=34 dep=0 uid=86 oct=47 lid=86 tim=5857877083392 hv=1432432939 ad='f22431a8'
BEGIN PROC_RET_REPORT_TEST; END;
END OF STMT
EXEC #4:c=407030000,e=714358039,p=1306018,cr=2069759,cu=0,mis=1,r=1,dep=0,og=1,tim=5857877083386
WAIT #4: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877086767
WAIT #4: nam='SQL*Net message from client' ela= 200996 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877287847
=====================
PARSING IN CURSOR #27 len=52 dep=0 uid=86 oct=47 lid=86 tim=5857877288121 hv=1029988163 ad='2c9c9168'
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
END OF STMT
PARSE #27:c=0,e=115,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=5857877288114
WAIT #27: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877288662
EXEC #27:c=0,e=637,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=5857877288949
WAIT #27: nam='SQL*Net message from client' ela= 37034 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877326129
WAIT #0: nam='SQL*Net message to client' ela= 1 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877326246
WAIT #0: nam='SQL*Net message from client' ela= 41706 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877367979
WAIT #0: nam='SQL*Net message to client' ela= 0 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5857877368117
*** 2008-01-08 16:41:16.179
WAIT #0: nam='SQL*Net message from client' ela= 201999998 driver id=1413697536 #bytes=1 p3=0 obj#=108859 tim=5858079368156
XCTEND rlbk=0, rd_only=1
STAT #25 id=1 cnt=1 pid=0 pos=1 obj=0 op='HASH JOIN (cr=18 pr=0 pw=0 time=7852 us)'
STAT #25 id=2 cnt=1 pid=1 pos=1 obj=0 op='FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=2990 us)'
STAT #25 id=3 cnt=1385 pid=1 pos=2 obj=0 op='FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=2780 us)'
STAT #26 id=1 cnt=1 pid=0 pos=1 obj=0 op='COUNT STOPKEY (cr=0 pr=0 pw=0 time=38 us)'
STAT #26 id=2 cnt=1 pid=1 pos=1 obj=0 op='FIXED TABLE FULL X$VERSION (cr=0 pr=0 pw=0 time=31 us)'
STAT #24 id=1 cnt=0 pid=0 pos=1 obj=0 op='NESTED LOOPS (cr=4648 pr=4641 pw=0 time=2518383 us)'
STAT #24 id=2 cnt=0 pid=1 pos=1 obj=108859 op='TABLE ACCESS FULL S_RET_TICKET_END_REJ (cr=4648 pr=4641 pw=0 time=2518377 us)'
STAT #24 id=3 cnt=0 pid=1 pos=2 obj=98998 op='TABLE ACCESS BY INDEX ROWID S_SITE_MASTER (cr=0 pr=0 pw=0 time=0 us)'
STAT #24 id=4 cnt=0 pid=3 pos=1 obj=98999 op='INDEX UNIQUE SCAN PK_SITE_NUM (cr=0 pr=0 pw=0 time=0 us)'
Sorry for the length of the post.
Thanks,
Jafar

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
SELECT B.CITY_CODE||'-'||B.STORE_NO||'-'||B.STORE_SHORT_NAME CITY_STORE,
RPAD(K1.TDATE,14,' ') TDATE, RPAD(K1.TAMT,14,' ') TAMT, RPAD(K1.NTKT ,9,' ')
NTKT, K1.POS POS
FROM
( SELECT SUBSTR(STORE_NO,3,6) STNO, TRANS_DATE TDATE, TICKET_AMOUNT TAMT,
TICKET_NO NTKT, POS_NO POS FROM DEVDBA.S_RET_TICKET_END_REJ WHERE
TRUNC(RECORD_DATE)=TRUNC(SYSDATE) AND TRAINING_MODE_FLAG=0 AND
VOID_TICKET_FLAG=0 AND (TICKET_AMOUNT>1000000 OR TICKET_AMOUNT<-1000000 ) )
K1,DEVDBA.S_SITE_MASTER B WHERE STNO=B.STORE_NO
call count cpu elapsed disk query current rows
Parse 1 0.02 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.39 2.51 4641 4648 0 0
total 3 0.41 2.52 4641 4648 0 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN) (recursive depth: 1)
Rows Row Source Operation
0 NESTED LOOPS (cr=4648 pr=4641 pw=0 time=2518383 us)
0 TABLE ACCESS FULL S_RET_TICKET_END_REJ (cr=4648 pr=4641 pw=0 time=2518377 us)
0 TABLE ACCESS BY INDEX ROWID S_SITE_MASTER (cr=0 pr=0 pw=0 time=0 us)
0 INDEX UNIQUE SCAN PK_SITE_NUM (cr=0 pr=0 pw=0 time=0 us)(object id 98999)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 NESTED LOOPS
0 TABLE ACCESS MODE: ANALYZED (FULL) OF 'S_RET_TICKET_END_REJ'
(TABLE)
0 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF
'S_SITE_MASTER' (TABLE)
0 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'PK_SITE_NUM' (INDEX
(UNIQUE))
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 3 0.02 0.04
db file scattered read 89 0.07 2.19
BEGIN PROC_RET_REPORT_TEST; END;
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 407.03 714.35 1306018 2069759 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 1 407.03 714.35 1306018 2069759 0 1
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
TCP Socket (KGAS) 43 0.11 0.12
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.20 0.20
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 3 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 3 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 86 (ORADMIN)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.03 0.03
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 2 407.03 714.35 1306018 2069762 0 2
Fetch 0 0.00 0.00 0 0 0 0
total 3 407.03 714.35 1306018 2069762 0 2
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file scattered read 7444 0.51 106.03
db file sequential read 9311 0.25 13.64
TCP Socket (KGAS) 43 0.11 0.12
SQL*Net message to client 4 0.00 0.00
SQL*Net message from client 4 201.99 202.27
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 22 0.05 0.04 0 0 0 0
Execute 30 0.03 0.02 0 0 0 0
Fetch 40 0.40 2.57 4646 4883 0 34
total 92 0.48 2.64 4646 4883 0 34
Misses in library cache during parse: 10
Misses in library cache during execute: 5
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file scattered read 89 0.07 2.19
db file sequential read 8 0.02 0.08
3 user SQL statements in session.
31 internal SQL statements in session.
34 SQL statements in session.
1 statement EXPLAINed in this session.
Trace file: odsprod_ora_27486.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
3 user SQL statements in trace file.
31 internal SQL statements in trace file.
34 SQL statements in trace file.
13 unique SQL statements in trace file.
1 SQL statements EXPLAINed using schema:
ORADMIN.prof$plan_table
Default table was used.
Table was created.
Table was dropped.
17240 lines in trace file.
2 elapsed seconds in trace file.Message was edited by:
Maran Viswarayar
Message was edited by:
Maran Viswarayar

Similar Messages

  • Query Tuning - using CASE statement in the WHERE clause - Duplicate Post

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

  • Query Tuning - using CASE statement in the WHERE clause

    Hi All,
    My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
    (Number of rows : approx > 600,000,000)
    Name                           Null     Type      
    ARTICLEID                      NOT NULL NUMBER(20)
    USERKEY                                 NUMBER(10)
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE      
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10)
    LINENUMBER                              NUMBER(10)
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2) 
    REQUESTDATETIME                         VARCHAR2(19)Explain Plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2224314832
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    PLAN_TABLE_OUTPUT
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
    Edited by: Chaitanya on Jun 9, 2011 2:47 AM

    Hi Dom,
    Modified Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND (('FULL'  = 'FULL'
    AND  (get_date_timestamp(os.requestdatetime)  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    AND   os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    OR ('FULL'  = 'INCR'
    AND os.entry_createddate  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
    PLAN_TABLE_OUTPUT
    Plan hash value: 3615447714
    | Id  | Operation                 | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |                   | 25125 |  1374K|       |   407K  (1)| 01:21:36 |       |       |
    |   1 |  HASH GROUP BY            |                   | 25125 |  1374K|  3768K|   407K  (1)| 01:21:36 |       |       |
    |   2 |   PARTITION RANGE ITERATOR|                   | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    |*  3 |    TABLE ACCESS FULL      | TABLE1 | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
                  2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM

  • Query tuning and using the "better" index.

    I have a database table with about 40,000 records in it. Using
    a certain index first limits the number of rows to 11,000
    records. Using a different index first (by disabling the other
    index in the query) limits the number of rows to 2,500 records.
    Using the explain plan, the rest of the query is parsed the same
    way for both queries. What reasons can explain why when the
    index that returns 11,000 records first runs faster than
    the "better" index? I thought the whole idea behind query
    tuning is to use the index that limits the data the most.

    It looks like Oracle likes the equality condition more than the greater than -less than combination (which you might like to recode as a BETWEEN condition for clarity).
    There are a number of factors here.
    i) Are the "test names" equally distributed? Do some test names appear with greater frequency than others? If so, collecting column statistics might cause the BATCH_2 index to be used for some test names, and not for others.
    ii) Likewise, what is the distribution of cdates? How does the distribution of cdates vary by test name?
    iii) You could force the use of the BATCH_6 index over the BATCH_2 by using an optimizer hint instead of dropping the BATCH_2 index ...
    select /*+ index(batch batch_6) */ id, test, cdate
    from batch
    where test = 'Some test name'
    and cdate >= &start date&
    and cdate < &end date& + 1
    ... or even try prompting Oracle to use both indexes ...
    select /*+ index(batch batch_6) index(batch batch_2) */ id, test, cdate
    from batch
    where test = 'Some test name'
    and cdate >= &start date&
    and cdate < &end date& + 1
    ... and test the response times, then chose to use the optimizer hint in your application
    iv) You might like to replace the rather unselective BATCH_2 index with a BATCH_2_6 index on both test and cdate (in that order). That would probably give you an excellent result, and the BATCH_6 index can still be used to satisfy queries slective on cdate that are not selective on test (in very recent versions of Oracle the BATCH_2_6 index might be used for such an operation, and you could drop both BATCH_6 and BATCH_2)
    Well, see if any of this helps.

  • Tuning query without using hint

    Hi,
    i want to change the plan of a query without using hint.
    Also i want to use the plan that hint generate in my original query.
    My db is a 11g.
    How can i do this?
    tnx

    You can use SQL Plan Manager. You might find this interesting:
    http://blogs.oracle.com/optimizer/entry/what_should_i_do_with_old_hints_in_my_workload
    The link above basically suggests these steps:
    1. Run the query with the hints, then
    2. Take the plan from #1 and associate its SQL plan baseline with the query with no hints
    3. Remove the hints for that query in the code and start capturing and evolving plans for the un-hinted query

  • Query tuning and how to force  table to use index?

    Dear Experts,
    i have two (2) question regarding performance during DRL.
    Question # 1
    There is a column name co_id in every transaction table. DBA suggest me to add [co_id='KPG'] in every clause which forces query to use index, resulting immediate processing. As an index was created for each table on the co_id column.
    Please note that co_id has constant value 'KPG' through out the table. is it make sense to add that column in where caluse like
    select a,b,c from tab1
    where a='89' and co_id='KPG'
    Question # 2
    if i am using a column name in where clause having index on it and that column is not in my column list does it restrict query for full table scan. like
    select a,b,c,d from tabletemp
    where e='ABC';
    Thanks in advance
    Edited by: Fiz Dosani on Mar 27, 2009 12:00 PM

    Fiz Dosani wrote:
    Dear Experts,
    i have two (2) question regarding performance during DRL.
    Question # 1
    There is a column name co_id in every transaction table. DBA suggest me to add [co_id='KPG'] in every clause which forces query to use index, resulting immediate processing. As an index was created for each table on the co_id column.
    Please note that co_id has constant value 'KPG' through out the table. is it make sense to add that column in where caluse like
    select a,b,c from tab1
    where a='89' and co_id='KPG'If co_id is always 'KPG' it is not needed to add this condition to the table. It would be very stupid to add an (normal) index on that column. An index is used to reduce the resultset of a query by storing the values and the rowids in a specified order. When all the values are equal and index justs makes all dml operations slower without makeing any select faster.
    And of cause the CBO is clever enough not to use such a index.
    >
    Question # 2
    if i am using a column name in where clause having index on it and that column is not in my column list does it restrict query for full table scan. like
    select a,b,c,d from tabletemp
    where e='ABC';
    Yes this is possible. However it depends from a few things.
    1) How selective this condition is. In general an index will be used when selectivity is less than 5%. This factor depends a bit on the database version. it means that when less then 5% of your rows have the value 'ABC' then an index access will be faster than the full table scan.
    2) Are the statistics up to date. The cost based optimizer (CBO) needs to know how many values are in that table, in the columns, in that index to make a good decision bout using an index access or a full table scan. Often one forgets to create statistics for freshly created data as in temptables.
    Edited by: Sven W. on Mar 27, 2009 8:53 AM

  • Complex SQL query Tuning

    Hi Fellas,
    I am new to query tuning. I have a big query with a TKPROF details. It is just fetching 34 records and taking approx 30 mins.
    The TKPROF detail will follow after the query.
    SELECT /*+ NO_INDEX(A, RA_CUSTOMER_TRX_N11 ) USE_NL(TYPES,A) */ a.customer_trx_id CUSTOMER_TRX_ID ,
    a.trx_number TRX_NUMBER ,
    A . INTERFACE_HEADER_ATTRIBUTE5 BILLING_STAGE ,
    A . INTERFACE_HEADER_CONTEXT PBRR_TYPE ,
    A . INTERFACE_HEADER_ATTRIBUTE11 BILLING_TERM ,
    NVL ( TL . SEQUENCE_NUM , 1 ) TERM_SEQUENCE_NUMBER ,
    types.type TRX_TYPE ,
    l_types.meaning TRX_TYPE_NAME ,
    TYPES . ACCOUNTING_AFFECT_FLAG OPEN_RECEIVABLE_FLAG ,
    a.trx_date TRX_DATE , SHIP_TO_CUSTOMER_ID SHIP_TO_CUSTOMER_ID ,
    SHIP_TO_CONTACT_ID SHIP_TO_CONTACT_ID ,
    REMIT_TO_ADDRESS_ID REMIT_TO_ADDRESS_ID ,
    A . PRIMARY_SALESREP_ID PRIMARY_SALESREP_ID ,
    B . ACCOUNT_NUMBER CUSTOMER_NUMBER ,
    A . INTERNAL_NOTES INTERNAL_NOTES ,
    A . COMMENTS TRX_COMMENTS ,
    PREVIOUS_CUSTOMER_TRX_ID PREVIOUS_CUSTOMER_TRX_ID ,
    SHIP_TO_SITE_USE_ID SHIP_TO_SITE_USE_ID ,
    NVL ( PRINTING_COUNT , 0 ) PRINTING_COUNT ,
    PRINTING_ORIGINAL_DATE PRINTING_ORIGINAL_DATE ,
    PRINTING_LAST_PRINTED PRINTING_LAST_PRINTED ,
    PRINTING_PENDING PRINTING_PENDING ,
    LAST_PRINTED_SEQUENCE_NUM LAST_PRINTED_SEQUENCE_NUMBER ,
    START_DATE_COMMITMENT START_DATE_COMMITMENT ,
    END_DATE_COMMITMENT END_DATE_COMMITMENT ,
    INITIAL_CUSTOMER_TRX_ID INITIAL_CUSTOMER_TRX_ID ,
    A . INVOICE_CURRENCY_CODE INVOICE_CURRENCY_CODE ,
    A . REASON_CODE CREDIT_HEADER_REASON_CODE_CSTM ,
    A . TERM_ID TERM_ID ,
    A . SHIP_DATE_ACTUAL SHIP_DATE_ACTUAL ,
    A . SHIP_VIA SHIP_VIA ,
    A . WAYBILL_NUMBER WAYBILL_NUMBER ,
    A . PURCHASE_ORDER PURCHASE_ORDER_NUMBER ,
    A . PURCHASE_ORDER_REVISION PURCHASE_ORDER_REVISION ,
    A . PURCHASE_ORDER_DATE PURCHASE_ORDER_DATE ,
    A . CREATED_BY ORDER_CREATED_BY_CSTM ,
    P . DUE_DATE TERM_DUE_DATE_FROM_PS ,
    NVL ( TL . RELATIVE_AMOUNT , 100 ) * ( 100 / NVL ( T . BASE_AMOUNT , 100 ) ) TERM_RELATIVE_AMOUNT ,
    T . NAME TERM_NAME ,
    A . BILL_TO_CUSTOMER_ID BILL_TO_CUSTOMER_ID ,
    A . BILL_TO_CONTACT_ID BILL_TO_CONTACT_ID ,
    A . BILL_TO_SITE_USE_ID BILL_TO_SITE_USE_ID ,
    U_BILL . LOCATION BILL_TO_LOCATION ,
    SUBSTRB ( PARTY . PARTY_NAME , 1 , 50 ) BILL_CUST_NAME ,
    RTRIM ( RPAD ( LOC . ADDRESS1 , 40 ) ) BILL_ADDRESS1 ,
    RTRIM ( RPAD ( LOC . ADDRESS2 , 40 ) ) BILL_ADDRESS2 ,
    RTRIM ( RPAD ( LOC . ADDRESS3 , 40 ) ) BILL_ADDRESS3 ,
    RTRIM ( RPAD ( LOC . ADDRESS4 , 40 ) ) BILL_ADDRESS4 ,
    LOC . CITY BILL_CITY , NVL ( LOC . STATE ,
    LOC . PROVINCE ) BILL_STATE ,
    LOC . POSTAL_CODE BILL_POSTAL_CODE ,
    LOC . COUNTRY BILL_COUNTRY ,
    U_BILL . TAX_REFERENCE BILL_SITE_TAX_REFERENCE ,
    PARTY . TAX_REFERENCE BILL_CUST_TAX_REFERENCE ,
    nvl(amount_line_items_original + decode(a.initial_customer_trx_id, '', 0, nvl(com_adj.amount,0)), to_number(null)) TRX_LINE_AMOUNT ,
    nvl(tax_original, to_number(null)) TRX_TAX_AMOUNT ,
    nvl(freight_original, to_number(null)) TRX_FREIGHT_AMOUNT ,
    p.amount_due_original + decode(a.initial_customer_trx_id, '', 0, nvl(com_adj.amount,0)) TRX_ALL_AMOUNT ,
    DECODE ( : P_ORDER_BY , 'TRX_NUMBER' , A . TRX_NUMBER , 'ADJUSTMENT_NUMBER' , A.TRX_NUMBER , 'CUSTOMER' , SUBSTRB ( PARTY . PARTY_NAME , 1 , 50 ) , 'POSTAL_CODE' , LOC . POSTAL_CODE , A . TRX_NUMBER ) ORDER_BY ,
    LOC . ADDRESS1 BILL_TO_ADDRESS1 ,
    LOC . ADDRESS2 BILL_TO_ADDRESS2 ,
    LOC . ADDRESS3 BILL_TO_ADDRESS3 ,
    LOC . ADDRESS4 BILL_TO_ADDRESS4 ,
    LOC . STATE BILL_TO_STATE ,
    LOC . PROVINCE BILL_TO_PROVINCE ,
    T . description Term_Description ,
    a . org_id ,
    a . created_from
    FROM
    AR_ADJUSTMENTS COM_ADJ,
    AR_PAYMENT_SCHEDULES P,
    RA_CUST_TRX_LINE_GL_DIST REC,
    RA_CUSTOMER_TRX A,
    HZ_CUST_ACCOUNTS B,
    RA_TERMS T,
    RA_TERMS_LINES TL,
    RA_CUST_TRX_TYPES TYPES,
    AR_LOOKUPS L_TYPES,
    HZ_PARTIES      PARTY,
    HZ_CUST_ACCT_SITES A_BILL,
    HZ_PARTY_SITES PARTY_SITE,
    HZ_LOCATIONS LOC,
    HZ_CUST_SITE_USES U_BILL
    WHERE
    A.BILL_TO_CUSTOMER_ID = B.CUST_ACCOUNT_ID AND
    REC.CUSTOMER_TRX_ID = A.CUSTOMER_TRX_ID AND
    REC.LATEST_REC_FLAG = 'Y' AND
    REC.ACCOUNT_CLASS = 'REC' AND
    P.PAYMENT_SCHEDULE_ID + DECODE ( P.CLASS , 'INV' , 0 , '' ) = COM_ADJ.PAYMENT_SCHEDULE_ID (+) AND
    COM_ADJ.SUBSEQUENT_TRX_ID IS NULL AND 'C' = COM_ADJ.ADJUSTMENT_TYPE (+) AND
    A.COMPLETE_FLAG = 'Y' AND
    A.CUST_TRX_TYPE_ID = TYPES.CUST_TRX_TYPE_ID AND
    L_TYPES.LOOKUP_TYPE = 'INV/CM/ADJ' AND
    A.PRINTING_OPTION IN ( 'PRI' , 'REP' ) AND
    L_TYPES.LOOKUP_CODE = DECODE ( TYPES.TYPE , 'DEP' , 'INV' , TYPES.TYPE ) AND
    NVL ( P.TERMS_SEQUENCE_NUMBER , nvl ( TL.SEQUENCE_NUM , 0 ) ) = nvl ( TL.SEQUENCE_NUM , nvl ( p.terms_sequence_number , 0 ) ) AND
    DECODE ( P.PAYMENT_SCHEDULE_ID , '' , 0 , NVL ( T.PRINTING_LEAD_DAYS , 0 ) ) = 0 AND
    A.BILL_TO_SITE_USE_ID = U_BILL.SITE_USE_ID AND
    U_BILL.CUST_ACCT_SITE_ID = A_BILL.CUST_ACCT_SITE_ID AND
    A_BILL.party_site_id = party_site.party_site_id AND
    B.PARTY_ID = PARTY.PARTY_ID AND
    loc.location_id = party_site.location_id AND
    NVL ( P.AMOUNT_DUE_REMAINING , 0 ) <> 0 AND
    A.CUST_TRX_TYPE_ID = 2526 AND
    TYPES.TYPE = 'INV' AND
    A.TERM_ID = TL.TERM_ID (+) AND
    A.TERM_ID = T.TERM_ID (+) AND
    A.CUSTOMER_TRX_ID = P.CUSTOMER_TRX_ID (+) AND
    A.PRINTING_PENDING = 'Y' AND
    NVL ( TL.SEQUENCE_NUM , 1 ) > NVL ( A.LAST_PRINTED_SEQUENCE_NUM , 0 ) and 1 = 1 AND
    NOT EXISTS ( SELECT 'X' from ECE_TP_DETAILS ETD ,
                        ECE_TP_HEADERS ETH
    WHERE
    ETH.TP_HEADER_ID = A_BILL.TP_HEADER_ID AND
    ETD.TP_HEADER_ID = ETH.TP_HEADER_ID AND
    ETD.EDI_FLAG = 'Y' AND
    ETD.DOCUMENT_ID = 'INO' AND
    ETD.DOCUMENT_TYPE = DECODE ( TYPES.TYPE , 'CM' , DECODE ( A.PREVIOUS_CUSTOMER_TRX_ID , NULL , 'OACM' , 'CM' ) , TYPES.TYPE ) ) AND
    A.PRINTING_OPTION IN ( 'PRI' , 'REP' ) AND
    T.NAME not like 'PB%' AND
    1 = 1 AND
    MIT_AR.GE_AR_COAKLEY_ELIGIBLE ( 'NEW' , P.CUSTOMER_TRX_ID , A.ORG_ID ) = 0 AND
    A.org_id = TYPES.org_id UNION SELECT /*+ NO_INDEX(A, RA_CUSTOMER_TRX_N11 ) USE_NL(TYPES,A) */
    a.customer_trx_id , a.trx_number ,
    A . INTERFACE_HEADER_ATTRIBUTE5 ,
    A . INTERFACE_HEADER_CONTEXT ,
    A . INTERFACE_HEADER_ATTRIBUTE11 ,
    NVL ( P . TERMS_SEQUENCE_NUMBER , 1 ) ,
    types.type , l_types.meaning ,
    TYPES . ACCOUNTING_AFFECT_FLAG ,
    a.trx_date ,
    A . SHIP_TO_CUSTOMER_ID ,
    A . SHIP_TO_CONTACT_ID ,
    A . REMIT_TO_ADDRESS_ID ,
    A . PRIMARY_SALESREP_ID ,
    B . ACCOUNT_NUMBER ,
    A . INTERNAL_NOTES ,
    A . COMMENTS ,
    PREVIOUS_CUSTOMER_TRX_ID ,
    SHIP_TO_SITE_USE_ID ,
    NVL ( PRINTING_COUNT , 0 ) ,
    PRINTING_ORIGINAL_DATE ,
    PRINTING_LAST_PRINTED ,
    PRINTING_PENDING ,
    LAST_PRINTED_SEQUENCE_NUM ,
    START_DATE_COMMITMENT ,
    END_DATE_COMMITMENT ,
    INITIAL_CUSTOMER_TRX_ID ,
    A . INVOICE_CURRENCY_CODE ,
    A . REASON_CODE ,
    A . TERM_ID ,
    A . SHIP_DATE_ACTUAL ,
    A . SHIP_VIA ,
    A . WAYBILL_NUMBER ,
    A . PURCHASE_ORDER ,
    A . PURCHASE_ORDER_REVISION ,
    A . PURCHASE_ORDER_DATE ,
    A . CREATED_BY ,
    P . DUE_DATE ,
    NVL ( TL . RELATIVE_AMOUNT , 100 ) * ( 100 / NVL ( T . BASE_AMOUNT , 100 ) ) ,
    T . NAME , A . BILL_TO_CUSTOMER_ID ,
    A . BILL_TO_CONTACT_ID ,
    A . BILL_TO_SITE_USE_ID ,
    U_BILL . LOCATION BILL_TO_LOCATION ,
    SUBSTRB ( PARTY . PARTY_NAME , 1 , 50 ) BILL_CUST_NAME ,
    RTRIM ( RPAD ( LOC . ADDRESS1 , 40 ) ) ,
    RTRIM ( RPAD ( LOC . ADDRESS2 , 40 ) ) ,
    RTRIM ( RPAD ( LOC . ADDRESS3 , 40 ) ) ,
    RTRIM ( RPAD ( LOC . ADDRESS4 , 40 ) ) ,
    LOC . CITY ,
    NVL ( LOC . STATE , LOC . PROVINCE ) ,
    LOC . POSTAL_CODE ,
    LOC . COUNTRY ,
    U_BILL . TAX_REFERENCE ,
    PARTY . TAX_REFERENCE ,
    nvl(amount_line_items_original + decode(a.initial_customer_trx_id, '', 0, nvl(com_adj.amount,0)), to_number(null)) ,
    nvl(tax_original, to_number(null)) ,
    nvl(freight_original, to_number(null)) ,
    p.amount_due_original + decode(a.initial_customer_trx_id, '', 0, nvl(com_adj.amount,0)) ,
    DECODE ( : P_ORDER_BY , 'TRX_NUMBER' ,
    A . TRX_NUMBER , 'ADJUSTMENT_NUMBER' ,
    A.TRX_NUMBER , 'CUSTOMER' ,
    SUBSTRB ( PARTY . PARTY_NAME , 1 , 50 ) , 'POSTAL_CODE' ,
    LOC . POSTAL_CODE , A . TRX_NUMBER ) ORDER_BY ,
    LOC . ADDRESS1 ,
    LOC . ADDRESS2 ,
    LOC . ADDRESS3 ,
    LOC . ADDRESS4 ,
    LOC . STATE ,
    LOC . PROVINCE ,
    T . description ,
    a . org_id ,
    a . created_from
    FROM
    RA_TERMS_LINES TL,
    RA_CUST_TRX_TYPES TYPES,
    AR_LOOKUPS L_TYPES,
         HZ_CUST_ACCOUNTS B,
    HZ_PARTIES      PARTY,
    HZ_CUST_SITE_USES U_BILL,
    HZ_CUST_ACCT_SITES A_BILL,
    HZ_PARTY_SITES PARTY_SITE,
    HZ_LOCATIONS LOC,
    AR_ADJUSTMENTS COM_ADJ,
    RA_CUSTOMER_TRX A,
    AR_PAYMENT_SCHEDULES P,
    RA_TERMS T
    WHERE
    A.BILL_TO_CUSTOMER_ID = B.CUST_ACCOUNT_ID
    AND P.PAYMENT_SCHEDULE_ID + DECODE ( P.CLASS , 'INV' , 0 , '' ) = COM_ADJ.PAYMENT_SCHEDULE_ID (+) AND
    COM_ADJ.SUBSEQUENT_TRX_ID IS NULL AND
    'C' = COM_ADJ.ADJUSTMENT_TYPE (+) AND
    A.COMPLETE_FLAG = 'Y' AND
    A.CUSTOMER_TRX_ID = P.CUSTOMER_TRX_ID AND
    A.CUST_TRX_TYPE_ID = TYPES.CUST_TRX_TYPE_ID AND
    L_TYPES.LOOKUP_TYPE = 'INV/CM/ADJ' AND
    A.PRINTING_OPTION IN ( 'PRI' , 'REP' ) AND
    L_TYPES.LOOKUP_CODE = DECODE ( TYPES.TYPE , 'DEP' , 'INV' , TYPES.TYPE ) AND
    NVL ( T.PRINTING_LEAD_DAYS , 0 ) > 0 AND
    A.BILL_TO_SITE_USE_ID = U_BILL.SITE_USE_ID AND
    U_BILL.CUST_ACCT_SITE_ID = A_BILL.CUST_ACCT_SITE_ID AND
    A_BILL.PARTY_SITE_ID = PARTY_SITE.PARTY_SITE_ID AND
    B.PARTY_ID = PARTY.PARTY_ID AND
    LOC.LOCATION_ID = PARTY_SITE.LOCATION_ID AND
    NVL ( P.TERMS_SEQUENCE_NUMBER , TL.SEQUENCE_NUM ) = TL.SEQUENCE_NUM AND
    NVL ( P.AMOUNT_DUE_REMAINING , 0 ) <> 0 AND
    A.CUST_TRX_TYPE_ID = 2526 AND
    TYPES.TYPE = 'INV' AND
    T.TERM_ID = P.TERM_ID AND
    TL.TERM_ID (+) = T.TERM_ID AND
    A.PRINTING_PENDING = 'Y' AND
    P.TERMS_SEQUENCE_NUMBER > NVL ( A.LAST_PRINTED_SEQUENCE_NUM , 0 ) and 1 = 1 AND
    NOT EXISTS ( SELECT 'X' from
    ECE_TP_DETAILS ETD ,
    ECE_TP_HEADERS ETH
    WHERE
    ETH.TP_HEADER_ID = A_BILL.TP_HEADER_ID AND
    ETD.TP_HEADER_ID = ETH.TP_HEADER_ID AND
    ETD.EDI_FLAG = 'Y' AND
    ETD.DOCUMENT_ID = 'INO' AND
    ETD.DOCUMENT_TYPE = DECODE ( TYPES.TYPE , 'CM' , DECODE ( A.PREVIOUS_CUSTOMER_TRX_ID , NULL , 'OACM' , 'CM' ) , TYPES.TYPE ) ) AND
    NVL ( A.PRINTING_OPTION , 'REP' ) IN ( 'PRI' , 'REP' ) AND
    T.NAME not like 'PB%' AND 1 = 1 AND
    MIT_AR.GE_AR_COAKLEY_ELIGIBLE ( 'NEW' , P.CUSTOMER_TRX_ID , A.ORG_ID ) = 0 AND
    A.org_id = TYPES.org_id
    ORDER BY 60 ASC,68 ASC,2 ASC,3 ASC,4 ASC,5 ASC,44 ASC
    call count cpu elapsed disk query current rows
    Parse 1 0.06 0.08 0 364 0 0
    Execute 1 5.11 4.98 0 0 0 0
    Fetch 18 81.35 1375.73 203636 357435 0 34
    total 20 86.52 1380.80 203636 357799 0 34
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 25
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max) Row Source Operation
    34 34 34 SORT UNIQUE (cr=569992 pr=227554 pw=0 time=1658548772 us)
    34 34 34 UNION-ALL (cr=569992 pr=227554 pw=0 time=773822949 us)
    34 34 34 FILTER (cr=228022 pr=107808 pw=0 time=773820837 us)
    34 34 34 FILTER (cr=228022 pr=107808 pw=0 time=773820394 us)
    34 34 34 NESTED LOOPS OUTER (cr=228022 pr=107808 pw=0 time=771070499 us)
    34 34 34 NESTED LOOPS (cr=227986 pr=107806 pw=0 time=773799735 us)
    34 34 34 NESTED LOOPS (cr=227882 pr=107806 pw=0 time=773742298 us)
    34 34 34 NESTED LOOPS (cr=227812 pr=107806 pw=0 time=773688021 us)
    34 34 34 NESTED LOOPS (cr=227708 pr=107806 pw=0 time=773636699 us)
    34 34 34 FILTER (cr=227638 pr=107806 pw=0 time=773566978 us)
    4616 4616 4616 NESTED LOOPS OUTER (cr=220679 pr=106836 pw=0 time=823009777 us)
    4610 4610 4610 NESTED LOOPS (cr=206836 pr=102712 pw=0 time=623651066 us)
    4610 4610 4610 NESTED LOOPS (cr=188367 pr=96450 pw=0 time=531982352 us)
    4610 4610 4610 NESTED LOOPS (cr=179145 pr=96449 pw=0 time=530980660 us)
    4610 4610 4610 FILTER (cr=165290 pr=96448 pw=0 time=529149297 us)
    4610 4610 4610 NESTED LOOPS OUTER (cr=165290 pr=96448 pw=0 time=530066499 us)
    4607 4607 4607 NESTED LOOPS (cr=156074 pr=96442 pw=0 time=762671095 us)
    4615 4615 4615 NESTED LOOPS (cr=146842 pr=96441 pw=0 time=751255741 us)
    4615 4615 4615 NESTED LOOPS (cr=137610 pr=96435 pw=0 time=751144978 us)
    4615 4615 4615 NESTED LOOPS (cr=123763 pr=96435 pw=0 time=750949543 us)
    4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=114531 pr=96435 pw=0 time=750675597 us)
    *329687 329687 329687 INDEX RANGE SCAN RA_CUSTOMER_TRX_N17 (cr=6232 pr=6046 pw=0 time=31982795 us)(object id 4788)* 4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_TYPES_ALL (cr=9232 pr=0 pw=0 time=239450 us)
    4615 4615 4615 INDEX UNIQUE SCAN RA_CUST_TRX_TYPES_U1 (cr=4617 pr=0 pw=0 time=160139 us)(object id 55731)
    4615 4615 4615 TABLE ACCESS BY INDEX ROWID FND_LOOKUP_VALUES (cr=13847 pr=0 pw=0 time=180337 us)
    4615 4615 4615 INDEX UNIQUE SCAN FND_LOOKUP_VALUES_U1 (cr=9232 pr=0 pw=0 time=135717 us)(object id 491822)
    4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_TERMS_B (cr=9232 pr=6 pw=0 time=155074 us)
    4615 4615 4615 INDEX UNIQUE SCAN RA_TERMS_B_U1 (cr=4617 pr=0 pw=0 time=60566 us)(object id 55734)
    4607 4607 4607 TABLE ACCESS BY INDEX ROWID RA_TERMS_TL (cr=9232 pr=1 pw=0 time=181115 us)
    4615 4615 4615 INDEX UNIQUE SCAN RA_TERMS_TL_U1 (cr=4617 pr=1 pw=0 time=82153 us)(object id 55755)
    4610 4610 4610 TABLE ACCESS BY INDEX ROWID RA_TERMS_LINES (cr=9216 pr=6 pw=0 time=259864 us)
    4610 4610 4610 INDEX RANGE SCAN RA_TERMS_LINES_U1 (cr=4609 pr=1 pw=0 time=104110 us)(object id 6703)
    4610 4610 4610 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=13855 pr=1 pw=0 time=1350357 us)
    4610 4610 4610 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=9222 pr=1 pw=0 time=434079 us)(object id 44870)
    4610 4610 4610 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCT_SITES_ALL (cr=9222 pr=1 pw=0 time=1024466 us)
    4610 4610 4610 INDEX UNIQUE SCAN HZ_CUST_ACCT_SITES_U1 (cr=4612 pr=1 pw=0 time=337477 us)(object id 46883)
    4610 4610 4610 TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_LINE_GL_DIST_ALL (cr=18469 pr=6262 pw=0 time=86754686 us)
    4610 4610 4610 INDEX RANGE SCAN RA_CUST_TRX_LINE_GL_DIST_N6 (cr=13836 pr=4061 pw=0 time=55844483 us)(object id 1510967)
    4616 4616 4616 TABLE ACCESS BY INDEX ROWID AR_PAYMENT_SCHEDULES_ALL (cr=13843 pr=4124 pw=0 time=50689789 us)
    4616 4616 4616 INDEX RANGE SCAN AR_PAYMENT_SCHEDULES_N2 (cr=9233 pr=1494 pw=0 time=15169412 us)(object id 4877)
    34 34 34 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=70 pr=0 pw=0 time=24450 us)
    34 34 34 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=36 pr=0 pw=0 time=5962 us)(object id 85278)
    34 34 34 TABLE ACCESS BY INDEX ROWID HZ_PARTY_SITES (cr=104 pr=0 pw=0 time=58609 us)
    34 34 34 INDEX UNIQUE SCAN HZ_PARTY_SITES_U1 (cr=70 pr=0 pw=0 time=31189 us)(object id 45527)
    34 34 34 TABLE ACCESS BY INDEX ROWID HZ_LOCATIONS (cr=70 pr=0 pw=0 time=52502 us)
    34 34 34 INDEX UNIQUE SCAN HZ_LOCATIONS_U1 (cr=36 pr=0 pw=0 time=23883 us)(object id 45692)
    34 34 34 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=104 pr=0 pw=0 time=49042 us)
    34 34 34 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=70 pr=0 pw=0 time=22106 us)(object id 757879)
    0 0 0 TABLE ACCESS BY INDEX ROWID AR_ADJUSTMENTS_ALL (cr=36 pr=2 pw=0 time=19638 us)
    0 0 0 INDEX RANGE SCAN AR_ADJUSTMENTS_N3 (cr=36 pr=2 pw=0 time=19271 us)(object id 5473)
    0 0 0 NESTED LOOPS (cr=0 pr=0 pw=0 time=9 us)
    0 0 0 INDEX UNIQUE SCAN ECE_TP_HEADERS_U1 (cr=0 pr=0 pw=0 time=7 us)(object id 46119)
    0 0 0 TABLE ACCESS BY INDEX ROWID ECE_TP_DETAILS (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN ECE_TP_DETAILS_U2 (cr=0 pr=0 pw=0 time=0 us)(object id 6271)
    0 0 0 FILTER (cr=341970 pr=119746 pw=0 time=883424760 us)
    0 0 0 FILTER (cr=341970 pr=119746 pw=0 time=883424758 us)
    0 0 0 NESTED LOOPS OUTER (cr=341970 pr=119746 pw=0 time=883424757 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424752 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424749 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424742 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424740 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424735 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424731 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424726 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424724 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424721 us)
    0 0 0 NESTED LOOPS (cr=341970 pr=119746 pw=0 time=883424715 us)
    34 34 34 NESTED LOOPS (cr=341900 pr=119746 pw=0 time=882400482 us)
    4615 4615 4615 NESTED LOOPS (cr=123763 pr=93484 pw=0 time=674293279 us)
    4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=114531 pr=93484 pw=0 time=674030164 us)
    329687 329687 329687 INDEX RANGE SCAN RA_CUSTOMER_TRX_N17 (cr=6232 pr=6130 pw=0 time=36621510 us)(object id 4788)
    4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_TYPES_ALL (cr=9232 pr=0 pw=0 time=249893 us)
    4615 4615 4615 INDEX UNIQUE SCAN RA_CUST_TRX_TYPES_U1 (cr=4617 pr=0 pw=0 time=169485 us)(object id 55731)
    34 34 34 TABLE ACCESS BY INDEX ROWID AR_PAYMENT_SCHEDULES_ALL (cr=218137 pr=26262 pw=0 time=310068873 us)
    3304 3304 3304 INDEX RANGE SCAN AR_PAYMENT_SCHEDULES_N2 (cr=214841 pr=24355 pw=0 time=283359418 us)(object id 4877)
    0 0 0 TABLE ACCESS BY INDEX ROWID RA_TERMS_B (cr=70 pr=0 pw=0 time=829 us)
    34 34 34 INDEX UNIQUE SCAN RA_TERMS_B_U1 (cr=36 pr=0 pw=0 time=527 us)(object id 55734)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 44870)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCT_SITES_ALL (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_CUST_ACCT_SITES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 46883)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 85278)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 757879)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_PARTY_SITES (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_PARTY_SITES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 45527)
    0 0 0 TABLE ACCESS BY INDEX ROWID HZ_LOCATIONS (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN HZ_LOCATIONS_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 45692)
    0 0 0 TABLE ACCESS BY INDEX ROWID RA_TERMS_TL (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN RA_TERMS_TL_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 55755)
    0 0 0 TABLE ACCESS BY INDEX ROWID RA_TERMS_LINES (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX RANGE SCAN RA_TERMS_LINES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 6703)
    0 0 0 TABLE ACCESS BY INDEX ROWID FND_LOOKUP_VALUES (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN FND_LOOKUP_VALUES_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 491822)
    0 0 0 TABLE ACCESS BY INDEX ROWID AR_ADJUSTMENTS_ALL (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX RANGE SCAN AR_ADJUSTMENTS_N3 (cr=0 pr=0 pw=0 time=0 us)(object id 5473)
    0 0 0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN ECE_TP_HEADERS_U1 (cr=0 pr=0 pw=0 time=0 us)(object id 46119)
    0 0 0 TABLE ACCESS BY INDEX ROWID ECE_TP_DETAILS (cr=0 pr=0 pw=0 time=0 us)
    0 0 0 INDEX UNIQUE SCAN ECE_TP_DETAILS_U2 (cr=0 pr=0 pw=0 time=0 us)(object id 6271)
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    row cache lock 6 0.00 0.00
    SQL*Net message to client 18 0.00 0.00
    SQL*Net more data to client 2 0.00 0.00
    gc current block 2-way 5375 0.02 3.76
    gc cr grant 2-way 49175 0.05 24.09
    db file sequential read 203636 0.51 1289.70
    gcs drm freeze in enter server mode 7 0.28 1.30
    latch: KCL gc element parent latch 4 0.00 0.00
    gc remaster 2 0.07 0.12
    latch: gcs resource hash 26 0.00 0.00
    latch free 1 0.00 0.00
    gc cr block 2-way 9 0.00 0.00
    latch: cache buffers chains 1 0.00 0.00
    SQL*Net message from client 18 0.00 0.00
    Thanks in Advance..

    Hi,
    it looks like your problem stems from the wrong choice of the driving table:
    4615 4615 4615            NESTED LOOPS (cr=123763 pr=96435 pw=0 time=750949543 us)
    4615 4615 4615              TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=114531 pr=96435 pw=0 time=750675597 us)
    329687 329687 329687       INDEX RANGE SCAN RA_CUSTOMER_TRX_N17 (cr=6232 pr=6046 pw=0 time=31982795 us)(object id 4788) 4615 4615 4615 TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_TYPES_ALL (cr=9232 pr=0 pw=0 time=239450 us)
    4615 4615 4615              INDEX UNIQUE SCAN RA_CUST_TRX_TYPES_U1 (cr=4617 pr=0 pw=0 time=160139 us)(object id 55731)
    4615 4615 4615              TABLE ACCESS BY INDEX ROWID FND_LOOKUP_VALUES (cr=13847 pr=0 pw=0 time=180337 us)Here, you are spending 750 seconds retriveing 329k rows, 98% of which are rejected on the next step. And the reason this is happening is because the optimizer underestimates the cardinatlity of this step by a factor of x50 (6.2k estimated, 329k actual value). Find out why this is happening or post relevant diagnostic information here (predicates, columns stats etc.), and fix this -- this should make your query twice as fast.
    The second half is coming from the SORT UNIQUE step. This looks weird: why on Earth it would take over 800 seconds to sort 34 rows?! Maybe there is something in the plan that I'm missing -- it's really hard to read because it's not formatted. Please obtain a plan with rowsource stats using dbms_xplan.display_cursor and post it here (google dbms_xplan.display_cursor allstats last if not sure how to do that).
    Best regards,
    Nikolay

  • Query tuning basics..

    Friends and gurus...
    OS: Linux
    DB: 11gR2
    Recently I have found myself trapped into many sql query tuning with and without bind variables and main aim of all tuning is to reduce total elapsed time displayed in AWR report.
    I found myself run all over the places just to identify problem and then try to solve it..
    with near to zero experience in query tuning I'm trying to learn this art and have below questions...
    Q.
    1. Identify problem: could somebody please list what all internal oracle tools available just to identify problem and what should be best approach?
    like sqltrace, explain plan, tkprof etc... list goes on so wanting to know which to follow and when...
    2. any idea how to get all details of steps listed in explain plan? since predicate information only list few steps where filter is used but some steps which takes long (hash join, nested loops) I don't know what caused it...
    3. how to identify problems in queries with bind variable?
    please note I don't have any 3rd party tool and all I work on is sqlplus session.
    thanks,

    khallas301, beside SB's reference to the Performance and Tuning Guide I want to point out that use of the AWR requires purchase of the extra cost EM Diagnositc and potentially also the Performance Pack License.
    You can use statspack if you do not have the EM liceses.
    How you approach what to tune depends a bit on the envornment. If only a few processes are having issues then you can look into customer complaints and tune what people are complaigning about. On the other hand if the entire system is having issues then you might want to identify critical processes and start with them.
    One approach would be to run sql trace on a critical process. Review the traces and tune the SQL statements you find having issues. Record the results and move on to the next critical process.
    Another approach would be to query the dynamic performance views for SQL with high logical IO counts, determine what processes the SQL is coming from, and tune that SQL.
    HTH -- Mark D Powell --

  • INTERMEDIA TEXT INDEX를 사용하는 QUERY의 TUNING

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-12
    INTERMEDIA TEXT INDEX를 사용하는 QUERY의 TUNING
    ===============================================
    Purpose
    Intermedia text를 사용하는 query의 속도를 향상시킬 수 있는 방안을
    알아보자.
    Explanation
    1. Make analyze all the table in the query
    text index를 이용하는 Query 안의 모든 Table을 analyze 해 주십시요.
    예를 들어 다음의 command를 이용할 수 있습니다.
    ANALYZE TABLE <table_name> COMPUTE STATISTICS;
    or
    ANALYZE TABLE <table_name> ESTIMATE STATISTICS 1000 ROWS;
    or
    ANALYZE TABLE <table_name> ESTIMATE STATISTICS 50 PERCENT;
    2. Using FIRST_ROWS hint
    더 좋은 response time 을 위해서 first_rows hint 를 사용해 보십시요.
    database에 기본적으로 설정된 optimizer mode는 choose mode입니다.
    이것은 전체 처리시간(throughput)을 가장 빠르게 하기 위한(all_rows mode)
    plan을 따르기 때문에 user의 입장에서는 first_rows 보다는 늦다고 느낄 수
    있습니다.
    Query에 다음과 같이 hint를 주고 performance를 확인해 보십시요.
    select /*+ FIRST_ROWS */ pk, col from ctx_tab
    where contains(txt_col, 'test', 1) > 0;
    단, first_rows hint를 이용하는 경우 자동으로 score 순서대로
    ordering 되지 않습니다. 왜냐하면 단어에 부합하는 문서를 찾는대로
    즉시 결과로 나타내 주기 때문입니다.
    3. Make sure text index is not fragmented
    insert, delete 가 많이 되는 table의 경우 index fragment를 제거해 주어야
    합니다. Index fragmentation 은 다음과 같이 확인할 수 있습니다.
    select count(*) from dr$<indexname>$i; -> A
    select count(*) from (select distinct(token_text) from dr$<indexname>$i); -> B
    위의 결과가 A/B 의 값이 3:1 보다 크면 optimize_index 를 실행해 주시는
    것이 좋습니다. 다음과 같은 command로 index optimization을 할 수 있습니다.
    alter index <index_name> rebuild online
    parameters('optimize full unlimited');
    index rebuild중에 online option을 주면 rebuild하는 중에도 계속 index를
    사용할 수 있게 됩니다. 하지만, 가능하면 사용자가 없을 때 rebuild하는 것이
    좋습니다.
    4. Check execution plan and sql trace.
    기본적인 여러 가지 작업들에도 속도가 별로 향상되지 않는다면, 직접
    sql trace를 떠서 Execution plan등을 확인해 보는 것이 필요합니다.
    예를 들어 SQL*PLUS에서 다음과 같이 sql trace를 뜹니다.
    alter session set timed_statistics=true;
    alter session set sql_trace=true;
    select ..... -> execute the query
    실행 후,
    exit
    user_dump_dest 에 지정된 directory에 trace 가 떨어지면 다음과 같은
    command로 tkprof 를 떠서 내용을 확인합니다.
    $ tkprof <tracefilename> <outputfilename> explain=username/password
    Referenc Documents
    Bulletin#10134 : SQL trace와 tkprof 사용 방법

  • Help for query tuning

    hello all
    my one of query is returning result in 1-2 mins only for 1 lakh record but i am not sure if it showed me complete rows or not because when I an trying to get count of result ..its taking lot of time .when I am using this query on plsql code ..code is running slow so just wanted to confirm on query tuning point of view if its fine or not ..please look onto it and let me know if query is fine or not by explain plan .my oracle version is 11g
    this is my query
    SELECT ROWNUM , TRUNC(rownum/5000) + 20000 ,'FOR_UPDATE', sku_org.NAME ,
    acct_promo_sku.src_num , acct_promo_sku.sub_type ,
    promo_actual.sku_actual_pos
    FROM siebel.s_src acct_promo_hdr,
    siebel.s_src acct_title_format,
    siebel.s_src acct_promo_sku,
    siebel.s_src_x acct_promo_hdrx,
    siebel.s_src_x acct_promo_skux,
    siebel.s_prod_int prod,
    siebel.s_bu promo_hdr_org,
    siebel.s_bu sku_org,
    siebelwb.stg_sbl_acct_promo_actuals2 promo_actual
    WHERE acct_promo_hdr.sub_type = 'PLAN_ACCOUNT_PROMOTION'
    AND acct_promo_hdr.row_id = acct_title_format.par_src_id
    AND acct_title_format.sub_type = 'PLAN_ACCT_PROMOTION_CATEGORY'
    AND acct_title_format.row_id = acct_promo_sku.par_src_id
    AND acct_promo_sku.sub_type = 'PLAN_ACCOUNT_PROMOTION_PRODUCT'
    AND acct_promo_hdr.row_id = acct_promo_hdrx.par_row_id
    AND acct_promo_sku.row_id = acct_promo_skux.par_row_id(+)
    AND acct_promo_sku.prod_id = prod.row_id
    AND acct_promo_hdr.bu_id = promo_hdr_org.row_id
    AND acct_promo_sku.bu_id = sku_org.row_id
    AND prod.x_prod_material_num = promo_actual.material_number
    and prod.X_PROD_SALES_ORG=promo_actual.sales_org
    AND acct_promo_hdr.row_id = promo_actual.acct_promo_id
    and nvl(acct_promo_hdr.pr_accnt_id,0)=nvl(promo_actual.acct_siebel_rowid,0)
    and nvl(acct_promo_hdr.x_indirect_id,0)=nvl(promo_actual.indirect_acct_siebel_rowid,0)
    AND promo_actual.load_date >= TRUNC(SYSDATE)
    AND promo_actual.load_date < TRUNC(SYSDATE + 1)
    explain plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 3864590768
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 298 | 2300 (1)| 00:00:28 |
    | 1 | COUNT | | | | | |
    |* 2 | FILTER | | | | | |
    | 3 | NESTED LOOPS | | | | | |
    | 4 | NESTED LOOPS | | 1 | 298 | 2300 (1)| 00:00:28 |
    | 5 | NESTED LOOPS OUTER | | 1 | 273 | 2298 (1)| 00:00:28 |
    | 6 | NESTED LOOPS | | 1 | 263 | 2296 (1)| 00:00:28 |
    | 7 | NESTED LOOPS | | 1 | 236 | 2295 (1)| 00:00:28 |
    | 8 | NESTED LOOPS | | 1 | 165 | 2292 (1)| 00:00:28 |
    | 9 | NESTED LOOPS | | 1 | 117 | 2289 (1)| 00:00:28 |
    | 10 | NESTED LOOPS | | 1 | 109 | 2289 (1)| 00:00:28 |
    | 11 | NESTED LOOPS | | 1 | 99 | 2287 (1)| 00:00:28 |
    |* 12 | TABLE ACCESS FULL | STG_SBL_ACCT_PROMO_ACTUALS2 | 1 | 49 | 2285 (1)| 00:0
    |* 13 | TABLE ACCESS BY INDEX ROWID| S_SRC | 1 | 50 | 2 (0)| 00:00:01 |
    |* 14 | INDEX UNIQUE SCAN | S_SRC_P1 | 1 | | 1 (0)| 00:00:01 |
    |* 15 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
    |* 16 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | 8 | 0 (0)| 00:00:01 |
    |* 17 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 48 | 3 (0)| 00:00:01 |
    |* 18 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
    |* 19 | TABLE ACCESS BY INDEX ROWID | S_SRC | 1 | 71 | 3 (0)| 00:00:01 |
    |* 20 | INDEX RANGE SCAN | S_SRC_F2 | 2 | | 2 (0)| 00:00:01 |
    | 21 | TABLE ACCESS BY INDEX ROWID | S_BU | 1 | 27 | 1 (0)| 00:00:01 |
    |* 22 | INDEX UNIQUE SCAN | S_BU_P1 | 1 | | 0 (0)| 00:00:01 |
    |* 23 | INDEX RANGE SCAN | S_SRC_X_U1 | 1 | 10 | 2 (0)| 00:00:01 |
    |* 24 | INDEX UNIQUE SCAN | S_PROD_INT_P1 | 1 | | 1 (0)| 00:00:01 |
    |* 25 | TABLE ACCESS BY INDEX ROWID | S_PROD_INT | 1 | 25 | 2 (0)| 00:00:
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(SYSDATE@!)<TRUNC(SYSDATE@!+1))
    12 - filter("PROMO_ACTUAL"."LOAD_DATE">=TRUNC(SYSDATE@!) AND "PROMO_ACTUAL"."LOAD_DATE"<TRUNC(SYSD
    13 - filter("ACCT_PROMO_HDR"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION' AND
    NVL("ACCT_PROMO_HDR"."PR_ACCNT_ID",'0')=NVL("PROMO_ACTUAL"."ACCT_SIEBEL_ROWID",'0') AND
    NVL("ACCT_PROMO_HDR"."X_INDIRECT_ID",'0')=NVL("PROMO_ACTUAL"."INDIRECT_ACCT_SIEBEL_ROWID",'0'
    14 - access("ACCT_PROMO_HDR"."ROW_ID"="PROMO_ACTUAL"."ACCT_PROMO_ID")
    15 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_PROMO_HDRX"."PAR_ROW_ID")
    16 - access("ACCT_PROMO_HDR"."BU_ID"="PROMO_HDR_ORG"."ROW_ID")
    17 - filter("ACCT_TITLE_FORMAT"."SUB_TYPE"='PLAN_ACCT_PROMOTION_CATEGORY')
    18 - access("ACCT_PROMO_HDR"."ROW_ID"="ACCT_TITLE_FORMAT"."PAR_SRC_ID")
    19 - filter("ACCT_PROMO_SKU"."PROD_ID" IS NOT NULL AND
    "ACCT_PROMO_SKU"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION_PRODUCT')
    20 - access("ACCT_TITLE_FORMAT"."ROW_ID"="ACCT_PROMO_SKU"."PAR_SRC_ID")
    22 - access("ACCT_PROMO_SKU"."BU_ID"="SKU_ORG"."ROW_ID")
    23 - access("ACCT_PROMO_SKU"."ROW_ID"="ACCT_PROMO_SKUX"."PAR_ROW_ID"(+))
    24 - access("ACCT_PROMO_SKU"."PROD_ID"="PROD"."ROW_ID")
    25 - filter("PROD"."X_PROD_MATERIAL_NUM" IS NOT NULL AND
    "PROD"."X_PROD_MATERIAL_NUM"="PROMO_ACTUAL"."MATERIAL_NUMBER" AND
    "PROD"."X_PROD_SALES_ORG"="PROMO_ACTUAL"."SALES_ORG")
    55 rows selected.
    thanks

    Hi,
    the plan you posted has the cost of 2300, i.e. 2300 single-block reads or equivalent number f multi-block reads. Even if none of the blocks is found in cache, 2300 reas shouldn't take more than a couple of minutes, beacause for most of the hard drives available today a disk read is typically within 5-10 ms.
    This means that if there is a problem, we will never find out about it by looking in the plan. And it's quite likely that there is, in fact, a problem, because the plan contains a bunch of nested joins, and the cost of each nested join is directly proportional to the cardinality of the previous nested loop. I.e. it suffices to make one bad mistake in estimating the number of rows coming fom one of the nested rows to screw up the entire plan and get all remaining estimates (including the total cost of the query) completely wrong.
    In order for us to be able to tell more, we need to see the plan with rowsource statistics, and please don't forget to use tags to preserve formatting (use the preview tab to make sure the posted plan is actually readable).
    Best regards,
      Nikolay                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SQL Query Tuning issue

    A query run by the 'tom' user who searches on (xyz crieteria) takes less than 5 seconds.
    However, when the user 'greg' ruuns the same query, it take > 14 minutes to execute for same xyz crieteria.
    Note:both are application users and internally use DOCD database user.Both are using same SQL Explain plan but diffrence is disk read in case of long running query.
    my question is if both queries are same and using same explain plan and returning same rows why there is disk read???? and such huge diffrence in execution time...Below is the tkprof output for both the queries.
    QUICK QUERY
    ===========
    SELECT E_NAME, E_CURVER_NUM, E_CURVER_CKO, E_PROTECTED, E_INA01, E_INA26,
    E_INA47, V_FILE_NAME, E_ICON_TITLE, E_INA41, E_INA11, E_INA16, E_INA40,
    E_INA15, E_INA35, E_ORG_FILENAME, E_COMMENT, E_INA28, E_INA27,
    E_CREATE_DATE, E_OWNER, E_LAST_DATE, V_CHECKED_OUT, V_CHECKIN_USER, V_NAME,
    V_E_NAME, V_AVAIL_STAT, V_RECLAIM, V_PERMANENT, V_CSI_STATUS, V_CD, E_INA01,
    V_INA03, V_INA02, V_INA04, E_INA02, V_INA01, V_CREATE_DATE, E_INA03
    FROM
    ELEMENT, VERSION WHERE (NLS_UPPER(E_INA01) LIKE NLS_UPPER(:V001) AND
    NLS_UPPER(E_INA26) = NLS_UPPER(:V002) AND E_INA02 IS NULL AND (E_INA03 IS
    NULL OR E_INA03 = :V003) AND V_BRANCH_CURVER = :V004) AND ELEMENT.E_NAME =
    VERSION.V_E_NAME ORDER BY 12, 10 DESC, 1, 26, 25
    call count cpu elapsed disk query current rows
    Parse 1 0.01 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 167 0.18 0.18 0 29466 0 1002
    total 169 0.20 0.19 0 29466 0 1002
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer goal: CHOOSE
    Parsing user id: 41
    Rows Row Source Operation
    1002 SORT ORDER BY (cr=29466 r=0 w=0 time=179192 us)
    8847 NESTED LOOPS (cr=29466 r=0 w=0 time=146638 us)
    14191 TABLE ACCESS FULL VERSION (cr=1082 r=0 w=0 time=25337 us)
    8847 TABLE ACCESS BY INDEX ROWID ELEMENT (cr=28384 r=0 w=0 time=97209 us)
    14191 INDEX UNIQUE SCAN UI256 (cr=14193 r=0 w=0 time=30388 us)(object id 29956)
    SLOW QUERY
    ==========
    SELECT E_NAME, E_CURVER_NUM, E_CURVER_CKO, E_PROTECTED, E_INA01, E_INA26,
    E_INA47, V_FILE_NAME, E_ICON_TITLE, E_INA41, E_INA11, E_INA16, E_INA40,
    E_INA15, E_INA35, E_ORG_FILENAME, E_COMMENT, E_INA28, E_INA27,
    E_CREATE_DATE, E_OWNER, E_LAST_DATE, V_CHECKED_OUT, V_CHECKIN_USER, V_NAME,
    V_E_NAME, V_AVAIL_STAT, V_RECLAIM, V_PERMANENT, V_CSI_STATUS, V_CD, E_INA01,
    V_INA03, V_INA02, V_INA04, E_INA02, V_INA01, V_CREATE_DATE, E_INA03
    FROM
    ELEMENT, VERSION WHERE (NLS_UPPER(E_INA01) LIKE NLS_UPPER(:V001) AND
    NLS_UPPER(E_INA26) = NLS_UPPER(:V002) AND E_INA02 IS NULL AND (E_INA03 IS
    NULL OR E_INA03 = :V003) AND V_BRANCH_CURVER = :V004) AND ELEMENT.E_NAME =
    VERSION.V_E_NAME ORDER BY 12, 10 DESC, 1, 26, 25
    call count cpu elapsed disk query current rows
    Parse 1 0.01 0.02 2 2 0 0
    Execute 1 0.01 0.00 0 0 0 0
    Fetch 167 0.29 1.18 2389 29466 0 1002
    total 169 0.32 1.21 2391 29468 0 1002
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer goal: CHOOSE
    Parsing user id: 41
    Rows Row Source Operation
    1002 SORT ORDER BY (cr=29466 r=2389 w=0 time=1180072 us)
    8847 NESTED LOOPS (cr=29466 r=2389 w=0 time=1144811 us)
    14191 TABLE ACCESS FULL VERSION (cr=1082 r=1078 w=0 time=134164 us)
    8847 TABLE ACCESS BY INDEX ROWID ELEMENT (cr=28384 r=1311 w=0 time=984455 us)
    14191 INDEX UNIQUE SCAN UI256 (cr=14193 r=137 w=0 time=127843 us)(object id 29956)

    Anuj,
    In the future, when posting items to the forum where spacing is critical to proper understanding, please use the { code } tags (without spaces) to retain the spacing.
    It appears that there is more to the story than what has been reported. It is good that you used tkprof, as it shows that there is more to the story. Taking a look at the two executions, the tkprof output shows that the first (quick) execution completed in 0.19 seconds, while the second (slow) execution completed in 1.21 seconds, even with th 2,391 blocks read from disk. My first question, if I were in the same situation, would be what would cause the first execution time to jump from 0.19 seconds to 5 seconds, and the second execution to jump from 1.21 seconds to 840 seconds (14 minutes)?
    In both cases, there is a library cache miss on both the parse and the execute calls - there may be some significance to this.
    In both cases, there were 167 fetch calls to return 1,002 rows, meaning that on average 6 rows were returned on each fetch.
    Let's assume that 'tom', whose query executed quickly, was connected to the database over a T1 connection with a 20ms (0.02 second) ping time. For siimplicity in calculation, assume that there were 170 round trips between the server and the client. The network communication between the client and the server would require at least 3.4 seconds, for a total time to send the query and retrieve the results of about 3.6 seconds. This is a little short of 5 seconds which you reported.
    Let's assume that 'greg', whose query executed slowly, was connected to the database over a satellite connection with a 2000ms (2 second) ping time. With the same number of round trips, the network communication would require about 340 seconds, for a total time to send the query and retrieve the results of about 341.21 seconds (5.7 minutes), about 8 minutes short of the target 14 minutes.
    Was this the only query executed by the clients, or were there multiple queries?
    Were the client computers on the same network segment?
    Did you gather a 10046 trace at level 8 or 12 for the sessions? If so, manually review the wait events in the trace files to see if it is possible to determine what was happening during the 14 minutes. Guessing can be fun, but sometimes you come up 8 minutes short by guessing alone.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Query tuning request

    This is my first post in this forum regarding query tuning, so my sincere apologies in advance if I have:
    1) not included sufficient information,
    2) included too much information,
    3) not posted to the correct forum
    I read through Randolf Geist's web page on instructions to post a query tuning request
    and attempted to follow it as closely as possible.
    I am attempting to figure out where a view I have constructed can be optimized.
    It takes approx. 45 seconds to 1 minute to run; I would like to cut that down to 10 seconds if possible.
    The view itself is somewhat complex; I will post the actual code if it will help you help me. Please advise.
    I was under the impression that posting the code was not necessary, but if it is, let me know and I will post it.
    I have been doing SQL development for a few years, but only recently in Oracle.
    I have no experience in looking through the following output and being able to tell where I can improve performance,
    so this will be a learning experience for me. Thanks in advance for your help - I appreciate it.
    Some additional information - my view is based on tables over which I have no control - it is a third-party application
    which I do reporting from. I do have the freedom to create indexes on columns within the tables if necessary.
    The statement is simply
    SELECT * FROM LLU_V_PRODUCTION_DETAIL_03
    which is the name of my view.
    here's all the information I've been able to retrieve by following Randolf's instructions:
    Oracle version is 10.2.0.1.0 - 64bit
    Here are optimizer parameters:
    NAME                                 TYPE        VALUE
    user_dump_dest                       string      C:\ORACLE\PRODUCT\10.2.0\ADMIN
                                                     \AXIUMPRODUCTION\UDUMP
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.1
    optimizer_index_caching              integer     90
    optimizer_index_cost_adj             integer     20
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          10-29-2005 01:36
    SYSSTATS_INFO        DSTOP                           10-29-2005 01:36
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW           1298.56584
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    13 rows selected.Here is the output of EXPLAIN PLAN:
    PLAN_TABLE_OUTPUT
    Plan hash value: 662813077
    | Id  | Operation                              | Name                        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                       |                             |    23M|    53G|       | 62330   (2)| 00:12:28 |
    |   1 |  VIEW                                  | LLU_V_PRODUCTION_DETAIL_03  |    23M|    53G|       | 62330   (2)| 00:12:28 |
    |   2 |   UNION-ALL                            |                             |       |       |       |            |          |
    |*  3 |    HASH JOIN                           |                             |    18M|  5062M|       |  1525  (10)| 00:00:19 |
    |   4 |     VIEW                               | index$_join$_007            |  1725 | 25875 |       |     4  (25)| 00:00:01 |
    |*  5 |      HASH JOIN                         |                             |       |       |       |            |          |
    |   6 |       INDEX FAST FULL SCAN             | USERS_PRIMARY               |  1725 | 25875 |       |     1   (0)| 00:00:01 |
    |   7 |       INDEX FAST FULL SCAN             | USERS_PRODUCER              |  1725 | 25875 |       |     2   (0)| 00:00:01 |
    |*  8 |     HASH JOIN                          |                             |   416K|   105M|       |  1399   (2)| 00:00:17 |
    |   9 |      TABLE ACCESS FULL                 | PRODUCER                    |  1396 |   118K|       |    24   (0)| 00:00:01 |
    |* 10 |      HASH JOIN                         |                             | 29819 |  5183K|       |  1372   (2)| 00:00:17 |
    |  11 |       TABLE ACCESS FULL                | CLASS                       |    20 |  1660 |       |     3   (0)| 00:00:01 |
    |* 12 |       TABLE ACCESS FULL                | QR_PRODUCTION               |   149K|    13M|       |  1367   (2)| 00:00:17 |
    |* 13 |    FILTER                              |                             |       |       |       |            |          |
    |* 14 |     HASH JOIN                          |                             |    16M|  5651M|       | 32983   (2)| 00:06:36 |
    |  15 |      VIEW                              | index$_join$_014            |  1725 | 25875 |       |     4  (25)| 00:00:01 |
    |* 16 |       HASH JOIN                        |                             |       |       |       |            |          |
    |  17 |        INDEX FAST FULL SCAN            | USERS_PRIMARY               |  1725 | 25875 |       |     1   (0)| 00:00:01 |
    |  18 |        INDEX FAST FULL SCAN            | USERS_PRODUCER              |  1725 | 25875 |       |     2   (0)| 00:00:01 |
    |* 19 |      HASH JOIN                         |                             |   149K|    49M|       | 32874   (1)| 00:06:35 |
    |  20 |       TABLE ACCESS FULL                | CLASS                       |    20 |  1660 |       |     3   (0)| 00:00:01 |
    |* 21 |       HASH JOIN                        |                             |   149K|    37M|       | 32870   (1)| 00:06:35 |
    |  22 |        TABLE ACCESS FULL               | PRODUCER                    |  1396 |   118K|       |    24   (0)| 00:00:01 |
    |* 23 |        HASH JOIN                       |                             |   222K|    37M|    12M| 32844   (1)| 00:06:35 |
    |  24 |         TABLE ACCESS FULL              | PATIENT                     |   188K|    10M|       |  6979   (1)| 00:01:24 |
    |* 25 |         HASH JOIN                      |                             |   222K|    24M|       | 23860   (2)| 00:04:47 |
    |* 26 |          TABLE ACCESS FULL             | PROCEDUR                    |   888 | 44400 |       |    11   (0)| 00:00:01 |
    |* 27 |          TABLE ACCESS FULL             | TRX                         |   442K|    28M|       | 23845   (2)| 00:04:47 |
    |* 28 |     TABLE ACCESS FULL                  | USERS                       |     1 |    11 |       |    55   (0)| 00:00:01 |
    |  29 |    NESTED LOOPS                        |                             |     1 |   473 |       | 25798   (1)| 00:05:10 |
    |  30 |     NESTED LOOPS                       |                             |     1 |   413 |       | 25797   (1)| 00:05:10 |
    |  31 |      NESTED LOOPS                      |                             |     1 |   398 |       | 25796   (1)| 00:05:10 |
    |  32 |       NESTED LOOPS                     |                             |     1 |   390 |       | 25795   (1)| 00:05:10 |
    |* 33 |        HASH JOIN                       |                             |     1 |   303 |       | 25794   (1)| 00:05:10 |
    |  34 |         TABLE ACCESS FULL              | LLU_EVALUATION_DESCRIPTIONS |    95 |  6175 |       |     3   (0)| 00:00:01 |
    |* 35 |         HASH JOIN                      |                             |  4630 |  1076K|       | 25791   (1)| 00:05:10 |
    |* 36 |          HASH JOIN                     |                             |  9607 |  1623K|       | 23834   (1)| 00:04:47 |
    |  37 |           MERGE JOIN                   |                             |   888 | 91464 |       |    13   (8)| 00:00:01 |
    |  38 |            TABLE ACCESS BY INDEX ROWID | CLASS                       |    20 |  1660 |       |     1   (0)| 00:00:01 |
    |  39 |             INDEX FULL SCAN            | CLASS_PRIMARY               |    20 |       |       |     1   (0)| 00:00:01 |
    |* 40 |            SORT JOIN                   |                             |   888 | 17760 |       |    12   (9)| 00:00:01 |
    |* 41 |             TABLE ACCESS FULL          | PROCEDUR                    |   888 | 17760 |       |    11   (0)| 00:00:01 |
    |* 42 |           TABLE ACCESS FULL            | TRX                         | 19125 |  1307K|       | 23820   (1)| 00:04:46 |
    |* 43 |          TABLE ACCESS FULL             | GRADITEM                    |   655K|    40M|       |  1952   (1)| 00:00:24 |
    |  44 |        TABLE ACCESS BY INDEX ROWID     | PRODUCER                    |     1 |    87 |       |     1   (0)| 00:00:01 |
    |* 45 |         INDEX UNIQUE SCAN              | PRODUCER_PRIMARY            |     1 |       |       |     1   (0)| 00:00:01 |
    |* 46 |       TABLE ACCESS BY INDEX ROWID      | GRADING                     |     1 |     8 |       |     1   (0)| 00:00:01 |
    |* 47 |        INDEX UNIQUE SCAN               | GRADING_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  48 |      TABLE ACCESS BY INDEX ROWID       | USERS                       |   221 |  3315 |       |     1   (0)| 00:00:01 |
    |* 49 |       INDEX RANGE SCAN                 | USERS_PRODUCER              |     1 |       |       |     1   (0)| 00:00:01 |
    |  50 |     TABLE ACCESS BY INDEX ROWID        | PATIENT                     |     1 |    60 |       |     1   (0)| 00:00:01 |
    |* 51 |      INDEX UNIQUE SCAN                 | PATIENT_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  52 |    TABLE ACCESS BY INDEX ROWID         | USERS                       |   109 |  1635 |       |     1   (0)| 00:00:01 |
    |  53 |     NESTED LOOPS                       |                             |     1 |   438 |       |  2023   (1)| 00:00:25 |
    |  54 |      NESTED LOOPS                      |                             |     1 |   423 |       |  2022   (1)| 00:00:25 |
    |  55 |       NESTED LOOPS                     |                             |     1 |   363 |       |  2021   (1)| 00:00:25 |
    |  56 |        NESTED LOOPS                    |                             |     1 |   276 |       |  2020   (1)| 00:00:25 |
    |  57 |         NESTED LOOPS                   |                             |     1 |   193 |       |  2019   (1)| 00:00:25 |
    |  58 |          NESTED LOOPS                  |                             |     1 |   185 |       |  2018   (1)| 00:00:25 |
    |  59 |           NESTED LOOPS                 |                             |     1 |   173 |       |  2017   (1)| 00:00:25 |
    |  60 |            NESTED LOOPS                |                             |     1 |   140 |       |  2016   (1)| 00:00:25 |
    |* 61 |             TABLE ACCESS FULL          | GRADITEM                    |   317 | 23141 |       |  1953   (2)| 00:00:24 |
    |* 62 |             TABLE ACCESS BY INDEX ROWID| TRX                         |     1 |    67 |       |     1   (0)| 00:00:01 |
    |* 63 |              INDEX UNIQUE SCAN         | TRX_PRIMARY                 |     1 |       |       |     1   (0)| 00:00:01 |
    |* 64 |            TABLE ACCESS BY INDEX ROWID | TRX                         |     1 |    33 |       |     1   (0)| 00:00:01 |
    |* 65 |             INDEX UNIQUE SCAN          | TRX_PRIMARY                 |     1 |       |       |     1   (0)| 00:00:01 |
    |* 66 |           TABLE ACCESS BY INDEX ROWID  | GRADITEM                    |     1 |    12 |       |     1   (0)| 00:00:01 |
    |* 67 |            INDEX RANGE SCAN            | GRADITEM_ID                 |    19 |       |       |     1   (0)| 00:00:01 |
    |* 68 |          TABLE ACCESS BY INDEX ROWID   | GRADING                     |     1 |     8 |       |     1   (0)| 00:00:01 |
    |* 69 |           INDEX UNIQUE SCAN            | GRADING_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |  70 |         TABLE ACCESS BY INDEX ROWID    | CLASS                       |     1 |    83 |       |     1   (0)| 00:00:01 |
    |* 71 |          INDEX UNIQUE SCAN             | CLASS_PRIMARY               |     1 |       |       |     1   (0)| 00:00:01 |
    |  72 |        TABLE ACCESS BY INDEX ROWID     | PRODUCER                    |     1 |    87 |       |     1   (0)| 00:00:01 |
    |* 73 |         INDEX UNIQUE SCAN              | PRODUCER_PRIMARY            |     1 |       |       |     1   (0)| 00:00:01 |
    |  74 |       TABLE ACCESS BY INDEX ROWID      | PATIENT                     |     1 |    60 |       |     1   (0)| 00:00:01 |
    |* 75 |        INDEX UNIQUE SCAN               | PATIENT_PRIMARY             |     1 |       |       |     1   (0)| 00:00:01 |
    |* 76 |      INDEX RANGE SCAN                  | USERS_PRODUCER              |     1 |       |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("QRP"."ProviderID"="U1"."Producer")
       5 - access(ROWID=ROWID)
       8 - access(TRIM("QRP"."ProviderID")=TRIM("P"."Producer"))
      10 - access(TRIM("QRP"."axiUm_Discipline")=TRIM("CLASS"."Class"))
      12 - filter("QRP"."ProviderID" IS NOT NULL AND "QRP"."Location"<'9990' AND "QRP"."ProcedureID"<>185 AND
                  "QRP"."PatientFirstName"<>'NON-PATIENT' AND ("QRP"."PatientFirstName"<>'TED' OR "QRP"."PatientLastName" NOT LIKE
                  'CAVENDER%'))
      13 - filter( NOT EXISTS (SELECT 0 FROM AXIUM."USERS" "USERS" WHERE "Custom3"='YES' AND LNNVL("User"<>:B1)) OR
                  TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')<'2011' OR TRIM(TO_CHAR(INTERNAL_FUNCTION("P"."EndDate"),'YYYY')) IS
                  NULL OR "TRX"."Procedure"='A0021' OR "TRX"."Procedure"='A0022')
      14 - access("TRX"."Producer"="U1"."Producer")
      16 - access(ROWID=ROWID)
      19 - access("PROC"."Discipline"="CLASS"."Class")
      21 - access("TRX"."Producer"="P"."Producer")
      23 - access("TRX"."Patient"="PAT"."Patient")
      25 - access("TRX"."Procedure"="PROC"."Procedure")
      26 - filter("PROC"."Discipline" IS NOT NULL)
      27 - filter("TRX"."Deleted"=0 AND "TRX"."Status"='C' AND "TRX"."Procedure" NOT LIKE 'D0149%' AND
                  "TRX"."Procedure"<>'D5001C')
      28 - filter("Custom3"='YES' AND LNNVL("User"<>:B1))
      33 - access(TRIM(UPPER("GI"."QuestionText"))=TRIM(UPPER("LLU"."GRADITEM_QuestionText")) AND
                  TRIM(UPPER("GI"."Text"))=TRIM(UPPER("LLU"."GRADITEM_Text")) AND TRIM("TRX"."Procedure")=TRIM("LLU"."ProcedureCode"))
      35 - access("TRX"."Type"="GI"."Type" AND "TRX"."Id"="GI"."Id" AND "TRX"."Treatment"="GI"."Treatment")
      36 - access("TRX"."Procedure"="PROC"."Procedure")
      40 - access("PROC"."Discipline"="CLASS"."Class")
           filter("PROC"."Discipline"="CLASS"."Class")
      41 - filter("PROC"."Discipline" IS NOT NULL)
      42 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C')
      43 - filter("GI"."Grading"<>0)
      45 - access("TRX"."Producer"="P"."Producer")
      46 - filter("G"."Deleted"=0)
      47 - access("TRX"."Grading"="G"."Grading")
           filter("G"."Grading"<>0 AND "G"."Grading"="GI"."Grading")
      49 - access("TRX"."Producer"="U1"."Producer")
      51 - access("TRX"."Patient"="PAT"."Patient")
      61 - filter("GI"."IsHeading"=3 AND TRIM("GI"."QuestionText")='Comments' AND "GI"."Grading"<>0)
      62 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
                  "TRX"."Procedure"='G1003'))
      63 - access("GI"."Type"="TRX"."Type" AND "GI"."Id"="TRX"."Id" AND "GI"."Treatment"="TRX"."Treatment")
      64 - filter("TRX"."Grading"<>0 AND "TRX"."Deleted"=0 AND "TRX"."Status"='C' AND ("TRX"."Procedure"='G1002' OR
                  "TRX"."Procedure"='G1003') AND "TRX"."Grading"="TRX"."Grading")
      65 - access("TRX"."Type"="TRX"."Type" AND "TRX"."Id"="TRX"."Id" AND "TRX"."Treatment"="TRX"."Treatment")
      66 - filter("GI"."RelValue"<>0 AND "TRX"."Type"="GI"."Type" AND "TRX"."Treatment"="GI"."Treatment")
      67 - access("TRX"."Id"="GI"."Id")
      68 - filter("G"."Deleted"=0)
      69 - access("TRX"."Grading"="G"."Grading")
           filter("G"."Grading"<>0 AND "GI"."Grading"="G"."Grading")
      71 - access("TRX"."Discipline"="CLASS"."Class")
      73 - access("TRX"."Producer"="P"."Producer")
      75 - access("TRX"."Patient"="PAT"."Patient")
      76 - access("TRX"."Producer"="U1"."Producer")
    138 rows selected.
    Elapsed: 00:00:00.62
    631015 rows selected.
    Elapsed: 00:01:49.13Output from AUTOTRACE (I think)
    NOTE: this post was too long for the forum, so I have removed a number of lines in the following output which appeared to be duplicating the above section (EXPLAIN PLAN).
    Statistics
           2657  recursive calls
              0  db block gets
       12734113  consistent gets
          13499  physical reads
              0  redo size
      103697740  bytes sent via SQL*Net to client
          69744  bytes received via SQL*Net from client
           6312  SQL*Net roundtrips to/from client
             76  sorts (memory)
              0  sorts (disk)
         631015  rows processedThe TKPROF output
    select * from llu_v_production_detail_03
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.51       0.51          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch     6312     88.09      98.01      13490   12733584          0      631015
    total     6314     88.60      98.52      13490   12733584          0      631015
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 57 
    Rows     Row Source Operation
    631015  VIEW  LLU_V_PRODUCTION_DETAIL_03 (cr=12733584 pr=13490 pw=0 time=92145592 us)
    631015   UNION-ALL  (cr=12733584 pr=13490 pw=0 time=91514573 us)
    125485    HASH JOIN  (cr=8099 pr=6396 pw=0 time=1523326 us)
       1725     VIEW  index$_join$_007 (cr=24 pr=0 pw=0 time=4777 us)
       1725      HASH JOIN  (cr=24 pr=0 pw=0 time=3051 us)
       1725       INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=50 us)(object id 55023)
       1725       INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=16 us)(object id 55024)
    144513     HASH JOIN  (cr=8075 pr=6396 pw=0 time=2326445 us)
       1396      TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=29 us)
    144513      HASH JOIN  (cr=7968 pr=6396 pw=0 time=2035684 us)
         20       TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=71 us)
    151043       TABLE ACCESS FULL QR_PRODUCTION (cr=7961 pr=6396 pw=0 time=313553 us)
    462685    FILTER  (cr=10755862 pr=7094 pw=0 time=58570941 us)
    466790     HASH JOIN  (cr=145247 pr=7094 pw=0 time=11007301 us)
       1725      VIEW  index$_join$_014 (cr=24 pr=0 pw=0 time=6817 us)
       1725       HASH JOIN  (cr=24 pr=0 pw=0 time=5091 us)
       1725        INDEX FAST FULL SCAN USERS_PRIMARY (cr=7 pr=0 pw=0 time=35 us)(object id 55023)
       1725        INDEX FAST FULL SCAN USERS_PRODUCER (cr=17 pr=0 pw=0 time=19 us)(object id 55024)
    485205      HASH JOIN  (cr=145223 pr=7094 pw=0 time=10945107 us)
         20       TABLE ACCESS FULL CLASS (cr=7 pr=0 pw=0 time=105 us)
    507772       HASH JOIN  (cr=145216 pr=7094 pw=0 time=11947534 us)
       1396        TABLE ACCESS FULL PRODUCER (cr=107 pr=0 pw=0 time=18 us)
    507772        HASH JOIN  (cr=145109 pr=7094 pw=0 time=10924473 us)
    188967         TABLE ACCESS FULL PATIENT (cr=31792 pr=0 pw=0 time=188998 us)
    507772         HASH JOIN  (cr=113317 pr=7094 pw=0 time=9652037 us)
        895          TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=65 us)
    509321          TABLE ACCESS FULL TRX (cr=113271 pr=7094 pw=0 time=5604567 us)
       8548     TABLE ACCESS FULL USERS (cr=10610615 pr=0 pw=0 time=39053120 us)
      42669    NESTED LOOPS  (cr=507317 pr=0 pw=0 time=3686506 us)
      42669     NESTED LOOPS  (cr=421535 pr=0 pw=0 time=3217140 us)
      45269      NESTED LOOPS  (cr=301155 pr=0 pw=0 time=2449542 us)
      45323       NESTED LOOPS  (cr=210131 pr=0 pw=0 time=2134056 us)
      45323        HASH JOIN  (cr=119056 pr=0 pw=0 time=1635472 us)
         95         TABLE ACCESS FULL LLU_EVALUATION_DESCRIPTIONS (cr=7 pr=0 pw=0 time=118 us)
      98272         HASH JOIN  (cr=119049 pr=0 pw=0 time=1446703 us)
      46996          HASH JOIN  (cr=109018 pr=0 pw=0 time=944857 us)
        786           MERGE JOIN  (cr=50 pr=0 pw=0 time=1528 us)
         20            TABLE ACCESS BY INDEX ROWID CLASS (cr=4 pr=0 pw=0 time=99 us)
         20             INDEX FULL SCAN CLASS_PRIMARY (cr=1 pr=0 pw=0 time=10 us)(object id 53850)
        786            SORT JOIN (cr=46 pr=0 pw=0 time=750 us)
        895             TABLE ACCESS FULL PROCEDUR (cr=46 pr=0 pw=0 time=18 us)
      47196           TABLE ACCESS FULL TRX (cr=108968 pr=0 pw=0 time=805137 us)
    696300          TABLE ACCESS FULL GRADITEM (cr=10031 pr=0 pw=0 time=277 us)
      45323        TABLE ACCESS BY INDEX ROWID PRODUCER (cr=91075 pr=0 pw=0 time=414937 us)
      45323         INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=45752 pr=0 pw=0 time=198709 us)(object id 54581)
      45269       TABLE ACCESS BY INDEX ROWID GRADING (cr=91024 pr=0 pw=0 time=353081 us)
      45270        INDEX UNIQUE SCAN GRADING_PRIMARY (cr=45753 pr=0 pw=0 time=173185 us)(object id 54088)
      42669      TABLE ACCESS BY INDEX ROWID USERS (cr=120380 pr=0 pw=0 time=703786 us)
      42669       INDEX RANGE SCAN USERS_PRODUCER (cr=46127 pr=0 pw=0 time=249186 us)(object id 55024)
      42669     TABLE ACCESS BY INDEX ROWID PATIENT (cr=85782 pr=0 pw=0 time=407452 us)
      42669      INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=43098 pr=0 pw=0 time=198477 us)(object id 54370)
        176    TABLE ACCESS BY INDEX ROWID USERS (cr=49426 pr=0 pw=0 time=1783886 us)
        367     NESTED LOOPS  (cr=49149 pr=0 pw=0 time=6159428 us)
        190      NESTED LOOPS  (cr=48953 pr=0 pw=0 time=409391 us)
        190       NESTED LOOPS  (cr=48569 pr=0 pw=0 time=407105 us)
        190        NESTED LOOPS  (cr=48185 pr=0 pw=0 time=404820 us)
        191         NESTED LOOPS  (cr=47991 pr=0 pw=0 time=410291 us)
        193          NESTED LOOPS  (cr=47603 pr=0 pw=0 time=422507 us)
        193           NESTED LOOPS  (cr=46979 pr=0 pw=0 time=416890 us)
        193            NESTED LOOPS  (cr=46396 pr=0 pw=0 time=414374 us)
      14285             TABLE ACCESS FULL GRADITEM (cr=9602 pr=0 pw=0 time=85793 us)
        193             TABLE ACCESS BY INDEX ROWID TRX (cr=36794 pr=0 pw=0 time=128427 us)
       8218              INDEX UNIQUE SCAN TRX_PRIMARY (cr=28576 pr=0 pw=0 time=64353 us)(object id 54930)
        193            TABLE ACCESS BY INDEX ROWID TRX (cr=583 pr=0 pw=0 time=2169 us)
        193             INDEX UNIQUE SCAN TRX_PRIMARY (cr=390 pr=0 pw=0 time=918 us)(object id 54930)
        193           TABLE ACCESS BY INDEX ROWID GRADITEM (cr=624 pr=0 pw=0 time=4840 us)
       1547            INDEX RANGE SCAN GRADITEM_ID (cr=395 pr=0 pw=0 time=2910 us)(object id 54093)
        191          TABLE ACCESS BY INDEX ROWID GRADING (cr=388 pr=0 pw=0 time=1887 us)
        191           INDEX UNIQUE SCAN GRADING_PRIMARY (cr=197 pr=0 pw=0 time=943 us)(object id 54088)
        190         TABLE ACCESS BY INDEX ROWID CLASS (cr=194 pr=0 pw=0 time=1306 us)
        190          INDEX UNIQUE SCAN CLASS_PRIMARY (cr=4 pr=0 pw=0 time=551 us)(object id 53850)
        190        TABLE ACCESS BY INDEX ROWID PRODUCER (cr=384 pr=0 pw=0 time=1617 us)
        190         INDEX UNIQUE SCAN PRODUCER_PRIMARY (cr=194 pr=0 pw=0 time=715 us)(object id 54581)
        190       TABLE ACCESS BY INDEX ROWID PATIENT (cr=384 pr=0 pw=0 time=1941 us)
        190        INDEX UNIQUE SCAN PATIENT_PRIMARY (cr=194 pr=0 pw=0 time=939 us)(object id 54370)
        176      INDEX RANGE SCAN USERS_PRODUCER (cr=196 pr=0 pw=0 time=1389 us)(object id 55024)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                    6312        0.00          0.00
      db file scattered read                       1614        0.02          2.08
      SQL*Net message from client                  6312        0.00         10.11
      SQL*Net more data to client                 48662        0.00          0.70
      db file sequential read                      4645        0.02          7.11
      latch: shared pool                              7        0.00          0.00
      latch: cache buffers chains                     1        0.00          0.00
    ********************************************************************************Again, I apologize if this is way more information than is necessary.
    All advice/suggestions/assistance will be gratefully accepted.
    Carl

    Hi Rob,
    Thank you for replying. Here is the view definition . . . it looks pretty convoluted, I know.
    I am reporting from a database which I have no control over other than to add indexes where needed.
    For reporting purposes, I am needing to create the dataset from a number of different tables; hence all the UNION clauses.
    -- CODE FOLLOWS
    CREATE OR REPLACE VIEW LLU_V_PRODUCTION_DETAIL_03
    AS
    SELECT
      'QR' AS "Source",
      U1."User" AS "UserID",
      QRP."ProviderID" AS "ProviderID",
      P."LastName" AS "ProviderLastName",
      P."FirstName" AS "ProviderFirstName",
      TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
      P."PGroup",
      QRP."PatientID",
      QRP."ChartNumber",
      QRP."PatientLastName",
      QRP."PatientFirstName",
      QRP."ProcedureID" || '-' || QRP."ProcedureSuffix" AS "Procedure",
      QRP."ProcedureDescription",
      QRP."Tooth" AS "Site",
      QRP."Surface",
      QRP."axiUm_Discipline" AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name" AS "DisciplineName",
      QRP."Points",
      0 AS "Hours",
      QRP."ServiceDate",
      0 AS "Id",
      QRP."UniqueID" AS "Grading",
      0 AS "LastSort",
      QRP."CategoryID",
      '' AS "CPAR comments"
    FROM QR_PRODUCTION QRP
    INNER JOIN PRODUCER P
      ON TRIM(QRP."ProviderID") = TRIM(P."Producer")
    INNER JOIN CLASS
      ON TRIM(QRP."axiUm_Discipline") = TRIM(CLASS."Class")
    INNER JOIN USERS U1
      ON QRP."ProviderID" = U1."Producer"
    WHERE (QRP."Location" < '9990')
    AND (QRP."ProviderID" IS NOT NULL)
    AND (QRP."ProcedureID" <> 185)
    -- skip the Cavender family - training patients
    AND NOT (QRP."PatientLastName" LIKE 'CAVENDER%' AND QRP."PatientFirstName" = 'TED')
    AND QRP."PatientFirstName" <> 'NON-PATIENT'
    --ORDER BY QRP."ProcedureID"
    UNION ALL
    SELECT
      'axiUm TRX' AS "Source",
      U1."User" AS "UserID",
      TRX."Producer" AS "ProviderID",
      P."LastName",
      P."FirstName",
      TO_CHAR(P."EndDate",'YYYY') AS "GraduationYear",
      P."PGroup",
      PAT."Patient",
      PAT."Chart",
      PAT."Last" AS "PatientLastName",
      PAT."First" AS "PatientFirstName",
      TRX."Procedure",
      PROC."Description",
      TRX."Site",
      TRX."Surface",
      TRIM(PROC."Discipline") AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name",
      CASE WHEN
          ((TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179'))
          OR
          -- no points are to be awarded for any procedures performed on typodonts
          (EXISTS (SELECT 1 FROM PTTYPES PTT WHERE PTT."Patient" = PAT."Patient" and PTT."PatType" = 'TYPO' and PTT."Deleted" = 0)))
        AND  -- except for the following procedures
          (TRX."Procedure" NOT IN ('A0015','A0016','A0018','D0210'))
        THEN 0 ELSE PROC."RelValue" END AS "Points",
      CASE WHEN TRX."Procedure" IN ('A0013','A0019','A0020','A0021','A0023','A0024','A0025','A0026','A0027','A0028','A0029','A0030','O179')
        THEN PROC."RelValue" ELSE 0 END AS "Hours",
      TRX."TreatmentDate",
      TRX."Id",
      TRX."Grading",
      -1 AS "LastSort",
      -- additional link conditions added and table name changed on 1 July 2009 - cji
      SELECT "CategoryID" FROM LLU_CATEGORIES_X_PROCEDURES_03 LLU
      WHERE TRX."Procedure" = LLU."ProcedureID"
      AND TO_CHAR(P."EndDate",'YYYY') = LLU."GraduationYear"
      AND SUBSTR(TRX."Producer",1,1) = LLU."ProviderType"
      AND LLU."CategoryID" NOT IN (82)
      ) AS "CategoryID",
      '' AS "CPAR comments"
    FROM TRX
    INNER JOIN PATIENT PAT
      ON TRX."Patient" = PAT."Patient"
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    INNER JOIN PROCEDUR PROC
      ON TRX."Procedure" = PROC."Procedure"
    INNER JOIN CLASS
      ON PROC."Discipline" = CLASS."Class"
    INNER JOIN PRODUCER P
      ON TRX."Producer" = P."Producer"
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    --AND (TRX."Grading" = 0)
    AND (TRX."Procedure" NOT LIKE 'D0149%')
    AND (TRX."Procedure" <> 'D5001C')
    -- exclude all procedures approved by Peds faculty ONLY FOR CLASS OF 2011 AND LATER
    -- EXCEPT FOR the Peds Block code (A0021 and A0022) - always include those
    AND NOT
    TRX."AppUser" IN (SELECT "User" FROM USERS WHERE "Custom3" = 'YES') -- Peds faculty
    AND
    TO_CHAR(P."EndDate",'YYYY') >= '2011'
    AND
    TRIM(TO_CHAR(P."EndDate",'YYYY')) IS NOT NULL
    AND
    TRX."Procedure" NOT IN ('A0021','A0022')
    UNION ALL
    SELECT
      'axiUm GRADING' AS "Source",
      U1."User" AS "UserID",
      TRX."Producer" AS "ProviderID",
      P."LastName",
      P."FirstName",
      TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
      P."PGroup",
      PAT."Patient",
      PAT."Chart",
      PAT."Last" AS "PatientLastName",
      PAT."First" AS "PatientFirstName",
      TRX."Procedure",
      LLU."Description",
      TRX."Site",
      TRX."Surface",
      TRIM(PROC."Discipline") AS "Discipline",
      "CLASS"."Rank" AS "DisciplineSorter",
      "CLASS"."Name",
      LLU."Points", --LLU_POINTS_FROM_EVALUATIONS(TRX."Procedure", nvl(GI."Text",0)),
      0 AS "Hours",
      TRX."TreatmentDate",
      GI."Id",
      GI."Grading",
      GI."Row" AS "LastSort",
      LLU."CategoryID",
      '' AS "CPAR comments"
    FROM TRX
    INNER JOIN PATIENT PAT
      ON TRX."Patient" = PAT."Patient"
    INNER JOIN PRODUCER P
      ON TRX."Producer" = P."Producer"
    INNER JOIN GRADING G
      ON TRX."Grading" = G."Grading"
    INNER JOIN GRADITEM GI
      ON G."Grading" = GI."Grading"
      AND TRX."Type" = GI."Type"
      AND TRX."Id" = GI."Id"
      AND TRX."Treatment" = GI."Treatment"
    INNER JOIN PROCEDUR PROC
      ON TRX."Procedure" = PROC."Procedure"
    INNER JOIN CLASS
      ON PROC."Discipline" = CLASS."Class"
    INNER JOIN LLU_EVALUATION_DESCRIPTIONS LLU
      ON (TRIM(UPPER(GI."QuestionText")) = TRIM(UPPER(LLU."GRADITEM_QuestionText")))
      AND (TRIM(UPPER(GI."Text")) = TRIM(UPPER(LLU."GRADITEM_Text")))
      AND (TRIM(TRX."Procedure") = TRIM(LLU."ProcedureCode"))
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    AND (TRX."Grading" <> 0)
    AND (G."Deleted" = 0)
    UNION ALL
    SELECT 'ClinPtsAdj',
      U1."User" AS "UserID",
      TRX."Producer",
      P."LastName", P."FirstName",
      TO_CHAR(P."EndDate",'YYYY'), -- Graduation year
      P."PGroup", PAT."Patient", PAT."Chart", PAT."Last", PAT."First",
      TRX."Procedure",
      'Clinic points adjustment',
      '' AS "Site",
      '' AS "Surface",
      TRIM(TRX."Discipline"),
      "CLASS"."Rank",
      "CLASS"."Name",
      DERIVED."Points",
      0 AS "Hours",
      GI."Date",
      GI."Id",
      GI."Grading",
      GI."Row",
      NULL AS "CategoryID",
      TRIM(REPLACE(GI."Note", CHR(13) || CHR(10), ' '))
    FROM TRX
    INNER JOIN PATIENT PAT
      ON (TRX."Patient" = PAT."Patient")
    INNER JOIN PRODUCER P
      ON (TRX."Producer" = P."Producer")
    INNER JOIN CLASS
      ON (TRX."Discipline" = CLASS."Class")
    INNER JOIN GRADING G
      ON (TRX."Grading" = G."Grading")
    INNER JOIN GRADITEM GI
      ON (GI."Grading" = G."Grading")
      AND (GI."Type" = TRX."Type")
      AND (GI."Id" = TRX."Id")
      AND (GI."Treatment" = TRX."Treatment")
    INNER JOIN USERS U1
      ON TRX."Producer" = U1."Producer"
    INNER JOIN
      SELECT TRX."Type", TRX."Id", TRX."Treatment", TRX."Grading",
        CASE WHEN TRX."Procedure" = 'G1003' THEN GI."RelValue" * -1 ELSE "RelValue" END AS "Points"
      FROM TRX, GRADITEM GI
      WHERE (TRX."Type" = GI."Type")
      AND (TRX."Id" = GI."Id")
      AND (TRX."Treatment" = GI."Treatment")
      AND (TRX."Procedure" IN ('G1002','G1003'))
      AND (TRX."Status" = 'C')
      AND (TRX."Deleted" = 0)
      AND (TRX."Grading" <> 0)
      AND (GI."RelValue" <> 0)
      ) DERIVED
      ON (TRX."Type" = DERIVED."Type")
      AND (TRX."Id" = DERIVED."Id")
      AND (TRX."Treatment" = DERIVED."Treatment")
      AND (TRX."Grading" = DERIVED."Grading")
    WHERE (TRX."Status" = 'C')
    AND (TRX."Deleted" = 0)
    AND (TRX."Grading" <> 0)
    AND (G."Deleted" = 0)
    AND (TRX."Procedure" IN ('G1002','G1003'))
    AND (GI."IsHeading" = 3)
    AND (TRIM(GI."QuestionText") = 'Comments')
    --ORDER BY "ProviderID", "DisciplineSorter", "Id", "Grading", "Site", "LastSort";A couple of additional points:
    The table USERS already had an index on column "Producer"; I added an index on column "Custom3" but it did not seem to make any difference.
    Table USERS has 1,725 rows
    Table PRODUCER (aliased as P) has 1,396 rows
    Table TRX has 1,443,764 rows.
    Any additional information you need I will be glad to provide.
    Thanks a bunch; it may not be too late to teach an old dog new tricks.
    And thank you all for the kind words about the posting; about the only thing I can do well is follow directions.
    Carl

  • Please reply for the query tuning

    Hi, i am a beginner in oracle dba, I have to know if i have studied little bit about query tuning in ORACLE.
    I wanna know if i have the following query and its plan then how it can be tuned:
    QUERY:
              SELECT z.emplid ,h.first_name || ' ' || h.last_name  ,z.grade ,z.DEPTID ,z.LOCATION
                              FROM sysadm.ps_lnt_latestbu_vw z, sysadm.ps_personal_data h
                                    WHERE  z.empl_status ='A'    --index access
                                    AND z.emplid = h.emplid      --join
                                    and z.emplid not in   (select g.emplid from sysadm.ps_lnt_asn_skl_tbl g)    --join
                                    and z.Business_unit=
                                                               (      select l.lnt_subunit from sysadm.ps_position_data l where l.position_nbr in
                                                                                                    ( select b.position_nbr from sysadm.ps_job b,sysadm.psoprdefn y
                                                                                                              where b.effdt=(     select max(g.effdt) from sysadm.ps_job g
                                                                                                                                            where g.emplid=b.emplid           --join costs high
                                                                                                                                                and g.effdt<=SYSDATE)               --filter/index
                                                                                                                    and b.effseq=
                                                                                                                             (select max(h.effseq) from sysadm.ps_job h
                                                                                                                                       where h.emplid=b.emplid           --join costs high
                                                                                                                                      and h.effdt=b.effdt)               --join costs high
                                                                                                                and b.empl_rcd=0          --filter/index access
                                                                                                                and y.EMPLID=b.EMPLID  --join
                                                                                                                and y.OPRID='1112'   -- filter/index access
                                               order by z.emplid
                                            /AND its plan is:
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=6 Card=1 Bytes=64)
       1    0   SORT (ORDER BY) (Cost=6 Card=1 Bytes=64)
       2    1     NESTED LOOPS (ANTI) (Cost=4 Card=1 Bytes=64)
       3    2       NESTED LOOPS (Cost=3 Card=1 Bytes=56)
       4    3         VIEW OF 'PS_LNT_LATESTBU_VW' (Cost=2 Card=1 Bytes=31)
       5    4           UNION-ALL
       6    5             CONCATENATION
       7    6               TABLE ACCESS (BY INDEX ROWID) OF 'PS_POSITION_DATA' (Cost=5 Card=90 Bytes=1890)
       8    7                 NESTED LOOPS
       9    8                   NESTED LOOPS (Cost=275 Card=1 Bytes=90)
      10    9                     NESTED LOOPS (Cost=275 Card=1 Bytes=82)
      11   10                       TABLE ACCESS (BY INDEX ROWID) OF 'PS_JOB' (Cost=3 Card=1 Bytes=50)
      12   11                         INDEX (RANGE SCAN) OF 'PS2JOB' (NON-UNIQUE) (Cost=2 Card=1)
      13   12                           SORT (AGGREGATE)
      14   13                             FIRST ROW (Cost=3 Card=1 Bytes=19)
      15   14                               INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      16   12                           SORT (AGGREGATE)
      17   16                             FIRST ROW (Cost=3 Card=1 Bytes=22)
      18   17                               INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      19   10                       INDEX (UNIQUE SCAN) OF 'PS_EMPLOYMENT'(UNIQUE)
      20    9                     INDEX (UNIQUE SCAN) OF 'PS_PERSONAL_DATA' (UNIQUE)
      21    8                   INDEX (RANGE SCAN) OF 'PS_POSITION_DATA' (UNIQUE) (Cost=5 Card=90)
      22    6               FILTER
      23   22                 NESTED LOOPS (Cost=275 Card=1 Bytes=90)
      24   23                   NESTED LOOPS (Cost=275 Card=1 Bytes=82)
      25   24                     NESTED LOOPS (Cost=275 Card=1 Bytes=71)
      26   25                       INDEX (FAST FULL SCAN) OF 'PS8POSITION_DATA' (NON-UNIQUE) (Cost=5 Card=90 Bytes=1890)
      27   25                       TABLE ACCESS (BY INDEX ROWID) OF 'PS_JOB' (Cost=3 Card=1 Bytes=50)
      28   27                         INDEX (RANGE SCAN) OF 'PS2JOB' (NON-UNIQUE) (Cost=2 Card=1)
      29   28                           SORT (AGGREGATE)
      30   29                             FIRST ROW (Cost=3 Card=1 Bytes=22)
      31   30                               INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      32   28                           SORT (AGGREGATE)
      33   32                             FIRST ROW (Cost=3 Card=1 Bytes=19)
      34   33                               INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      35   24                     INDEX (UNIQUE SCAN) OF 'PS_EMPLOYMENT' (UNIQUE)
      36   23                   INDEX (UNIQUE SCAN) OF 'PS_PERSONAL_DATA'(UNIQUE)
      37   22                 SORT (AGGREGATE)
      38   37                   FIRST ROW (Cost=2 Card=1 Bytes=17)
      39   38                     INDEX (RANGE SCAN (MIN/MAX)) OF 'PS_POSITION_DATA' (UNIQUE) (Cost=2 Card=9000)
      40    5             FILTER
      41   40               NESTED LOOPS (Cost=751 Card=1 Bytes=191)
      42   41                 NESTED LOOPS (OUTER) (Cost=750 Card=1 Bytes=167)
      43   42                   NESTED LOOPS (OUTER) (Cost=749 Card=1 Bytes=143)
      44   43                     NESTED LOOPS (Cost=748 Card=1 Bytes=134)
      45   44                       NESTED LOOPS (Cost=748 Card=1 Bytes=123)
      46   45                         NESTED LOOPS (Cost=748 Card=1 Bytes=119)
      47   46                           NESTED LOOPS (Cost=747 Card=1 Bytes=98)
      48   47                             NESTED LOOPS (Cost=744 Card=1 Bytes=62)
      49   48                               NESTED LOOPS (Cost=744 Card=1Bytes=54)
      50   49                                 VIEW OF 'PS_LNTPRJOBSYSJRVW'(Cost=741 Card=1 Bytes=9)
      51   50                                   FILTER
      52   51                                     NESTED LOOPS (OUTER) (Cost=735 Card=1 Bytes=68)
      53   52                                       NESTED LOOPS (Cost=734Card=1 Bytes=51)
      54   53                                         NESTED LOOPS (Cost=734 Card=1 Bytes=43)
      55   54                                           TABLE ACCESS (BY INDEX ROWID) OF 'PS_JOB' (Cost=734 Card=1 Bytes=32)
      56   55                                             INDEX (RANGE SCAN) OF 'PSCJOB' (NON-UNIQUE) (Cost=206 Card=1013)
      57   54                                           INDEX (UNIQUE SCAN) OF 'PS_EMPLOYMENT' (UNIQUE)
      58   53                                         INDEX (UNIQUE SCAN) OF 'PS_PERSONAL_DATA' (UNIQUE)
      59   52                                       INDEX (RANGE SCAN) OF'PS_POSITION_DATA' (UNIQUE) (Cost=1 Card=1 Bytes=17)
      60   51                                     SORT (AGGREGATE)
      61   60                                       FIRST ROW (Cost=3 Card=1 Bytes=19)
      62   61                                         INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      63   51                                     SORT (AGGREGATE)
      64   63                                       FIRST ROW (Cost=3 Card=1 Bytes=22)
      65   64                                         INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      66   51                                     SORT (AGGREGATE)
      67   66                                       FIRST ROW (Cost=2 Card=1 Bytes=17)
      68   67                                         INDEX (RANGE SCAN (MIN/MAX)) OF 'PS_POSITION_DATA' (UNIQUE) (Cost=2 Card=9000)
      69   49                                 TABLE ACCESS (BY INDEX ROWID) OF 'PS_JOB' (Cost=3 Card=1 Bytes=45)
      70   69                                   INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE) (Cost=2 Card=1)
      71   70                                     SORT (AGGREGATE)
      72   71                                       INDEX (RANGE SCAN) OF'PSAJOB' (NON-UNIQUE) (Cost=3 Card=1 Bytes=19)
      73   72                                         SORT (AGGREGATE)
      74   73                                           FIRST ROW (Cost=3Card=8 Bytes=88)
      75   74                                             INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=25963)
      76   70                                     SORT (AGGREGATE)
      77   76                                       FIRST ROW (Cost=3 Card=8 Bytes=88)
      78   77                                         INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=25963)
      79   48                               INDEX (UNIQUE SCAN) OF 'PS_PERSONAL_DATA' (UNIQUE)
      80   47                             TABLE ACCESS (BY INDEX ROWID) OF'PS_JOB' (Cost=3 Card=1 Bytes=36)
      81   80                               INDEX (RANGE SCAN) OF 'PSAJOB'(NON-UNIQUE) (Cost=2 Card=1)
      82   81                                 SORT (AGGREGATE)
      83   82                                   FIRST ROW (Cost=3 Card=1 Bytes=19)
      84   83                                     INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      85   81                                 SORT (AGGREGATE)
      86   85                                   FIRST ROW (Cost=3 Card=1 Bytes=22)
      87   86                                     INDEX (RANGE SCAN (MIN/MAX)) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=207700)
      88   46                           INDEX (RANGE SCAN) OF 'PS8POSITION_DATA' (NON-UNIQUE) (Cost=1 Card=1 Bytes=21)
      89   45                         INDEX (UNIQUE SCAN) OF 'PS_BUS_UNIT_TBL_HR' (UNIQUE)
      90   44                       INDEX (UNIQUE SCAN) OF 'PS_EMPLOYMENT'(UNIQUE)
      91   43                     INDEX (RANGE SCAN) OF 'PS_POSITION_DATA'(UNIQUE) (Cost=1 Card=1 Bytes=9)
      92   42                   INDEX (FULL SCAN) OF 'PS0LOCATION_TBL' (NON-UNIQUE) (Cost=1 Card=1 Bytes=24)
      93   41                 INDEX (RANGE SCAN) OF 'PS0LOCATION_TBL' (NON-UNIQUE) (Cost=1 Card=1 Bytes=24)
      94   40               SORT (AGGREGATE)
      95   94                 FIRST ROW (Cost=2 Card=1 Bytes=17)
      96   95                   INDEX (RANGE SCAN (MIN/MAX)) OF 'PS_POSITION_DATA' (UNIQUE) (Cost=2 Card=9000)
      97    4           TABLE ACCESS (BY INDEX ROWID) OF 'PS_POSITION_DATA' (Cost=2 Card=1 Bytes=13)
      98   97             NESTED LOOPS (Cost=9 Card=1 Bytes=19)
      99   98               VIEW OF 'VW_NSO_1' (Cost=5 Card=1 Bytes=6)
    100   99                 SORT (UNIQUE)
    101  100                   NESTED LOOPS (Cost=5 Card=1 Bytes=44)
    102  101                     TABLE ACCESS (BY INDEX ROWID) OF 'PSOPRDEFN' (Cost=2 Card=1 Bytes=14)
    103  102                       INDEX (UNIQUE SCAN) OF 'PS_PSOPRDEFN'(UNIQUE) (Cost=1 Card=1)
    104  101                     TABLE ACCESS (BY INDEX ROWID) OF 'PS_JOB' (Cost=3 Card=1 Bytes=30)
    105  104                       INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE) (Cost=2 Card=1)
    106  105                         SORT (AGGREGATE)
    107  106                           INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=8 Bytes=128)
    108  105                         SORT (AGGREGATE)
    109  108                           INDEX (RANGE SCAN) OF 'PSAJOB' (NON-UNIQUE) (Cost=3 Card=1 Bytes=19)
    110   98               INDEX (RANGE SCAN) OF 'PS_POSITION_DATA' (UNIQUE) (Cost=1 Card=1)
    111    3         TABLE ACCESS (BY INDEX ROWID) OF 'PS_PERSONAL_DATA'(Cost=1 Card=1 Bytes=25)
    112  111           INDEX (UNIQUE SCAN) OF 'PS_PERSONAL_DATA' (UNIQUE)
    113    2       INDEX (RANGE SCAN) OF 'PS_LNT_ASN_SKL_TBL' (UNIQUE) (Cost=1 Card=10076 Bytes=80608)
    Statistics
             70  recursive calls
              0  db block gets
        1186931  consistent gets
           5660  physical reads
             60  redo size
            462  bytes sent via SQL*Net to client
            373  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
              0  rows processedMy thoughts for this is:
    1. NLJ high cost -- rewrite inner sub-query
    2. sort is done for each join for max function every time so,     therefore try use use sort merge hint
    3. h           alias has been referenced twice for table name.
    PLEASE TELL ME WHAT TO DO IF I AM ORACLE DBA.
    Thanks in advance.
    Edited by: user2060331 on Mar 25, 2010 9:17 AM
    Edited by: user2060331 on Mar 25, 2010 9:21 AM
    Edited by: user2060331 on Mar 25, 2010 9:32 AM
    Edited by: user2060331 on Mar 25, 2010 9:47 AM

    No it's not. You should see indentations for each level of the explain plan. You've lost all of it. It should look like this (not your query):
    PLAN_TABLE_OUTPUT
    | Id  | Operation                   | Name                | Rows  | Bytes | Cost  | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT            |                     | 16116 |  2911K|   712 |        |      |
    |   1 |  FILTER                     |                     |       |       |       |        |      |
    |   2 |   CONNECT BY WITH FILTERING |                     |       |       |       |        |      |
    |   3 |    FILTER                   |                     |       |       |       |        |      |
    |   4 |     COUNT                   |                     |       |       |       |        |      |
    |   5 |      HASH JOIN RIGHT OUTER  |                     | 16116 |  2911K|   712 |        |      |
    |   6 |       REMOTE                | LSW_USR_GRP_XREF    |   518 | 13986 |     4 | MYPROJ~ | R->S |
    |   7 |       HASH JOIN RIGHT OUTER |                     | 16116 |  2486K|   707 |        |      |
    |   8 |        REMOTE               | LSW_USR_XREF        |   222 |  2886 |     4 | MYPROJ~ | R->S |
    |   9 |        HASH JOIN RIGHT OUTER|                     | 16116 |  2282K|   702 |        |      |
    |  10 |         TABLE ACCESS FULL   | MYPROJ_PROCESS_MAP   |   176 |  4752 |     4 |        |      |
    |  11 |         HASH JOIN OUTER     |                     | 16116 |  1857K|   698 |        |      |
    |  12 |          TABLE ACCESS FULL  | MYPROJ_MPPA | 16116 |  1243K|    71 |        |      |
    |  13 |          REMOTE             | LSW_TASK            | 80730 |  3074K|   625 | MYPROJ~ | R->S |
    |  14 |    HASH JOIN                |                     |       |       |       |        |      |
    |  15 |     CONNECT BY PUMP         |                     |       |       |       |        |      |
    |  16 |     COUNT                   |                     |       |       |       |        |      |
    |  17 |      HASH JOIN RIGHT OUTER  |                     | 16116 |  2911K|   712 |        |      |
    |  18 |       REMOTE                | LSW_USR_GRP_XREF    |   518 | 13986 |     4 | MYPROJ~ | R->S |
    |  19 |       HASH JOIN RIGHT OUTER |                     | 16116 |  2486K|   707 |        |      |
    |  20 |        REMOTE               | LSW_USR_XREF        |   222 |  2886 |     4 | MYPROJ~ | R->S |
    |  21 |        HASH JOIN RIGHT OUTER|                     | 16116 |  2282K|   702 |        |      |
    |  22 |         TABLE ACCESS FULL   | MYPROJ_PROCESS_MAP   |   176 |  4752 |     4 |        |      |
    |  23 |         HASH JOIN OUTER     |                     | 16116 |  1857K|   698 |        |      |
    |  24 |          TABLE ACCESS FULL  | MYPROJ_MPPA | 16116 |  1243K|    71 |        |      |
    |  25 |          REMOTE             | LSW_TASK            | 80730 |  3074K|   625 | MYPROJ~ | R->S |
    ---------------------------------------------------------------------------------------------------

  • Query performance using distinct

    Greetings! We're on Oracle 8.1.7, Solaris 2.8.
    I have a query that utilizes a different access path if I use the word distinct in the select from this view. Here is our query:
    SELECT
    DISTINCT SETID,
    VENDOR_ID,
    VENDOR_NAME_SHORT,
    AR_NUM,
    NAME1,
    ADDRESS1,
    ADDRESS2,
    CITY
    FROM
    PS_VENDOR_VW
    WHERE
    SETID LIKE 'MNSA' AND
    NAME1='FUN' ORDER BY NAME1, SETID, VENDOR_ID
    The view SQL is:
    SELECT /*+ FIRST_ROWS */ a.setid
    , a.vendor_name_short
    , a.name1
    , c.address1
    , c.address2
    , c.city
    , a.vendor_id
    FROM SYSADM.ps_vendor a
    SELECT /*+ INDEX_ASC(B PSAVENDOR_ADDR) */
    FROM SYSADM.ps_vendor_addr b
    WHERE b.effdt = (
    SELECT MAX(effdt)
    FROM SYSADM.ps_vendor_addr
    WHERE setid = b.setid
    AND vendor_id = b.vendor_id
    AND address_seq_num = b.address_seq_num
    AND effdt <= sysdate)) c
    WHERE a.setid = c.setid (+)
    AND a.vendor_id = c.vendor_id (+)
    AND a.prim_addr_seq_num=c.address_seq_num (+)
    This query does an index full scan on an index for ps_vendor_addr. It takes 2+ minutes to run. Now, if I remove the word distinct, it uses an index range scan and "view pushed predicate". It runs in 2 seconds.
    I've tried with and without the first_rows hint in the view. If I leave off the INDEX_ASC hint then it does a full table scan of table ps_vendor_addr. It refuses to do a range scan with the hint. Can anybody tell me how I can get the 'distinct' query tuned?
    2 minutes may not seem like a lot but when online users run the query many times a day, it is very frustrating.
    Thanks! I hope I provided enough info.

    Thomas:
    The different behaviours you are seeing are a result of the DISTINCT in the query. This causes a sort to be performed, and will influence the way that the CBO will execute the query. (You do know that you are using the Cost Based Optimizer because of the hints, and that you should analyze the tables and indexes?) You need to be able to re-write the view to avoid the need for the DISTINCT in the query.
    Without knowing the meaning of the fields, it is really hard to say anything meaningful, but my guess is that it is the correlated sub-query that is ultimately causing the need for the DISTINCT. Is the combination of set_id,vendor_id and address_seq_num truly unique, or is the address_seq_num just a sequence.
    For example in one of my databases, I have a table with INDV_ID, EFF_DT, EMPSTAT_SEQ. The empstat_seq field is just there to allow for more than one thing happening on the same day. The way we query this table is:
    SELECT *
    FROM empstat_t a
    WHERE indv_id = :emp_id and
          TO_CHAR(eff_dt,'yyyymmdd')||TO_CHAR(empstat_seq,'009') =
                  (SELECT MAX(TO_CHAR(eff_dt,'yyyymmdd')||TO_CHAR(empstat_seq,'009')
                   FROM empstat_t
                   WHERE a.indv_id = indv_id);Could something similar work in your case?
    If not, assuming your statistics are up to date, I would also look at creating the view without hints to see what the optimizer comes up with on its own. It may be better than you think.
    TTFN
    John

  • Query tuning : you can do it yourself

    Hello,
    This thread is not a question.
    How tune my query ?
    My query didn't use indexes why ?
    I have indexes on table, stats are up-to-date why Oracle does a full scan on table ?
    What are the hint which I can use ?
    etc...
    I would like try to answer to many such questions posted in this forum about query tuning.
    And explain that tuning is not always complicated, is not always reserved to some consultants, is not always solved by hints usage, and not require to buy some books which would give some magic solutions.
    By this thread, I would explain to people which have some query performance issues, that the solution is maybe here, in front of their eyes, inside the query itself. The solution may come from their own side, and that they can be happy to solve such question themself.
    I'll develop here below a case from a real word situation encountered some time ago.

    At this point, remove this huge and nightmarish hint. We'll use it only if no other ways may found.
    First, a look into the data model to see if the joins may be rewrite differently.
    Original joins :
        dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID and
        dw.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID and
        dw.REGION_ROUTING_ID = rr.REGION_ROUTING_ID and
        dw.CITY_ROUTING_ID  = cr.CITY_ROUTING_ID andAnd indeed, the join may be rewrite as below :
        and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
        and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
        and cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
        and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_IDNote the aliases were change here. Is it complicated to try to rewrite query like that ?
    Secondly, we will try to see how avoid or, at least, workaround the all OR conditions. It would be well if we could merge all the FROM (bind variable :a) in one column, same for all TO (bind variable :b), unfortunately, the data model cannot be change (of course). Ok, we will try to work with a temporary table by combining all the possiblities between the two conditions.
    create global temporary table REGION_ROUTING_TMP
    on commit preserve rows
    as
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    where  1=2;And an index based on the two mains criteria of the query may help :
    create index IDX_REGION_ROUTING_TMP on REGION_ROUTING_TMP(REGION_FROM,REGION_TO);Then we'll populate table :
    insert into REGION_ROUTING_TMP
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP3 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING;The insert take near 9 seconds, which is a reasonnable elapse time.
    At this point, the query become :
    Select
       ap.AIRPORT_PAIR,  
       dw.DELIVERY_PERIOD,
       dw.TOTAL_PAX As Demand,
       od.GLOBAL_TOTAL_PAX as Total_OD_Demand,
       dw.REPORTED_PAX As ReportedPax,
       ap.AIRPORT_FROM,
       ap.AIRPORT_TO,
       ap.CITY_FROM,
       ap.CITY_TO,
       ap.COUNTRY_FROM_NAME,
       ap.COUNTRY_TO_NAME,
       ap.REGION_FROM_NAME,
       ap.REGION_TO_NAME,
       ar.AIRPORT_ROUTING,
       cr.CITY_ROUTING,
       cor.COUNTRY_ROUTING_NAMES,
       rr.REGION_ROUTING_NAMES,
       ar.NUMBER_OF_STOP,
       dw.PERCENT_OF_TOTAL_PAX_VS_OD,
       dw.AIRLINE1,
       dw.AIRLINE2,
       dw.AIRLINE3,
       dw.AIRLINE4,
       dw.NUMBER_OF_AIRLINE,
       dw.AIRCRAFTCLASS_NAME,
       dw.FARE
    From
       REGION_ROUTING_TMP rr, -- here we use now the temporary table instead of REGION_ROUTING table
       DETAILED_FLIGHTS dw,
       AIRPORT_PAIR ap,
       AIRPORT_ROUTING ar,
       CITY_ROUTING cr,
       COUNTRY_ROUTING cor,
       OD od
    where
            dw.DELIVERY_PERIOD  in ('2006-09','2006-08','2006-07')
    and dw.AIRPORT_PAIR_ID    = ap.AIRPORT_PAIR_ID
    and dw.OD_ID              = od.OD_ID
    and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
    and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
    and     cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
    and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_ID
    and rr.REGION_FROM        = '7'  |
    and rr.REGION_TO          = '8'  |-> these two lines replace all the OR conditions;And explain plan :
    | Id  | Operation                             |  Name                          | Rows  | Bytes | Cost  | Pstart| Pstop |
    |   0 | SELECT STATEMENT                      |                                |   469 |   174K|  3462 |       |       |
    |   1 |  NESTED LOOPS                         |                                |   469 |   174K|  3462 |       |       |
    |   2 |   NESTED LOOPS                        |                                |   458 |   166K|  3004 |       |       |
    |   3 |    NESTED LOOPS                       |                                |   454 |   127K|  2096 |       |       |
    |   4 |     NESTED LOOPS                      |                                |   258 | 58308 |   548 |       |       |
    |   5 |      NESTED LOOPS                     |                                |   246 | 48216 |    56 |       |       |
    |   6 |       NESTED LOOPS                    |                                |    26 |  4420 |     4 |       |       |
    |   7 |        TABLE ACCESS BY INDEX ROWID    | REGION_ROUTING_TMP             |     1 |   123 |   
    |*  8 |         INDEX RANGE SCAN              | IDX_REGION_ROUTING_TMP         |     1 |       |     1 |       | 
    |   9 |        TABLE ACCESS BY INDEX ROWID    | COUNTRY_ROUTING                |    32 |  1504 |     2
    |* 10 |         INDEX RANGE SCAN              | IX9_COUNTRY_ROUTING            |    32 |       |     1 |       | 
    |  11 |       TABLE ACCESS BY INDEX ROWID     | CITY_ROUTING                   |     9 |   234 |     2 | 
    |* 12 |        INDEX RANGE SCAN               | IX9_CITY_ROUTING               |    12 |       |     1 |    
    |  13 |      TABLE ACCESS BY INDEX ROWID      | AIRPORT_ROUTING                |     1 |    30 |     2
    |* 14 |       INDEX RANGE SCAN                | IX10_AIRPORT_ROUTING           |     1 |       |     1 |   
    |* 15 |     TABLE ACCESS BY GLOBAL INDEX ROWID| DETAILED_FLIGHTS               |     2 |   122 |   
    |* 16 |      INDEX RANGE SCAN                 | IX3_DETAILED_FLIGHTS           |     9 |       |     2 |    
    |  17 |    TABLE ACCESS BY INDEX ROWID        | AIRPORT_PAIR                   |     1 |    85 |     2 |  
    |* 18 |     INDEX RANGE SCAN                  | IX1_AIRPORT_PAIR               |     1 |       |     1 |       |
    |  19 |   TABLE ACCESS BY INDEX ROWID         | OD                             |     1 |    10 |     1 |       |   
    |* 20 |    INDEX UNIQUE SCAN                  | PK_OD                          |     1 |       |       |       |       |
    ----------------------------------------------------------------------------------------------------Ouf, this sound like better, isn't it ? Was it complicated to arrive as such result ?
    Ok, now launch the query and see the elapse time :
    104103 rows selected.
    Elapsed: 00:09:00.12
    Statistics
              0  recursive calls
              0  db block gets
        1214845  consistent gets
         272481  physical reads
              0  redo size
       11164355  bytes sent via SQL*Net to client
         257032  bytes received via SQL*Net from client
           6942  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedWoaw, developer is now very happy, less than 10 minutes instead of one hour... and without modify anything else in database and server settings, without add indexes, without add any hints...
    Ok, now the problem is in the number of returned lines. Have you see the number of return client/server ? We'll now to try to reduce this one. Increasing the number of line returned by fetch :
    set arraysize 5000
    --run the query
    104103 rows selected.
    Elapsed: 00:02:25.49
    Statistics
              0  recursive calls
              0  db block gets
        1150893  consistent gets
         271432  physical reads
              0  redo size
       11018641  bytes sent via SQL*Net to client
           1013  bytes received via SQL*Net from client
             22  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedOk, the number of retunr client/server is now low, and elapse time is ok user.

Maybe you are looking for