Help on tuning SQL
Hi list ,
I need your help in tuning this sql.
Oracle 10g,Windows 2008 64 bit running on virtual machine.
SELECT t0.RecID, t0.PrtID, t0.RecOrdDt, t0.RecOrdID, t0.RecExtOrdID, t0.RecPocID, t0.PriID, t0.CasID, t0.CasNo, t0.CasClass, t0.CasPocID, t0.CasAdmit, t0.CasNotValid, t0.PatName, t0.PatFName, t0.PatBName, t0.PatBDate, t0.PatSex, t0.PatNotValid, t0.RstID, t0.RstState, t0.RstMeaningI18N, t0.PrtType, t0.PrtSubType, t0.RpxType, t0.RpxPrio, t0.PerID, t0.PerName, t0.PerFName, t0.PerTitle, t0.PerType, t0.AgnExtID
FROM
IXSERV.XsvRecPerInfoV t0
WHERE
((((t0.AgnExtID = '1728454694') AND (t0.PrtID IN (72, 165)))
AND (t0.RpxType IN (1, 2, 6, 3, 5)))
AND (t0.RstState IN (202, 208, 210, 203, 206)))
call count cpu elapsed disk query current rows
Parse 1 0.04 0.03 0 1999 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 4 5.39 57.42 45408 53080 0 45
total 6 5.43 57.46 45408 55079 0 45
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows Row Source Operation
45 NESTED LOOPS (cr=53080 pr=45408 pw=0 time=2611987 us)
45 NESTED LOOPS (cr=52941 pr=45355 pw=0 time=46145568 us)
45 HASH JOIN (cr=52802 pr=45314 pw=0 time=45407144 us)
1 TABLE ACCESS BY INDEX ROWID PERPERSON (cr=3 pr=6 pw=0 time=40510 us)
1 INDEX RANGE SCAN PERIDXAGNEXTID (cr=2 pr=5 pw=0 time=22311 us)(object id 56817)
23623 TABLE ACCESS BY INDEX ROWID XSVRECPERXREF (cr=52799 pr=45308 pw=0 time=50046345 us)
33893 NESTED LOOPS (cr=47543 pr=42261 pw=0 time=73003406 us)
5139 HASH JOIN (cr=37184 pr=40103 pw=0 time=56090695 us)
5 TABLE ACCESS FULL XMFREPORTSTATE (cr=7 pr=6 pw=0 time=22565 us)
66900 TABLE ACCESS BY INDEX ROWID XSVPATIENTRECORD (cr=37177 pr=40097 pw=0 time=39887547 us)
66903 NESTED LOOPS (cr=146 pr=141 pw=0 time=8095232 us)
2 INLIST ITERATOR (cr=4 pr=3 pw=0 time=37200 us)
2 TABLE ACCESS BY INDEX ROWID XMFPATIENTRECORDTYPE (cr=4 pr=3 pw=0 time=37198 us)
2 INDEX UNIQUE SCAN PKPRT (cr=2 pr=1 pw=0 time=26746 us)(object id 56143)
66900 INDEX RANGE SCAN RECIDXPRTID (cr=142 pr=138 pw=0 time=51513 us)(object id 56410)
28753 INDEX RANGE SCAN RPXIDXRECID (cr=10359 pr=2158 pw=0 time=4518986 us)(object id 56453)
45 TABLE ACCESS BY INDEX ROWID ADTCASE (cr=139 pr=41 pw=0 time=423483 us)
45 INDEX UNIQUE SCAN PK_ADTCASE (cr=94 pr=23 pw=0 time=184866 us)(object id 55295)
45 TABLE ACCESS BY INDEX ROWID ADTPATIENT (cr=139 pr=53 pw=0 time=413067 us)
45 INDEX UNIQUE SCAN PK_ADTPATIENT (cr=94 pr=21 pw=0 time=195583 us)(object id 55361)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net break/reset to client 2 0.00 0.00
SQL*Net message to client 5 0.00 0.00
SQL*Net message from client 5 114.42 128.67
SQL*Net more data to client 1 0.00 0.00
db file sequential read 27969 0.13 51.57
db file scattered read 3271 0.05 4.61
Some lines from trace fils :
WAIT #1: nam='db file sequential read' ela= 12778 file#=4 block#=3726132 blocks=1 obj#=56817 tim=249799016372
WAIT #1: nam='db file scattered read' ela= 9271 file#=4 block#=3726133 blocks=4 obj#=56817 tim=249799025761
WAIT #1: nam='db file sequential read' ela= 18141 file#=4 block#=587487 blocks=1 obj#=55853 tim=249799043945
WAIT #1: nam='db file sequential read' ela= 18304 file#=4 block#=752595 blocks=1 obj#=56219 tim=249799062471
and the view XsvRecPerInfoV is :
SELECT d.RecID, d.PrtID, d.RecOrdDt, d.RecOrdID, d.RecExtOrdID, d.PocID, d.PriID, c.CasID, c. CasNo, c.CasClass, c.PocID, c.CasAdmit, c.CasNotValid, p.PatName, p.PatFName, p.PatBName, p.PatBDate, p.PatSex, p.PatNotValid, r.RstID, r.RstState, r.RstMeaningI18N, prt.PrtType, prt.PrtSubType, x.RpxType, x.RpxPrio, per.PerID, per.PerName, per.PerFName, per.PerTitle, per.PerType, per.AgnExtID
FROM XsvPatientRecord d,
AdtCase c,
AdtPatient p,
XmfReportState r,
XmfPatientRecordType prt,
XsvRecPerXRef x,
PerPerson per
WHERE
d.RecID = x.RecID
AND d.RstID = r.RstID
AND d.PrtID = prt.PrtID
AND d.CasID = c.CasID
AND x.PerID = per.PerID
AND c.PatID = p.PatID
i have two questions :
-1 The problem in tables XSVPATIENTRECORD and XSVRECPERXREF so how can i speed this query either by rewriting it or indexs?
-2 is my system i-o is slow ?
Best wishes
Edited by: welo on Oct 6, 2010 5:05 AM
hi ,
it did not work with dynamic samplying. I am posting here trace 10053 output for the correct plan and wrong plan choosed but the optimizer i need soome one to help me in understanding why the optimizer is choosing wrong join order.
Sql statement and wrong plan :
tageCurrent SQL statement for this session:
SELECT t0.RecID, t0.PrtID, t0.RecOrdDt, t0.RecOrdID, t0.RecExtOrdID, t0.RecPocID, t0.PriID, t0.CasID, t0.CasNo, t0.CasClass, t0.CasPocID, t0.CasAdmit, t0.CasNotValid, t0.PatName, t0.PatFName, t0.PatBName, t0.PatBDate, t0.PatSex, t0.PatNotValid, t0.RstID, t0.RstState, t0.RstMeaningI18N, t0.PrtType, t0.PrtSubType, t0.RpxType, t0.RpxPrio, t0.PerID, t0.PerName, t0.PerFName, t0.PerTitle, t0.PerType, t0.AgnExtID
FROM XsvRecPerInfoV t0
WHERE
((((t0.AgnExtID = '1393621382') AND (t0.PrtID IN (72, 165))) AND (t0.RpxType IN (1, 2, 6, 3, 5))) AND (t0.RstState IN (202, 208, 210, 203, 206)))
--------------------------------------------------------------------+-----------------------------------+
| Id | Operation | Name | Rows | Bytes | Cost | Time |
--------------------------------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | | | | 842 | |
| 1 | NESTED LOOPS | | 1 | 204 | 842 | 00:00:11 |
| 2 | NESTED LOOPS | | 1 | 163 | 840 | 00:00:11 |
| 3 | HASH JOIN | | 1 | 129 | 838 | 00:00:11 |
| 4 | TABLE ACCESS BY INDEX ROWID | PERPERSON | 1 | 29 | 2 | 00:00:01 |
| 5 | INDEX RANGE SCAN | PERIDXAGNEXTID | 1 | | 1 | 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | XSVRECPERXREF | 2 | 34 | 3 | 00:00:01 |
| 7 | NESTED LOOPS | | 379 | 37K | 835 | 00:00:11 |
| 8 | HASH JOIN | | 238 | 19K | 342 | 00:00:05 |
| 9 | TABLE ACCESS FULL | XMFREPORTSTATE | 5 | 65 | 3 | 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | XSVPATIENTRECORD | 524 | 30K | 218 | 00:00:03 |
| 11 | NESTED LOOPS | | 1049 | 72K | 338 | 00:00:05 |
| 12 | INLIST ITERATOR | | | | | |
| 13 | TABLE ACCESS BY INDEX ROWID | XMFPATIENTRECORDTYPE| 2 | 22 | 2 | 00:00:01 |
| 14 | INDEX UNIQUE SCAN | PKPRT | 2 | | 1 | 00:00:01 |
| 15 | INDEX RANGE SCAN | RECIDXPRTID | 524 | | 119 | 00:00:02 |
| 16 | INDEX RANGE SCAN | RPXIDXRECID | 2 | | 2 | 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | ADTCASE | 1 | 34 | 2 | 00:00:01 |
| 18 | INDEX UNIQUE SCAN | PK_ADTCASE | 1 | | 1 | 00:00:01 |
| 19 | TABLE ACCESS BY INDEX ROWID | ADTPATIENT | 1 | 41 | 2 | 00:00:01 |
| 20 | INDEX UNIQUE SCAN | PK_ADTPATIENT | 1 | | 1 | 00:00:01 |
--------------------------------------------------------------------+-----------------------------------+
3 - access("PER"."PERID"="X"."PERID")
5 - access("PER"."AGNEXTID"='1393621382')
6 - filter(("X"."RPXTYPE"=1 OR "X"."RPXTYPE"=2 OR "X"."RPXTYPE"=3 OR "X"."RPXTYPE"=5 OR "X"."RPXTYPE"=6))
8 - access("D"."RSTID"="R"."RSTID")
9 - filter(("R"."RSTSTATE"=202 OR "R"."RSTSTATE"=203 OR "R"."RSTSTATE"=206 OR "R"."RSTSTATE"=208 OR "R"."RSTSTATE"=210))
14 - access(("PRT"."PRTID"=72 OR "PRT"."PRTID"=165))
15 - access("D"."PRTID"="PRT"."PRTID")
15 - filter(("D"."PRTID"=72 OR "D"."PRTID"=165))
16 - access("X"."RECID"="D"."RECID")
18 - access("D"."CASID"="C"."CASID")
20 - access("C"."PATID"="P"."PATID")
Join order[7]: XMFPATIENTRECORDTYPE[PRT]#1 XSVPATIENTRECORD[D]#3 XMFREPORTSTATE[R]#2 XSVRECPERXREF[X]#5 PERPERSON[PER]#0 ADTCASE[C]#6 ADTPATIENT[P]#4
Now joining: XSVPATIENTRECORD[D]#3
NL Join
Outer table: Card: 2.00 Cost: 2.00 Resp: 2.00 Degree: 1 Bytes: 11
Inner table: XSVPATIENTRECORD Alias: D
Access Path: TableScan
NL Join: Cost: 53601.79 Resp: 53601.79 Degree: 1
Cost_io: 53336.00 Cost_cpu: 7967475433
Resp_io: 53336.00 Resp_cpu: 7967475433
kkofmx: index filter:
("D"."PRTID"=72 OR "D"."PRTID"=165) AND ("X"."RPXTYPE"=1 OR "X"."RPXTYPE"=2 OR "X"."RPXTYPE"=3 OR "X"."RPXTYPE"=5 OR "X"."RPXTYPE"=6) AND ("R"."RSTSTATE"=202 OR "R"."RSTSTATE"=203 OR "R"."RSTSTATE"=206 OR "R"."RSTSTATE"=208 OR "R"."RSTSTATE"=210) AND "PER"."PERID"="X"."PERID" AND "X"."RECID"="D"."RECID" AND "D"."RSTID"="R"."RSTID" AND "D"."PRTID"="PRT"."PRTID" AND "D"."CASID"="C"."CASID" AND "C"."PATID"="P"."PATID" AND ("PRT"."PRTID"=72 OR "PRT"."PRTID"=165)
kkofmx: index filter:"D"."PRTID"="PRT"."PRTID" AND "D"."CASID"="C"."CASID" AND "C"."PATID"="P"."PATID" AND ("PRT"."PRTID"=72 OR "PRT"."PRTID"=165)
kkofmx: index filter:
("D"."PRTID"=72 OR "D"."PRTID"=165) AND ("X"."RPXTYPE"=1 OR "X"."RPXTYPE"=2 OR "X"."RPXTYPE"=3 OR "X"."RPXTYPE"=5 OR "X"."RPXTYPE"=6) AND ("R"."RSTSTATE"=202 OR "R"."RSTSTATE"=203 OR "R"."RSTSTATE"=206 OR "R"."RSTSTATE"=208 OR "R"."RSTSTATE"=210) AND "PER"."PERID"="X"."PERID" AND "X"."RECID"="D"."RECID" AND "D"."RSTID"="R"."RSTID" AND "D"."PRTID"="PRT"."PRTID" AND "D"."CASID"="C"."CASID" AND "C"."PATID"="P"."PATID" AND ("PRT"."PRTID"=72 OR "PRT"."PRTID"=165)
Access Path: index (FullScan)
Index: IRECRECORDIDPRTID
resc_io: 43172.00 resc_cpu: 2118737558
ix_sel: 1 ix_sel_with_filters: 6.2392e-005
NL Join: Cost: 86121.14 Resp: 86121.14 Degree: 1
Cost_io: 85924.00 Cost_cpu: 5909611610
Resp_io: 85924.00 Resp_cpu: 5909611610
Access Path: index (AllEqJoinGuess)
Index: RECIDXPRTID
resc_io: 217.00 resc_cpu: 13774732
ix_sel: 0.0074074 ix_sel_with_filters: 6.2392e-005
NL Join (ordered): Cost: 338.30 Resp: 338.30 Degree: 1
Cost_io: 337.00 Cost_cpu: 39079056
Resp_io: 337.00 Resp_cpu: 39079056
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
Best NL cost: 338.30
resc: 338.30 resc_io: 337.00 resc_cpu: 39079056
resp: 338.30 resp_io: 337.00 resp_cpu: 39079056
Join Card: 1048.85 = outer (2.00) * inner (70797.49) * sel (0.0074074)
Join Card - Rounded: 1049 Computed: 1048.85
SM Join
Outer table:
resc: 2.00 card 2.00 bytes: 11 deg: 1 resp: 2.00
Inner table: XSVPATIENTRECORD Alias: D
resc: 13387.34 card: 70797.49 bytes: 59 deg: 1 resp: 13387.34
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 651 Row size: 75 Total Rows: 70797
Initial runs: 2 Merge passes: 1 IO Cost / pass: 354
Total IO sort cost: 1005 Total CPU sort cost: 97398867
Total Temp space used: 11969000
SM join: Resc: 14397.59 Resp: 14397.59 [multiMatchCost=0.00]
SM cost: 14397.59
resc: 14397.59 resc_io: 14389.81 resc_cpu: 233098276
resp: 14397.59 resp_io: 14389.81 resp_cpu: 233098276
HA Join
Outer table:
resc: 2.00 card 2.00 bytes: 11 deg: 1 resp: 2.00
Inner table: XSVPATIENTRECORD Alias: D
resc: 13387.34 card: 70797.49 bytes: 59 deg: 1 resp: 13387.34
using dmeth: 2 #groups: 1
Cost per ptn: 0.74 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 1 probefrag: 614 ppasses: 1
Hash join: Resc: 13390.08 Resp: 13390.08 [multiMatchCost=0.00]
HA cost: 13390.08
resc: 13390.08 resc_io: 13384.81 resc_cpu: 157767585
resp: 13390.08 resp_io: 13384.81 resp_cpu: 157767585
Best:: JoinMethod: NestedLoop
Cost: 338.30 Degree: 1 Resp: 338.30 Card: 1048.85 Bytes: 70
Now joining: XMFREPORTSTATE[R]#2
NL Join
Outer table: Card: 1048.85 Cost: 338.30 Resp: 338.30 Degree: 1 Bytes: 70
Inner table: XMFREPORTSTATE Alias: R
Access Path: TableScan
NL Join: Cost: 1489.04 Resp: 1489.04 Degree: 1
Cost_io: 1486.00 Cost_cpu: 91090703
Resp_io: 1486.00 Resp_cpu: 91090703
Access Path: index (UniqueScan)
Index: PK_XMFREPORTSTATE
resc_io: 1.00 resc_cpu: 8697
ix_sel: 0.030303 ix_sel_with_filters: 0.030303
NL Join: Cost: 1387.61 Resp: 1387.61 Degree: 1
Cost_io: 1386.00 Cost_cpu: 48201937
Resp_io: 1386.00 Resp_cpu: 48201937
Access Path: index (AllEqUnique)
Index: PK_XMFREPORTSTATE
resc_io: 1.00 resc_cpu: 8697
ix_sel: 0.030303 ix_sel_with_filters: 0.030303
NL Join: Cost: 1387.61 Resp: 1387.61 Degree: 1
Cost_io: 1386.00 Cost_cpu: 48201937
Resp_io: 1386.00 Resp_cpu: 48201937
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
Best NL cost: 1387.61
resc: 1387.61 resc_io: 1386.00 resc_cpu: 48201937
resp: 1387.61 resp_io: 1386.00 resp_cpu: 48201937
Join Card: 238.38 = outer (1048.85) * inner (5.00) * sel (0.045455)
Join Card - Rounded: 238 Computed: 238.38
SM Join
Outer table:
resc: 338.30 card 1048.85 bytes: 70 deg: 1 resp: 338.30
Inner table: XMFREPORTSTATE Alias: R
resc: 3.00 card: 5.00 bytes: 13 deg: 1 resp: 3.00
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 12 Row size: 87 Total Rows: 1049
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 30450620
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 1 Row size: 25 Total Rows: 5
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 29976876
Total Temp space used: 0
SM join: Resc: 343.32 Resp: 343.32 [multiMatchCost=0.00]
SM cost: 343.32
resc: 343.32 resc_io: 340.00 resc_cpu: 99556133
resp: 343.32 resp_io: 340.00 resp_cpu: 99556133
HA Join
Outer table:
resc: 338.30 card 1048.85 bytes: 70 deg: 1 resp: 338.30
Inner table: XMFREPORTSTATE Alias: R
resc: 3.00 card: 5.00 bytes: 13 deg: 1 resp: 3.00
using dmeth: 2 #groups: 1
Cost per ptn: 0.51 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 11 probefrag: 1 ppasses: 1
Hash join: Resc: 341.81 Resp: 341.81 [multiMatchCost=0.00]
HA Join (swap)
Outer table:
resc: 3.00 card 5.00 bytes: 13 deg: 1 resp: 3.00
Inner table: XSVPATIENTRECORD Alias: D
resc: 338.30 card: 1048.85 bytes: 70 deg: 1 resp: 338.30
using dmeth: 2 #groups: 1
Cost per ptn: 0.50 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 1 probefrag: 11 ppasses: 1
Hash join: Resc: 341.81 Resp: 341.81 [multiMatchCost=0.00]
HA cost: 341.81
resc: 341.81 resc_io: 340.00 resc_cpu: 54222464
resp: 341.81 resp_io: 340.00 resp_cpu: 54222464
Best:: JoinMethod: Hash
Cost: 341.81 Degree: 1 Resp: 341.81 Card: 238.38 Bytes: 83
Now joining: XSVRECPERXREF[X]#5
NL Join
Outer table: Card: 238.38 Cost: 341.81 Resp: 341.81 Degree: 1 Bytes: 83
Inner table: XSVRECPERXREF Alias: X
Access Path: TableScan
NL Join: Cost: 280914.52 Resp: 280914.52 Degree: 1
Cost_io: 275752.00 Cost_cpu: 154753663635
Resp_io: 275752.00 Resp_cpu: 154753663635
kkofmx: index filter:
("X"."RPXTYPE"=1 OR "X"."RPXTYPE"=2 OR "X"."RPXTYPE"=3 OR "X"."RPXTYPE"=5 OR "X"."RPXTYPE"=6) AND ("R"."RSTSTATE"=202 OR "R"."RSTSTATE"=203 OR "R"."RSTSTATE"=206 OR "R"."RSTSTATE"=208 OR "R"."RSTSTATE"=210) AND "PER"."PERID"="X"."PERID" AND "X"."RECID"="D"."RECID" AND "D"."RSTID"="R"."RSTID" AND "D"."PRTID"="PRT"."PRTID" AND "D"."CASID"="C"."CASID" AND "C"."PATID"="P"."PATID" AND ("PRT"."PRTID"=72 OR "PRT"."PRTID"=165)
Access Path: index (AllEqJoinGuess)
Index: RPXIDXRECID
resc_io: 3.00 resc_cpu: 23984
ix_sel: 1.6577e-006 ix_sel_with_filters: 1.6577e-006
NL Join: Cost: 835.02 Resp: 835.02 Degree: 1
Cost_io: 833.08 Cost_cpu: 58098995
Resp_io: 833.08 Resp_cpu: 58098995
Access Path: index (RangeScan)
Index: URPXRECPERTYPE
resc_io: 3.00 resc_cpu: 23274
ix_sel: 1.6577e-006 ix_sel_with_filters: 9.4822e-007
NL Join: Cost: 835.02 Resp: 835.02 Degree: 1
Cost_io: 833.08 Cost_cpu: 58181005
Resp_io: 833.08 Resp_cpu: 58181005
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
Best NL cost: 835.02
resc: 835.02 resc_io: 833.08 resc_cpu: 58098995
resp: 835.02 resp_io: 833.08 resp_cpu: 58098995
Join Card: 378.67 = outer (238.38) * inner (835508.80) * sel (1.9013e-006)
Join Card - Rounded: 379 Computed: 378.67
SM Join
Outer table:
resc: 341.81 card 238.38 bytes: 83 deg: 1 resp: 341.81
Inner table: XSVRECPERXREF Alias: X
resc: 1180.68 card: 835508.80 bytes: 17 deg: 1 resp: 1180.68
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 3 Row size: 102 Total Rows: 238
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 30061009
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 2967 Row size: 29 Total Rows: 835509
Initial runs: 2 Merge passes: 1 IO Cost / pass: 1608
Total IO sort cost: 4575 Total CPU sort cost: 843575684
Total Temp space used: 53699000
SM join: Resc: 6126.64 Resp: 6126.64 [multiMatchCost=0.00]
SM cost: 6126.64
resc: 6126.64 resc_io: 6074.00 resc_cpu: 1577856809
resp: 6126.64 resp_io: 6074.00 resp_cpu: 1577856809
HA Join
Outer table:
resc: 341.81 card 238.38 bytes: 83 deg: 1 resp: 341.81
Inner table: XSVRECPERXREF Alias: X
resc: 1180.68 card: 835508.80 bytes: 17 deg: 1 resp: 1180.68
using dmeth: 2 #groups: 1
Cost per ptn: 3.29 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 3 probefrag: 2958 ppasses: 1
Hash join: Resc: 1525.78 Resp: 1525.78 [multiMatchCost=0.00]
HA cost: 1525.78
resc: 1525.78 resc_io: 1499.00 resc_cpu: 802794893
resp: 1525.78 resp_io: 1499.00 resp_cpu: 802794893
Best:: JoinMethod: NestedLoop
Cost: 835.02 Degree: 1 Resp: 835.02 Card: 378.67 Bytes: 100
Now joining: PERPERSON[PER]#0
NL Join
Outer table: Card: 378.67 Cost: 835.02 Resp: 835.02 Degree: 1 Bytes: 100
Inner table: PERPERSON Alias: PER
Access Path: TableScan
NL Join: Cost: 409701.78 Resp: 409701.78 Degree: 1
Cost_io: 408070.08 Cost_cpu: 48912477468
Resp_io: 408070.08 Resp_cpu: 48912477468
Access Path: index (UniqueScan)
Index: PKPER
resc_io: 2.00 resc_cpu: 16603
ix_sel: 2.7682e-006 ix_sel_with_filters: 2.7682e-006
NL Join: Cost: 1593.23 Resp: 1593.23 Degree: 1
Cost_io: 1591.08 Cost_cpu: 64391486
Resp_io: 1591.08 Resp_cpu: 64391486
Access Path: index (AllEqJoin)
Index: PERIDXAGNEXTID
resc_io: 2.00 resc_cpu: 15703
ix_sel: 0.001065 ix_sel_with_filters: 0.001065
NL Join: Cost: 1593.22 Resp: 1593.22 Degree: 1
Cost_io: 1591.08 Cost_cpu: 64050386
Resp_io: 1591.08 Resp_cpu: 64050386
Access Path: index (AllEqUnique)
Index: PKPER
resc_io: 2.00 resc_cpu: 16603
ix_sel: 2.7682e-006 ix_sel_with_filters: 2.7682e-006
NL Join: Cost: 1593.23 Resp: 1593.23 Degree: 1
Cost_io: 1591.08 Cost_cpu: 64391486
Resp_io: 1591.08 Resp_cpu: 64391486
****** trying bitmap/domain indexes ******
Access Path: index (AllEqJoin)
Index: PERIDXAGNEXTID
resc_io: 1.00 resc_cpu: 8171
ix_sel: 0.001065 ix_sel_with_filters: 0.001065
NL Join: Cost: 1214.12 Resp: 1214.12 Degree: 1
Cost_io: 1212.08 Cost_cpu: 61195971
Resp_io: 1212.08 Resp_cpu: 61195971
Access Path: index (AllEqUnique)
Index: PKPER
resc_io: 1.00 resc_cpu: 9021
ix_sel: 2.7682e-006 ix_sel_with_filters: 2.7682e-006
NL Join: Cost: 1214.13 Resp: 1214.13 Degree: 1
Cost_io: 1212.08 Cost_cpu: 61518121
Resp_io: 1212.08 Resp_cpu: 61518121
Access path: Bitmap index - rejected
Cost: 3293.30 Cost_io: 3287.25 Cost_cpu: 181295210 Sel: 9.5086e-007
Not believed to be index-only
****** finished trying bitmap/domain indexes ******
Best NL cost: 1593.22
resc: 1593.22 resc_io: 1591.08 resc_cpu: 64050386
resp: 1593.22 resp_io: 1591.08 resp_cpu: 64050386
Join Card: 0.34 = outer (378.67) * inner (1.00) * sel (8.9286e-004)
Join Card - Rounded: 1 Computed: 0.34
SM Join
Outer table:
resc: 835.02 card 378.67 bytes: 100 deg: 1 resp: 835.02
Inner table: PERPERSON Alias: PER
resc: 2.00 card: 1.00 bytes: 29 deg: 1 resp: 2.00
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 6 Row size: 120 Total Rows: 379
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 30122624
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 1 Row size: 42 Total Rows: 1
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 29976353
Total Temp space used: 0
SM join: Resc: 839.02 Resp: 839.02 [multiMatchCost=0.00]
SM cost: 839.02
resc: 839.02 resc_io: 835.08 resc_cpu: 118213674
resp: 839.02 resp_io: 835.08 resp_cpu: 118213674
HA Join
Outer table:
resc: 835.02 card 378.67 bytes: 100 deg: 1 resp: 835.02
Inner table: PERPERSON Alias: PER
resc: 2.00 card: 1.00 bytes: 29 deg: 1 resp: 2.00
using dmeth: 2 #groups: 1
Cost per ptn: 0.50 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 6 probefrag: 1 ppasses: 1
Hash join: Resc: 837.52 Resp: 837.52 [multiMatchCost=0.00]
HA Join (swap)
Outer table:
resc: 2.00 card 1.00 bytes: 29 deg: 1 resp: 2.00
Inner table: XSVRECPERXREF Alias: X
resc: 835.02 card: 378.67 bytes: 100 deg: 1 resp: 835.02
using dmeth: 2 #groups: 1
Cost per ptn: 0.50 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 1 probefrag: 6 ppasses: 1
Hash join: Resc: 837.52 Resp: 837.52 [multiMatchCost=0.00]
HA cost: 837.52
resc: 837.52 resc_io: 835.08 resc_cpu: 73140924
resp: 837.52 resp_io: 835.08 resp_cpu: 73140924
Best:: JoinMethod: Hash
Cost: 837.52 Degree: 1 Resp: 837.52 Card: 0.34 Bytes: 129
Now joining: ADTCASE[C]#6
NL Join
Outer table: Card: 0.34 Cost: 837.52 Resp: 837.52 Degree: 1 Bytes: 129
Inner table: ADTCASE Alias: C
Access Path: TableScan
NL Join: Cost: 6458.89 Resp: 6458.89 Degree: 1
Cost_io: 6414.08 Cost_cpu: 1343349671
Resp_io: 6414.08 Resp_cpu: 1343349671
Access Path: index (UniqueScan)
Index: PK_ADTCASE
resc_io: 2.00 resc_cpu: 16573
ix_sel: 3.9499e-007 ix_sel_with_filters: 3.9499e-007
NL Join: Cost: 839.52 Resp: 839.52 Degree: 1
Cost_io: 837.08 Cost_cpu: 73157497
Resp_io: 837.08 Resp_cpu: 73157497
Access Path: index (AllEqUnique)
Index: PK_ADTCASE
resc_io: 2.00 resc_cpu: 16573
ix_sel: 3.9478e-007 ix_sel_with_filters: 3.9478e-007
NL Join: Cost: 839.52 Resp: 839.52 Degree: 1
Cost_io: 837.08 Cost_cpu: 73157497
Resp_io: 837.08 Resp_cpu: 73157497
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
Best NL cost: 839.52
resc: 839.52 resc_io: 837.08 resc_cpu: 73157497
resp: 839.52 resp_io: 837.08 resp_cpu: 73157497
Join Card: 0.34 = outer (0.34) * inner (2531689.00) * sel (3.9478e-007)
Join Card - Rounded: 1 Computed: 0.34
SM Join
Outer table:
resc: 837.52 card 0.34 bytes: 129 deg: 1 resp: 837.52
Inner table: ADTCASE Alias: C
resc: 5621.37 card: 2531689.00 bytes: 34 deg: 1 resp: 5621.37
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 1 Row size: 152 Total Rows: 1
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 29976353
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 14878 Row size: 48 Total Rows: 2531689
Initial runs: 2 Merge passes: 1 IO Cost / pass: 8060
Total IO sort cost: 22938 Total CPU sort cost: 2822696818
Total Temp space used: 264217000
SM join: Resc: 29492.06 Resp: 29492.06 [multiMatchCost=0.00]
SM cost: 29492.06
resc: 29492.06 resc_io: 29352.08 resc_cpu: 4196022842
resp: 29492.06 resp_io: 29352.08 resp_cpu: 4196022842
HA Join
Outer table:
resc: 837.52 card 0.34 bytes: 129 deg: 1 resp: 837.52
Inner table: ADTCASE Alias: C
resc: 5621.37 card: 2531689.00 bytes: 34 deg: 1 resp: 5621.37
using dmeth: 2 #groups: 1
Cost per ptn: 8.95 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 1 probefrag: 14217 ppasses: 1
Hash join: Resc: 6467.84 Resp: 6467.84 [multiMatchCost=0.00]
HA cost: 6467.84
resc: 6467.84 resc_io: 6414.08 resc_cpu: 1611506897
resp: 6467.84 resp_io: 6414.08 resp_cpu: 1611506897
Best:: JoinMethod: NestedLoop
Cost: 839.52 Degree: 1 Resp: 839.52 Card: 0.34 Bytes: 163
Now joining: ADTPATIENT[P]#4
NL Join
Outer table: Card: 0.34 Cost: 839.52 Resp: 839.52 Degree: 1 Bytes: 163
Inner table: ADTPATIENT Alias: P
Access Path: TableScan
NL Join: Cost: 2172.07 Resp: 2172.07 Degree: 1
Cost_io: 2161.08 Cost_cpu: 329395913
Resp_io: 2161.08 Resp_cpu: 329395913
Access Path: index (UniqueScan)
Index: PK_ADTPATIENT
resc_io: 2.00 resc_cpu: 16533
ix_sel: 1.8294e-006 ix_sel_with_filters: 1.8294e-006
NL Join: Cost: 841.52 Resp: 841.52 Degree: 1
Cost_io: 839.08 Cost_cpu: 73174030
Resp_io: 839.08 Resp_cpu: 73174030
Access Path: index (AllEqUnique)
Index: PK_ADTPATIENT
resc_io: 2.00 resc_cpu: 16533
ix_sel: 1.8294e-006 ix_sel_with_filters: 1.8294e-006
NL Join: Cost: 841.52 Resp: 841.52 Degree: 1
Cost_io: 839.08 Cost_cpu: 73174030
Resp_io: 839.08 Resp_cpu: 73174030
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
Best NL cost: 841.52
resc: 841.52 resc_io: 839.08 resc_cpu: 73174030
resp: 841.52 resp_io: 839.08 resp_cpu: 73174030
Join Card: 0.34 = outer (0.34) * inner (546621.00) * sel (1.8294e-006)
Join Card - Rounded: 1 Computed: 0.34
SM Join
Outer table:
resc: 839.52 card 0.34 bytes: 163 deg: 1 resp: 839.52
Inner table: ADTPATIENT Alias: P
resc: 1332.55 card: 546621.00 bytes: 41 deg: 1 resp: 1332.55
using dmeth: 2 #groups: 1
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 1 Row size: 190 Total Rows: 1
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 29976353
Total Temp space used: 0
SORT resource Sort statistics
Sort width: 445 Area size: 390144 Max Area size: 78223360
Degree: 1
Blocks to Sort: 3748 Row size: 56 Total Rows: 546621
Initial runs: 2 Merge passes: 1 IO Cost / pass: 2032
Total IO sort cost: 5780 Total CPU sort cost: 591684408
Total Temp space used: 65872000
SM join: Resc: 7972.81 Resp: 7972.81 [multiMatchCost=0.00]
SM cost: 7972.81
resc: 7972.81 resc_io: 7941.08 resc_cpu: 951056673
resp: 7972.81 resp_io: 7941.08 resp_cpu: 951056673
HA Join
Outer table:
resc: 839.52 card 0.34 bytes: 163 deg: 1 resp: 839.52
Inner table: ADTPATIENT Alias: P
resc: 1332.55 card: 546621.00 bytes: 41 deg: 1 resp: 1332.55
using dmeth: 2 #groups: 1
Cost per ptn: 2.32 #ptns: 1
hash_area: 124 (max=19098) buildfrag: 1 probefrag: 3537 ppasses: 1
Hash join: Resc: 2174.39 Resp: 2174.39 [multiMatchCost=0.00]
HA cost: 2174.39
resc: 2174.39 resc_io: 2161.08 resc_cpu: 399046339
resp: 2174.39 resp_io: 2161.08 resp_cpu: 399046339
Plan cardinality mismatch: best card= 0.33796097408 curr card= 0.33791727990
Best:: JoinMethod: NestedLoop
Cost: 841.52 Degree: 1 Resp: 841.52 Card: 0.34 Bytes: 204
Best so far: Table#: 1 cost: 2.0007 card: 2.0000 bytes: 22
Table#: 3 cost: 338.3037 card: 1048.8517 bytes: 73430
Table#: 2 cost: 341.8088 card: 238.3754 bytes: 19754
Table#: 5 cost: 835.0191 card: 378.6697 bytes: 37900
Table#: 0 cost: 837.5209 card: 0.3381 bytes: 129
Table#: 6 cost: 839.5214 card: 0.3379 bytes: 163
Table#: 4 cost: 841.5220 card: 0.3379 bytes: 204
tage
Similar Messages
-
Hi
SQL : 1
Following Hierarchical SQL giving output with 2 seconds with 1169 records.
SELECT LPAD ('.', 2 * (LEVEL - 1), '.') || LEVEL bom_level,
msia.segment1
|| '.'
|| msia.segment2
|| '.'
|| msia.segment3
|| '.'
|| msia.segment4 parent_item_code,
msia.description parent_description, msia.primary_unit_of_measure,
LPAD ('.', 2 * (LEVEL - 1), '.')
|| msic.segment1
|| '.'
|| msic.segment2
|| '.'
|| msic.segment3
|| '.'
|| msic.segment4 component_item_code,
msic.description component_description, bic.operation_seq_num,
bic.component_quantity
FROM bom_bill_of_materials bom,
bom_inventory_components bic,
mtl_system_items msia,
mtl_system_items msic
WHERE bic.bill_sequence_id = bom.bill_sequence_id
AND msia.inventory_item_id = bom.assembly_item_id
AND msia.organization_id = bom.organization_id
AND msic.inventory_item_id = bic.component_item_id
AND msic.organization_id = bom.organization_id
START WITH bom.assembly_item_id = 1407543
AND bom.organization_id = 56
CONNECT BY bom.assembly_item_id = PRIOR bic.component_item_id
AND bom.organization_id = 56;
SQL : 2
Following SQL giving output = 1407543
SELECT e.equipment_item_id FROM websupp.epa_transaction_header e WHERE equipment_id = 34
Now, when I am replacing START WITH clause of SQL:1 with SQL:2 means to replace 1407543 with SQL:2, it is taking so long time .
Can you guide me in tuning SQL :1
Thanks in advance
Sanjaytry something
with t as
SELECT e.equipment_item_id val FROM websupp.epa_transaction_header e WHERE equipment_id = 34
SELECT LPAD ('.', 2 * (LEVEL - 1), '.') || LEVEL bom_level,
msia.segment1
|| '.'
|| msia.segment2
|| '.'
|| msia.segment3
|| '.'
|| msia.segment4 parent_item_code,
msia.description parent_description, msia.primary_unit_of_measure,
LPAD ('.', 2 * (LEVEL - 1), '.')
|| msic.segment1
|| '.'
|| msic.segment2
|| '.'
|| msic.segment3
|| '.'
|| msic.segment4 component_item_code,
msic.description component_description, bic.operation_seq_num,
bic.component_quantity
FROM bom_bill_of_materials bom,
bom_inventory_components bic,
mtl_system_items msia,
mtl_system_items msic,
t t
WHERE bic.bill_sequence_id = bom.bill_sequence_id
AND msia.inventory_item_id = bom.assembly_item_id
AND msia.organization_id = bom.organization_id
AND msic.inventory_item_id = bic.component_item_id
AND msic.organization_id = bom.organization_id
START WITH bom.assembly_item_id = t.val --1407543
AND bom.organization_id = 56
CONNECT BY bom.assembly_item_id = PRIOR bic.component_item_id
AND bom.organization_id = 56; -
Hi,
I need your advise on the following queries (using Oracle EBS tables). I runs more than one hour for the subquery part only. I would like to achieve much faster result. I appreciate if anyone can help me tuning this query.
SELECT item_id, item_code, org_id,
CASE
WHEN COUNT (a) = 6
THEN 1
WHEN COUNT (a) = 5
THEN 2
WHEN COUNT (a) = 3 OR COUNT (a) = 4
THEN 3
WHEN COUNT (a) = 1 OR COUNT (a) = 2
THEN 4
END "MC"
FROM (SELECT oel.inventory_item_id item_id, msi.segment1 item_code,
oel.ship_from_org_id org_id, SUM (oel.ordered_quantity) a,
TO_CHAR (oel.request_date, 'Mon-YYYY') b
FROM mtl_system_items_b msi,
mtl_item_categories mic,
oe_order_headers_all oeh,
oe_order_lines_all oel
WHERE oeh.header_id = oel.header_id
AND oel.request_date BETWEEN TRUNC (ADD_MONTHS (LAST_DAY (SYSDATE), -7)) + 1
AND TRUNC (ADD_MONTHS (LAST_DAY (SYSDATE), -1)) + 1
AND msi.creation_date < TRUNC (ADD_MONTHS (LAST_DAY (SYSDATE), -7)) + 1
AND oel.ship_from_org_id = msi.organization_id
AND oeh.header_id = oel.header_id
AND oel.inventory_item_id = msi.inventory_item_id
AND msi.inventory_item_id = mic.inventory_item_id
AND msi.organization_id = mic.organization_id
AND mic.category_set_id = 1
AND mic.category_id = 178
AND oel.org_id = oeh.org_id
GROUP BY oel.inventory_item_id,
msi.segment1,
oel.ship_from_org_id,
TO_CHAR (oel.request_date, 'Mon-YYYY'))
GROUP BY item_id, item_code, org_id
Here is the explain plan for the query, seems OK, but the query took so much time.
Plan
SELECT STATEMENT CHOOSECost: 3,955 Bytes: 38 Cardinality: 1
15 SORT GROUP BY Cost: 3,955 Bytes: 38 Cardinality: 1
14 VIEW APPS. Cost: 3,955 Bytes: 38 Cardinality: 1
13 SORT GROUP BY Cost: 3,955 Bytes: 91 Cardinality: 1
12 FILTER
11 NESTED LOOPS Cost: 3,908 Bytes: 91 Cardinality: 1
8 NESTED LOOPS Cost: 3,907 Bytes: 82 Cardinality: 1
5 NESTED LOOPS Cost: 1,303 Bytes: 1,612 Cardinality: 31
2 TABLE ACCESS BY INDEX ROWID INV.MTL_ITEM_CATEGORIES Cost: 59 Bytes: 11,818 Cardinality: 622
1 INDEX SKIP SCAN NON-UNIQUE INV.MTL_ITEM_CATEGORIES_N1 Cost: 42 Cardinality: 622
4 TABLE ACCESS BY INDEX ROWID INV.MTL_SYSTEM_ITEMS_B Cost: 2 Bytes: 33 Cardinality: 1
3 INDEX UNIQUE SCAN UNIQUE INV.MTL_SYSTEM_ITEMS_B_U1 Cost: 1 Cardinality: 1
7 TABLE ACCESS BY INDEX ROWID ONT.OE_ORDER_LINES_ALL Cost: 84 Bytes: 30 Cardinality: 1
6 INDEX RANGE SCAN NON-UNIQUE ONT.OE_ORDER_LINES_N3 Cost: 2 Cardinality: 94
10 TABLE ACCESS BY INDEX ROWID ONT.OE_ORDER_HEADERS_ALL Cost: 1 Bytes: 9 Cardinality: 1
9 INDEX UNIQUE SCAN UNIQUE ONT.OE_ORDER_HEADERS_U1 Cardinality: 1
Thanks in advance,
Dapid CandraCheck out these links on how to post proper tuning requests.
{message:id=1812597}
{thread:id=863295}
After a quick look at your execution plan I noticed you have a lot of steps that report a cardinality of 1. Do you know if statistics have been gathered recently on these tables? If not, you probably should. -
Please help me in tuning sql queries. I am a bit new to this. I have generated an Explain plan(plan table) for a particular sql statement using sql navigator. What do i do with this information exactly in order to tune the statement. It is showing some table access full,merge join cartesian, hash join semi and so on. Can anyone guide me with the general tuning procedure with respect to using the plan table analysis.
Hi,
There is a good metalink note about this one
46234.1 : Interpreting Explain plan
Nicolas. -
Hi there,
I need some help regarding the SQL QPAC which is a built in QPAC in Adobe Livecycle Workflow. The SQL QPAC takes MYSQL as the default database. Suppose if we need to connect to the SQL Server or any other database, what is the procedure to do that.
SurajHi Suraj
You need to deploy a second copy of the SQL QPAC, and point it at a different datasource. The datasource is defined as a deployment parameter (it will prompt you when you deploy the new version of the qpac).
You will also need to define the datasource in your application server. This is done in different ways for different application servers - for details, please see: standards_based_qpacs.pdf (part of the Workflow SDK), page 12, "Creating a JNDI datasource".
Alternately, you can try out our SQLPlus QPAC. This allows you to directly specify connection url, driver, username and password. The SQLPlus QPAC does a lot of other things that the regular SQL QPAC doesn't do, such as handling multiple rows, testing your query, and outputting the data in a variety of ways.
Details at: http://www.avoka.com/avoka/qpac_library.shtml
Howard -
Request for help in tuning the server which is running opmn process.
Hi Folks,
I request for an help in tuning the server which is running oracle app server opmn process , It is chewing arround 40% of the CPU resource,and our sysadmin is back of me to resolve this issues.
any feedback on this is highly appriciated...
Thanks in advanceRe: How to Achieve Performance Tuning
I hope you may find answers here..
Sharma -
Help with an SQL Query on the Logger
We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
'10-11-2012 23:59:59:59'David, thanks for replying. Unfortunitly I don't know enough about SQL to put that into a query and have it return data. Would you be able to give an example on what the query would look like?
-
Help: APEX - PL/SQL Function
Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
ID Number,
B_Number varchar2(10),
G_Type varchar2(10),
Site varchar2(50),
Event varchar2(50),
Date varchar(10),
Dataset varchar2(50),
Mode varchar2(50),
Topic varchar2(10),
Parameter varchar2(10),
Value varchar2(10)The table is filled with records which, like this:
B Number | G-Type |Site |Event |Date | Dataset | Mode | Topic | Parameter | Value
800257 | 4.2 | USA | Test |18.08.08 | Pre |MBA | Field | F_C | 73,9015
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_C | 73,6951
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_C | 73,71
800257 | 4.2 | USA | Test |18.08.08 | Post |MBA | Field | F_C | 73,7526
800257 | 4.2 | USA | Test |18.08.08 | Pre |MBA | Field | F_C | 4,5170
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_H | 24,6074
800257 | 4.2 | England | Test |03.04.96 | BL |MBA | Field | F_H | 24,62
800257 | 4.2 | England | Test |18.08.08 | Post |MBA | Field | F_H | 24,4717 Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
The result should look like this for the example above:
B Number | G-Type | Site |Event |Date | Dataset | Mode | Topic |Parameter | Value | Topic2 | Parameter2 | Value2
800257 | 4.2 | USA | Test |18.08.08 | Pre | MBA | Field | F_C | 73,9015 | - | - | -
800257 | 4.2 | USA | Test |03.04.96 | BL | MBA | Field | F_C | 73,6951 | Field | F_H | 24,6074
800257 | 4.2 | USA | Test |03.04.96 | BL | MBA | Field | F_C | 73,71 | Field | F_H | 24,62
800257 | 4.2 | USA | Test |18.08.08 | Post | MBA | Field | F_C | 73,7526 | - | - | -
800257 | 4.2 | USA | Test |18.08.08 | Pre | MBA | Field | F_C | 4,5170 | - | - | -
800257 | 4.2 | England | Test |18.08.08 | Post | MBA | Field | F_H | 24,4717 | - | - | -Hope you understand my problem and some1 can help me.
Thank you
Regards
Chris
Edited by: user11369135 on 09.07.2009 00:50user11369135 wrote:
Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
Edited by: user11369135 on 09.07.2009 00:50if I understand correctly then you want a simple GROUP BY on B_number, Event, Date and Dataset.
But you want additionaly show 3 columns from one of the rows that was grouped.
This can be done using the little known KEEP syntax.
Documentation: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#sthref1389
Example from the docs
Aggregate Example
The following example returns, within each department of the sample table hr.employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:
SELECT department_id,
MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
FROM employees
GROUP BY department_id;
DEPARTMENT_ID Worst Best
10 4400 4400
20 6000 13000
30 2500 11000
40 6500 6500
50 2100 8200
60 4200 9000
70 10000 10000
80 6100 14000
90 17000 24000
100 6900 12000
110 8300 12000
7000 7000 -
Help on java.sql.Types class
Hai Friends ,
I want some help on java.sql.Types class .
What is the use of the above class ?
Some details about this class.Good Morning Yekesa
First of all i would like to thank U for looking into my problem.
I am using java.sql.Types.OTHER for
{"?=CALL(storedprocedurename.functionname(?))"}
registerOutParameter(1,javal.sql.Types.OTHER)
setString(2,"user")
here the
second parameter passes an argument to function name ( viz. username say "user")
and the function will return the ref cursor as follows:
// declaration in pl/sql procedure
begin
rc ref cursor
open rc for select * from ss_user where login_name="user";
return rc;
end
now the stored procedure has a return value (i.e. stored function) which it needs to register as
registerOutParameter(1,javal.sql.Types.OTHER)
and it finally results in the following errors :
Loading driver
Before conn stmt
After conn stmt
Calling Stored procedure
Stored procedure called
java.sql.SQLException: Invalid column type
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:243)
at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:2487)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:64)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:54)
at sptest.<init>(sptest.java:28)
at sptest.main(sptest.java:49)
T couldn't understand why it is saying Invalid Column Type because its working fine with both
java.sql.Types.INTEGER
and
java.sql.Types.VARCHAR
Pl help me at the earliest as i have wasted a lot of time on it.
pl mail me in detail at [email protected]
bye then
bansi
null -
Hi All,
I need little help in designing SQL. My input and output data is given below:
Input
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Here out of 2nd and third record of input, output is 2nd record of output and 5th and 6th record of input would come out as 4th record of output. Basically, if we overlapping duration between Date_1 and Date_2, we need to take min of Date_1 and max of Date_2 for that overlapping records. In case of no overlapping, we would simply output input record like record 1 and 4 of input.
Out of
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
2/24/2011 1:48:07 PM was min of above 2 and 5/24/20114:50:16 was max of above 2.
Similarly in other overlapping scenario:
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
6/16/2011 3:25:42 PM was min of above 2 and 6/25/2011 5:55:55 PM was max of above 2.
Pls help.
Thanks.Hi Frank.,
The above logic with NVL is not working.
My input sample is:
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
I am giving create and insert statement below for creation of above data. Please see if you can help me:
CREATE TABLE test1
KEY1 NUMBER ,
DATE_1 DATE ,
date_2 DATE
insert into test1
values(1, TO_TIMESTAMP ('2/14/2011 5:22:35 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('2/22/2011 3:05:13 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:07 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('5/24/2011 4:50:16 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), '' ) ;
values(1, TO_TIMESTAMP ('5/24/2011 5:18:19 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/16/2011 3:17:40 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('6/16/2011 3:25:42 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/24/2011 1:33:13 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('6/17/2011 1:12:54 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/25/2011 5:55:55 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
commit;
Expected output would be:
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Thanks.... -
Need help to debug SQL Tuning Advisor Error Message
Hi,
I am getting an error message while try to get recommendations from the SQL Tuning Advisor.
Environment:
Oracle Version: 11.2.0.3.0
O/S: AIX
Following is my code:
declare
my_task_name varchar2 (30);
my_sqltext clob;
begin
my_sqltext := 'SELECT DISTINCT MRKT_AREA AS DIVISION, PROMO_ID,
PROMO_CODE,
RBR_DTL_TYPE.PERF_DETL_TYP,
RBR_DTL_TYPE.PERF_DETL_DESC,
RBR_DTL_TYPE.PERF_DETL_SUB_TYP,
RBR_DTL_TYPE.PERF_DETL_SUB_DESC,
BU_SYS_ITM_NUM,
RBR_CPN_LOC_ITEM_ARCHIVE.CLI_SYS_ITM_DESC,
PROMO_START_DATE,
PROMO_END_DATE,
PROMO_VALUE2,
PROMO_VALUE1,
EXEC_COMMENTS,
PAGE_NUM,
BLOCK_NUM,
AD_PLACEMENT,
BUYER_CODE,
RBR_CPN_LOC_ITEM_ARCHIVE.CLI_STAT_TYP,
RBR_MASTER_CAL_ARCHIVE.STATUS_FLAG
FROM (PROMO_REPT_OWNER.RBR_CPN_LOC_ITEM_ARCHIVE
INNER JOIN PROMO_REPT_OWNER.RBR_MASTER_CAL_ARCHIVE
ON (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_PROMO_ID = PROMO_ID)
AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_PERF_DTL_ID = PERF_DETAIL_ID)
AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_STR_NBR = STORE_ZONE)
AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_ITM_ID = ITM_ID))
INNER JOIN PROMO_REPT_OWNER.RBR_DTL_TYPE
ON (RBR_MASTER_CAL_ARCHIVE.PERF_DETL_TYP = RBR_DTL_TYPE.PERF_DETL_TYP)
AND (RBR_MASTER_CAL_ARCHIVE.PERF_DETL_SUB_TYP = RBR_DTL_TYPE.PERF_DETL_SUB_TYP)
WHERE ( ((MRKT_AREA)=40)
AND ((RBR_DTL_TYPE.PERF_DETL_TYP)=1)
AND ((RBR_DTL_TYPE.PERF_DETL_SUB_TYP)=1) )
AND ((CLI_STAT_TYP)=1 Or (CLI_STAT_TYP)=6)
AND ((RBR_MASTER_CAL_ARCHIVE.STATUS_FLAG)=''A'')
AND ( ((PROMO_START_DATE) >= to_date(''2011-10-20'', ''YYYY-MM-DD'')
And (PROMO_END_DATE) <= to_date(''2011-10-26'', ''YYYY-MM-DD'')) )
ORDER BY MRKT_AREA';
my_task_name := dbms_sqltune.create_tuning_task
(sql_text => my_sqltext,
user_name => 'PROMO_REPT_OWNER',
scope => 'COMPREHENSIVE',
time_limit => 3600,
task_name => 'Test_Query',
description => 'Test Query');
end;
begin
dbms_sqltune.execute_tuning_task(task_name => 'Test_Query');
end;
set serveroutput on size unlimited;
set pagesize 5000
set linesize 130
set long 50000
set longchunksize 500000
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('Test_Query') FROM DUAL;
Output:
snippet .....
FINDINGS SECTION (1 finding)
1- Index Finding (see explain plans section below)
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 71.48%)
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
Error: Cannot fetch actions for recommendation: INDEX
Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Rationale
Creating the recommended indices significantly improves the execution plan
of this statement. However, it might be preferable to run "Access Advisor"
using a representative SQL workload as opposed to a single statement. This
will allow to get comprehensive index recommendations which takes into
account index maintenance overhead and additional space consumption.
snippet
Any ideas why I am getting ORA-06502 error?
Thanks in advance
RogersBug 14407401 - ORA-6502 from index recommendation section of DBMS_SQLTUNE output (Doc ID 14407401.8)
Fixed:
The fix for 14407401 is first included in
12.1.0.1 (Base Release) -
Help with performance SQL tuning - Rewriting the query
Hi
I have serious performance issues with some 8 update queries
These were earlier taking 5 mins . Now taking 2.5 hours
This is one of the culprit UPDATE statement (These are 7 such other update statements on different tables but same logic)
We have change the update to MERGE and used PARALLEL hints but have not got desired results
There are appropriate indexes on the tables
Is there a way to rewrite the UPDATE statement in a better way to improve the performance
update TABLE_dob
set key_act =
(select skey from table_subs
where sub_act = sub_num)
where exists
(select 1 from table_subs
where sub_act = sub_num);
Table_DOB has 37 million records
Table_subs has 20 million recordsaashoo_5 wrote:
Hi
I have serious performance issues with some 8 update queries
These were earlier taking 5 mins . Now taking 2.5 hours
This is one of the culprit UPDATE statement (These are 7 such other update statements on different tables but same logic)
We have change the update to MERGE and used PARALLEL hints but have not got desired results
There are appropriate indexes on the tables
Is there a way to rewrite the UPDATE statement in a better way to improve the performance
update TABLE_dob
set key_act =
(select skey from table_subs
where sub_act = sub_num)
where exists
(select 1 from table_subs
where sub_act = sub_num);
Table_DOB has 37 million records
Table_subs has 20 million recordsThread: HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting -
Hi,
I have a partioned table.I am spooling output of an sql which joins the partioned table and another referece table of minimal data.
each partion except 3 contains 5 milllion records on average
othere 3 partitions has 6.6 million records (each one).
The sql takes 3 mins if it is triggered against the partions with 5 million but
the same sql is taing 8 hrs if it is triggered against the partion with 6.5 million.
Please help me how can avoid this performace issue
Below are IO statistics for the two cases
(partion with 6.5 million)
BLOCK_GETS=9
CONSISTENT_GETS=89533761
PHYSICAL_READS=15746
(partion with 5.0 million)
BLOCK_GETS=8
CONSISTENT_GETS=1215131
PHYSICAL_READS=28848Hi,
post the select for the 2 SQL's and the EXPLAIN for each. -
Pls help in performance tuning SQL
Hi All,
Can someone please help me to tune this quesry. Rt now it is takin 20 mins tro retuns 80,000 rows and its using dblink
SELECT COUNT(*) FROM
(SELECT /*+driving_site(main)*/CORP_ACTG_PRD_YEAR,
CORP_ACTG_PRD_NBR,
FCN_CODE,
LOCAL_CRNC_CODE,
GL_LOCAL_AMT,
CORP_ID,
PGRD_COST_CTR_ID,
MAJOR_CODE,
EXP_MINOR_CODE,
PGRD_EXP_CODE,
PGRD_EXP_DESC,
DIV_CODE,
MKT_CODE,
PROD_CODE,
PGRD_PROJECT_CODE,
PGRD_PROJ_SHORT_DESC
FROM --#GifDBLink# main,
[email protected] main,
select actg_prd_year, actg_prd_nbr from DM_GIF_ESSBASE_CTRL
where cur_prd_ind='Y' and src_id=84
union
select decode(actg_prd_nbr,1,actg_prd_year-1,actg_prd_year) actg_prd_year,
decode(actg_prd_nbr,1,12,actg_prd_nbr-1) actg_prd_nbr
from DM_GIF_ESSBASE_CTRL
where cur_prd_ind='Y' and src_id=84
union
select decode(actg_prd_nbr,12,actg_prd_year+1,actg_prd_year) actg_prd_year,
decode(actg_prd_nbr,12,1,actg_prd_nbr+1) actg_prd_nbr
from DM_GIF_ESSBASE_CTRL
where cur_prd_ind='Y' and src_id=84 ) minor
where main.CORP_ACTG_PRD_YEAR = minor.actg_prd_year
and main.CORP_ACTG_PRD_NBR = minor.actg_prd_nbr) T;user13365939 wrote:
anyone?Incorrect.
You are only one who can provide the information that was requested in this thread.
Please see the FAQ, read the instructions and provide the necessary information.
Re: 3. How to improve the performance of my query? / My query is running slow. -
Hi
I have a query which will read one fact table and 4 dimension table.fact table contains millions of records
Can u suggest me how can i tune my query which uses the fact table to get the best performance.Which version of the database are you using? Have you enabled Star Transformation? What does the explain plan look like? Is this intended for building a materilaized view or as the basis for running an ad hoc report?
We created bit map indexes on the joining columns.bitmap indexes or bitmap-join indexes?
Cheers, APC
Maybe you are looking for
-
Sorry, I got an answer but can't find it anymore. My problem is still not solved, so I will decribe it again. I re-installed the drivers from the HP website, for my 16 months old HP 6700 Premium. I got a HP buttom, as normal on my desktop screen. Pr
-
Open PDF File from Link on SSRS Report REDUX
Revisiting an earlier post here, because a solution is revealed. The string below, when entered into the "Jump to URL" value on the Navigation tab for Textbox properties, works IN A REPORT PUBLISHED to a Report Server. This would NOT work in the Vi
-
Locking a Warehouse via DTW failed
Hello Experts, i have been reading all the topics related to the subject i have posted. The problem is really simple, there has been a mistake in creating a warehouse (that was immediately associated to all the items because of the system set up) and
-
hi once see this program and tel me whats wrong with me and correct the errors plz TABLES: HRP1001, HRP1026, HRP1000. TYPE-POOLS SLIS. **************DATA TYPES DECLARATION ********************** TYPES :BEGIN OF ST_OUTPUT, COUNT TYPE STRING,
-
Hi: I speak spanish... is there a way to change the error message... ??? have the same problem for forgot password email I can customise the email but not the email subjet. thanx