Request for tunning the below query
Hi,
Can any one help me on the below query while improving the performance,
SELECT accdet, acceprec, accinvalid, accnetanal, accphy, accvalid,
actlabcost, actlabhrs, actualcontactdate, actualfinish, actualstart,
affecteddate, affectedemail, affectedperson, affectedphone,
alteration, aslaiddwg, assetnum, assetorgid, assetsiteid,
assumptions, basedet, basereq, bicounty, bidplo, bieasting,
bihousename, bihouseno, binorthing, bipobox, bipostcode, biposttown,
bistreet, bisubb as bisupp, boostcomp, boostcompdet, ccemail, cchouseno, ccid,
ccname, cctel1type, cctel2type, cctelephone1, cctelephone2, cdm,
changeby, changedate, CLASS, classstructureid, cocontact, cocounty,
codplo, coeasment, coeasting, cohousename, conorthing, copobox,
commodity, commoditygroup, coneasereq, consent, consents,
copostcode, coposttown, costcon, costreet, cosubb, cpi90,
createworelasset, customerref, custtype, depot, description, durt,
ecvpressuretier, ecvsize, enduserid, engdifficult, exaoq, existin,
existsdq, expid, exshq, externalrecid, extralanddetail, failurecode,
fr1code, fr2code, fuelpovscheme, g17, gbna, glaccount,
globalticketclass, globalticketid, govconf, govener, govenerdet,
govhouse, hasactivity, hasld, historyflag, impact, infill,
infoprovide, inheritstatus, internalpriority, interquote, isglobal,
isknownerror, isknownerrordate, kioskdet, kioskreq, langcode,
latecertdate, leadt, lengthpri, lengthpub, loadtype, LOCATION, m25,
maindesac, mainusage, meterboxty, metercon, meterloc, meterser,
mininforec, mininforeq, mprnno, newaoq, newpid, newsdq, newshq,
np14, nrswa, nsgno, oldquotever, oldticketid, orgid, originsgn,
origrecordclass, origrecordid, origrecorgid, origrecsiteid, owner,
ownergroup, packagesent, paymethod, payterms, permittowork, physub,
pressuretier, privateexc, problemcode, propertiesno, propertytype,
publicexc, purgerel, quotedate, quotetype, quotever, reinforcement,
reinforcementa, reinforcementb, relatedtoglobal, reportdate,
reportedby, reportedemail, reportedphone, reportedpriority,
rowstamp, sc, scj, scoreq, servicerelay, sgnbillcontact,
sgnblkbyfin, sgncusttobill, sgncusttosite, sgndisreasoth,
sgneasment, sgnenhance, sgneow, sgneowreq, sgngqmvalid,
sgninfillcost, sgninfillver, sgninfprojno, sgnisstdchrg,
sgnloadnoenter, sgnmainsreq, sgnmaxaccdate, sgnnoncont, sgnpipesiz,
sgnpurord, sgnqdaysremain, sgnqstd, sgnquotdate, sgnquotval,
sgnreasdis, sgntotalaoq, sgntotalshq, sgnvarreq, sicontact,
sicounty, sidplo, sieasting, sihousename, sihouseno, sinorthing,
sipobox, sipostcode, siposttown, sistreet, sisubb, sitecond, sitegt,
siteid, sitel1, sitel2, siteplpro, sitevisit, solution, sos,
sosrecdate, SOURCE, status, statusdate, subfinal, supervisor,
supplytype, surveycarr, surveydef, surveyreas, surveyreq, surveyret,
surveysent, targetcontactdate, targetfinish, targetstart, TEMPLATE,
templateid, termtype, thirdpartyeas, thirdpartypipe, ticketid,
ticketuid, totalaoq, totalpid, totalsdq, totalshq, traffictime,
typewo, urgency, variat, vendor, customer_enquiry_ref,
quote_version, costs, mains_infill_charge, mtr_housing_kiosk_charge,
mtr_housing_kiosk_base_charge, specialist_reinstatement,
easement_charge, total_quote_ex_vat, vat, total_quote_incl_vat,
design_charge, reinforcement_charge, reinforcement_cost,
connection_allowance, workorder.pscdate, workorder.ascdate,
workorder.fincode, workorder.istask, workorder.status,
workorder.targstartdate, workorder.targcompdate,
workorder.schedfinish, workorder.actfinish, workorder.estdur,
workorder.wonum, workorder.mprn,
workorder.sihousename AS wositehousename,
workorder.sihouseno AS wositehouseno,
workorder.sistreet AS wositestreet,
workorder.sicounty AS wositecounty,
workorder.siposttown AS wositeposttown,
workorder.sipostcode AS wositepostcode, workorder.workorderid
FROM (maximo.sr
INNER JOIN
(maximo.relatedrecord INNER JOIN maximo.workorder
ON relatedrecord.relatedreckey =
(CASE
WHEN workorder.PARENT IS NOT NULL
THEN workorder.PARENT
ELSE workorder.wonum
END
AND relatedrecord.orgid = workorder.orgid
AND relatedrecord.siteid = workorder.siteid
AND relatedrecord.relatedrecclass = 'WORKORDER')
ON sr.ticketid = relatedrecord.recordkey
AND sr.orgid = relatedrecord.orgid
AND sr.siteid = relatedrecord.siteid
AND relatedrecord.CLASS = 'SR')
LEFT JOIN
frozen_quote@gqmfof
ON sr.ticketid = customer_enquiry_ref
AND sr.quotever = quote_version
Regards,
grace
Could you please provide more info.
Refer to the following link.
When your query takes too long ...
thanks
Similar Messages
-
Request for tunning the SQL query
Hi,
I've a query mentioned below.I've tried it in different ways.But still it is taking much time.
And there are some 9 indexes created on the column siteid. And both the table having indexes.But still full table scanning occuring for both the tables. Can any one help on this.Or can anyone write the same query in a different way.
select r.recordkey,
r.orgid,
r.siteid,
r.class,
w.pscdate,
w.ascdate,
w.targstartdate,
w.targcompdate,
w.schedfinish,
w.actfinish,
w.estdur,
w.wonum,
w.mprn,
w.sihousename wositehousename,
w.sihouseno wositehouseno,
w.sistreet wositestreet,
w.sicounty wositecounty,
w.siposttown wositeposttown,
w.sipostcode wositepostcode,
w.workorderid
from relatedrecord r,
workorder w
where r.relatedreckey = case when w.parent is null then w.wonum else w.parent end
and r.orgid = w.orgid
and r.siteid = w.siteid
and r.relatedrecclass = 'WORKORDER'
Explain Plan Res:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 38 K 4819
HASH JOIN 38 K 5 M 4819
TABLE ACCESS FULL MAXIMO.RELATEDRECORD 30 K 1 M 390
TABLE ACCESS FULL MAXIMO.WORKORDER 229 K 26 M 2922
Regards,
Arjun.Hi,
Some question.
1) r.relatedrecclass = 'WORKORDER', how many records are there with relatedrecclass as "WORKORDER" compared to the total number of records in that table (in percentage)
2) Do we have index on relatedrecclass? (if possible in combination with recordkey and class column)
3) What is the total number of records in both the table?
4) What is the expected number of records with the below query?
Regards
Anurag -
Hi,
Can anyone help me on the below query while improving performance. WHen i executed in TOAD 8.6.1 it is taking cost 8890. becoz of joins & some table are scanning fully eventhough there are some indexes on it.
If possible please rewrite the below query in anyotherway.
SELECT
SR.*,
frozen_quote.*,
WORKORDER.pscdate,
WORKORDER.ascdate,
WORKORDER.targstartdate,
WORKORDER.targcompdate,
WORKORDER.schedfinish,
WORKORDER.actfinish,
WORKORDER.estdur,
WORKORDER.wonum,
WORKORDER.MPRN,
WORKORDER.sihousename AS wositehousename,
WORKORDER.sihouseno AS wositehouseno,
WORKORDER.sistreet AS wositestreet,
WORKORDER.sicounty AS wositecounty,
WORKORDER.siposttown AS wositeposttown,
WORKORDER.sipostcode AS wositepostcode,
WORKORDER.workorderid
FROM (maximo.SR
INNER JOIN
(maximo.RELATEDRECORD
INNER JOIN maximo.WORKORDER
ON RELATEDRECORD.relatedreckey=(
CASE
WHEN WORKORDER.parent IS NOT NULL
THEN WORKORDER.parent
ELSE WORKORDER.wonum
END
AND RELATEDRECORD.orgid=WORKORDER.orgid
AND RELATEDRECORD.siteid=WORKORDER.siteid
AND RELATEDRECORD.relatedrecclass='WORKORDER'
ON SR.ticketid=RELATEDRECORD.recordkey
AND SR.orgid=RELATEDRECORD.orgid
AND SR.siteid=RELATEDRECORD.siteid
AND RELATEDRECORD.class='SR')
LEFT JOIN
frozen_quote@gqmfof
ON SR.ticketid = CUSTOMER_ENQUIRY_REF
AND SR.quotever = QUOTE_VERSION
Regards,
Arjun.Check the plan of the non ansii version below against the plan of your version.
Sometimes they might be different as I remember hearing somewhere. The probability is not very high though as using ansii syntax some care
must be taken specifying predicates so the compared versions I heard about might well not be equivalent.
If the plans are the same and having indexes on linking columns in place I don't see what else could be done as accessing a remote database
can well be the major contribution the slow response you're experiencing.
select y.*,
f.*
from (select s.*,
x.pscdate,x.ascdate,x.targstartdate,x.targcompdate,x.schedfinish,x.actfinish,x.estdur,x.wonum,x.mprn,
x.sihousename wositehousename,x.sihouseno wositehouseno,x.sistreet wositestreet,
x.sicounty wositecounty,x.siposttown wositeposttown,x.sipostcode wositepostcode,
x.workorderid
from (select r.recordkey,r.orgid,r.siteid,r.class,
w.pscdate,w.ascdate,w.targstartdate,w.targcompdate,w.schedfinish,w.actfinish,w.estdur,w.wonum,w.mprn,
w.sihousename wositehousename,w.sihouseno wositehouseno,w.sistreet wositestreet,
w.sicounty wositecounty,w.siposttown wositeposttown,w.sipostcode wositepostcode,
w.workorderid
from relatedrecord r,
workorder w
where r.relatedreckey = case when w.parent is null then w.wonum else w.parent end
and r.orgid = w.orgid
and r.siteid = w.siteid
and r.relatedrecclass = 'WORKORDER'
) x,
sr s
where x.recordkey = s.ticketid
and x.orgid = s.orgid
and x.siteid = s.siteid
and x.class = 'SR'
) y,
frozen_quote@gqmfof f
where y.ticketid = f.customer_enquiry_ref
and y.quotever = f.quote_versionRegards
Etbin -
Need to tune the below query.
Query below:
I have generated the explain plan for the same and its cost is overall 2089...
But Strange once I have removed the "ORDER SIBLINGS BY RETAILER_NM" from below then its cost is coming overall 40.
Can U suggest me what is the best solution.
SELECT path as Retailer_id, logical_physical_flg, parent_retailer_id, upper(retailer_nm), max_level
FROM (SELECT A.RETAILER_ID,LOGICAL_PHYSICAL_FLG, NULL AS PARENT_RETAILER_ID, B.RETAILER_NM, a.retailer_id path,
(LEVEL+2) AS MAX_LEVEL FROM
RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND
B.RETAILER_ID=A.RETAILER_ID AND B.STATUS='ACTIVE' AND
A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
AND MANAGED_BY='Y'
UNION
SELECT a.RETAILER_ID, LOGICAL_PHYSICAL_FLG, replace(sys_connect_by_path(decode(level, 1, a.parent_retailer_id), '~'), '~') parent_retailer_id, RETAILER_NM, LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(B.RETAILER_ID, '/') AS path, LEVEL+3 AS MAX_LEVEL
FROM RETAILER B, RETAILER_HIERARCHY A
WHERE B.RETAILER_ID=A.RETAILER_ID AND UPPER(B.STATUS)='ACTIVE' AND EXISTS
(SELECT RETAILER_ID FROM USER_RETAILER_MAP C WHERE USER_ID = 'ALEX.CAYLESS@GMACIO' AND
B.RETAILER_ID = C.RETAILER_ID AND MANAGED_BY= 'Y')
START WITH PARENT_RETAILER_ID IN (SELECT A.RETAILER_ID FROM
RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND B.RETAILER_ID=A.RETAILER_ID
AND UPPER(B.STATUS)='ACTIVE' AND A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
AND MANAGED_BY='Y') CONNECT BY PRIOR A.RETAILER_ID=PARENT_RETAILER_ID )
START WITH PARENT_RETAILER_ID IS NULL CONNECT BY PRIOR RETAILER_ID = PARENT_RETAILER_ID
ORDER SIBLINGS BY RETAILER_NM
Explain Plan:
==========================
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1352 | 5385K| 2089 |
|* 1 | CONNECT BY WITH FILTERING | | | | |
|* 2 | FILTER | | | | |
| 3 | COUNT | | | | |
| 4 | VIEW | | 1352 | 5385K| 40 |
| 5 | SORT UNIQUE | | 1352 | 84128 | 40 |
| 6 | UNION-ALL | | | | |
|* 7 | HASH JOIN ANTI | | 16 | 1296 | 12 |
|* 8 | HASH JOIN | | 19 | 1406 | 9 |
| 9 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 10 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
|* 11 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
| 12 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
|* 13 | CONNECT BY WITH FILTERING | | | | |
| 14 | NESTED LOOPS | | | | |
|* 15 | HASH JOIN | | 58 | 2262 | 5 |
| 16 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 17 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 18 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 19 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 20 | NESTED LOOPS | | | | |
| 21 | BUFFER SORT | | 3 | 54 | |
| 22 | CONNECT BY PUMP | | | | |
|* 23 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 24 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 25 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 26 | FILTER | | | | |
|* 27 | CONNECT BY WITH FILTERING | | | | |
|* 28 | FILTER | | | | |
| 29 | COUNT | | | | |
|* 30 | HASH JOIN | | 1336 | 82832 | 9 |
| 31 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 32 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 33 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 34 | NESTED LOOPS | | 1 | 47 | 3 |
|* 35 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 36 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 37 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|* 38 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|* 39 | VIEW | VW_NSO_3 | 3 | 21 | |
|* 40 | CONNECT BY WITH FILTERING | | | | |
| 41 | NESTED LOOPS | | | | |
|* 42 | HASH JOIN | | 58 | 2262 | 5 |
| 43 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
|* 44 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 45 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 46 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 47 | NESTED LOOPS | | | | |
| 48 | BUFFER SORT | | 3 | 54 | |
| 49 | CONNECT BY PUMP | | | | |
|* 50 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 51 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 52 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 53 | HASH JOIN | | | | |
| 54 | CONNECT BY PUMP | | | | |
| 55 | COUNT | | | | |
|* 56 | HASH JOIN | | 1336 | 82832 | 9 |
| 57 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 58 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 59 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 60 | NESTED LOOPS | | 1 | 47 | 3 |
|* 61 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 62 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 63 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|* 64 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|* 65 | VIEW | VW_NSO_3 | 3 | 21 | |
|* 66 | CONNECT BY WITH FILTERING | | | | |
| 67 | NESTED LOOPS | | | | |
|* 68 | HASH JOIN | | 58 | 2262 | 5 |
| 69 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 70 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 71 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 72 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 73 | NESTED LOOPS | | | | |
| 74 | BUFFER SORT | | 3 | 54 | |
| 75 | CONNECT BY PUMP | | | | |
|* 76 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 77 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 78 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 79 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 80 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 81 | HASH JOIN | | | | |
| 82 | CONNECT BY PUMP | | | | |
| 83 | COUNT | | | | |
| 84 | VIEW | | 1352 | 5385K| 40 |
| 85 | SORT UNIQUE | | 1352 | 84128 | 40 |
| 86 | UNION-ALL | | | | |
|* 87 | HASH JOIN ANTI | | 16 | 1296 | 12 |
|* 88 | HASH JOIN | | 19 | 1406 | 9 |
| 89 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 90 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
|* 91 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
| 92 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
|* 93 | CONNECT BY WITH FILTERING | | | | |
| 94 | NESTED LOOPS | | | | |
|* 95 | HASH JOIN | | 58 | 2262 | 5 |
| 96 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 97 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 98 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 99 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 100 | NESTED LOOPS | | | | |
| 101 | BUFFER SORT | | 3 | 54 | |
| 102 | CONNECT BY PUMP | | | | |
|*103 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*104 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*105 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*106 | FILTER | | | | |
|*107 | CONNECT BY WITH FILTERING | | | | |
|*108 | FILTER | | | | |
| 109 | COUNT | | | | |
|*110 | HASH JOIN | | 1336 | 82832 | 9 |
| 111 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 112 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 113 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 114 | NESTED LOOPS | | 1 | 47 | 3 |
|*115 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*116 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*117 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|*118 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|*119 | VIEW | VW_NSO_3 | 3 | 21 | |
|*120 | CONNECT BY WITH FILTERING | | | | |
| 121 | NESTED LOOPS | | | | |
|*122 | HASH JOIN | | 58 | 2262 | 5 |
| 123 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
|*124 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 125 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 126 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 127 | NESTED LOOPS | | | | |
| 128 | BUFFER SORT | | 3 | 54 | |
| 129 | CONNECT BY PUMP | | | | |
|*130 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*131 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*132 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 133 | HASH JOIN | | | | |
| 134 | CONNECT BY PUMP | | | | |
| 135 | COUNT | | | | |
|*136 | HASH JOIN | | 1336 | 82832 | 9 |
| 137 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 138 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 139 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 140 | NESTED LOOPS | | 1 | 47 | 3 |
|*141 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*142 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*143 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|*144 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|*145 | VIEW | VW_NSO_3 | 3 | 21 | |
|*146 | CONNECT BY WITH FILTERING | | | | |
| 147 | NESTED LOOPS | | | | |
|*148 | HASH JOIN | | 58 | 2262 | 5 |
| 149 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|*150 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 151 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 152 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 153 | NESTED LOOPS | | | | |
| 154 | BUFFER SORT | | 3 | 54 | |
| 155 | CONNECT BY PUMP | | | | |
|*156 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*157 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*158 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*159 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*160 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
11 - filter("B"."STATUS"='ACTIVE')
13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
24 - filter("A"."MANAGED_BY"='Y')
25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
."MANAGED_BY"='Y'))
27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
"SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
"='Y'))
28 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
"SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
"='Y'))
30 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
35 - filter("A"."MANAGED_BY"='Y')
36 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
37 - filter(UPPER("B"."STATUS")='ACTIVE')
38 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
39 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
40 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
42 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
44 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
50 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
51 - filter("A"."MANAGED_BY"='Y')
52 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
56 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
61 - filter("A"."MANAGED_BY"='Y')
62 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
63 - filter(UPPER("B"."STATUS")='ACTIVE')
64 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
65 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
66 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
68 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
70 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
76 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
77 - filter("A"."MANAGED_BY"='Y')
78 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
79 - filter("C"."MANAGED_BY"='Y')
80 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
87 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
88 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
90 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
91 - filter("B"."STATUS"='ACTIVE')
93 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
95 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
97 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
103 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
104 - filter("A"."MANAGED_BY"='Y')
105 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
106 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
."MANAGED_BY"='Y'))
107 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
"SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
"='Y'))
108 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
"SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
"='Y'))
110 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
115 - filter("A"."MANAGED_BY"='Y')
116 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
117 - filter(UPPER("B"."STATUS")='ACTIVE')
118 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
119 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
120 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
122 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
124 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
130 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
131 - filter("A"."MANAGED_BY"='Y')
132 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
136 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
141 - filter("A"."MANAGED_BY"='Y')
142 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
143 - filter(UPPER("B"."STATUS")='ACTIVE')
144 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
145 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
146 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
148 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
150 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
156 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
157 - filter("A"."MANAGED_BY"='Y')
158 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
159 - filter("C"."MANAGED_BY"='Y')
160 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
Edited by: user13345267 on Jul 19, 2010 1:56 AMPlease find formatted sql.
SELECT path AS retailer_id,
logical_physical_flg,
parent_retailer_id,
Upper(retailer_nm),
max_level
FROM (SELECT a.retailer_id,
logical_physical_flg,
NULL AS parent_retailer_id,
b.retailer_nm,
a.retailer_id path,
( LEVEL + 2 ) AS max_level
FROM retailer b,
user_retailer_map a
WHERE user_id = 'ALEX.CAYLESS@GMACIO'
AND b.retailer_id = a.retailer_id
AND b.status = 'ACTIVE'
AND a.retailer_id NOT IN (SELECT DISTINCT retailer_id
FROM retailer_hierarchy
START WITH parent_retailer_id IN (
SELECT
retailer_id
FROM
user_retailer_map a
WHERE
user_id = 'ALEX.CAYLESS@GMACIO'
AND managed_by = 'Y')
CONNECT BY PRIOR
retailer_id = parent_retailer_id)
AND managed_by = 'Y'
UNION
SELECT a.retailer_id,
logical_physical_flg,
Replace(Sys_connect_by_path(
Decode(LEVEL, 1, a.parent_retailer_id), '~')
'~')
parent_retailer_id,
retailer_nm,
Lpad(' ', 2 * LEVEL - 1)
||Sys_connect_by_path(b.retailer_id, '/') AS path,
LEVEL + 3 AS max_level
FROM retailer b,
retailer_hierarchy a
WHERE b.retailer_id = a.retailer_id
AND Upper(b.status) = 'ACTIVE'
AND EXISTS (SELECT retailer_id
FROM user_retailer_map c
WHERE user_id = 'ALEX.CAYLESS@GMACIO'
AND b.retailer_id = c.retailer_id
AND managed_by = 'Y')
START WITH parent_retailer_id IN (SELECT a.retailer_id
FROM retailer b,
user_retailer_map a
WHERE user_id = 'ALEX.CAYLESS@GMACIO'
AND
b.retailer_id = a.retailer_id
AND Upper(b.status) = 'ACTIVE'
AND a.retailer_id NOT IN
(SELECT DISTINCT
retailer_id
FROM retailer_hierarchy
START WITH parent_retailer_id IN
SELECT
retailer_id
FROM
user_retailer_map a
WHERE
user_id = 'ALEX.CAYLESS@GMACIO'
AND managed_by = 'Y')
CONNECT BY PRIOR
retailer_id = parent_retailer_id)
AND managed_by = 'Y')
CONNECT BY PRIOR a.retailer_id = parent_retailer_id)
START WITH parent_retailer_id IS NULL
CONNECT BY PRIOR retailer_id = parent_retailer_id
ORDER SIBLINGS BY RETAILER_NM
Execution Plan
====================================
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1352 | 5385K| 2089 |
|* 1 | CONNECT BY WITH FILTERING | | | | |
|* 2 | FILTER | | | | |
| 3 | COUNT | | | | |
| 4 | VIEW | | 1352 | 5385K| 40 |
| 5 | SORT UNIQUE | | 1352 | 84128 | 40 |
| 6 | UNION-ALL | | | | |
|* 7 | HASH JOIN ANTI | | 16 | 1296 | 12 |
|* 8 | HASH JOIN | | 19 | 1406 | 9 |
| 9 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 10 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
|* 11 | TABLE ACCESS FULL | RETAILER | 32 | 1408 | 6 |
| 12 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
|* 13 | CONNECT BY WITH FILTERING | | | | |
| 14 | NESTED LOOPS | | | | |
|* 15 | HASH JOIN | | 58 | 2262 | 5 |
| 16 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 17 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 18 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 19 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 20 | NESTED LOOPS | | | | |
| 21 | BUFFER SORT | | 3 | 54 | |
| 22 | CONNECT BY PUMP | | | | |
|* 23 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 24 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 25 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 26 | FILTER | | | | |
|* 27 | CONNECT BY WITH FILTERING | | | | |
|* 28 | FILTER | | | | |
| 29 | COUNT | | | | |
|* 30 | HASH JOIN | | 1336 | 82832 | 9 |
| 31 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 32 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 33 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 34 | NESTED LOOPS | | 1 | 47 | 3 |
|* 35 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 36 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 37 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|* 38 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|* 39 | VIEW | VW_NSO_3 | 3 | 21 | |
|* 40 | CONNECT BY WITH FILTERING | | | | |
| 41 | NESTED LOOPS | | | | |
|* 42 | HASH JOIN | | 58 | 2262 | 5 |
| 43 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
|* 44 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 45 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 46 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 47 | NESTED LOOPS | | | | |
| 48 | BUFFER SORT | | 3 | 54 | |
| 49 | CONNECT BY PUMP | | | | |
|* 50 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 51 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 52 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 53 | HASH JOIN | | | | |
| 54 | CONNECT BY PUMP | | | | |
| 55 | COUNT | | | | |
|* 56 | HASH JOIN | | 1336 | 82832 | 9 |
| 57 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 58 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 59 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 60 | NESTED LOOPS | | 1 | 47 | 3 |
|* 61 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 62 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 63 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|* 64 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|* 65 | VIEW | VW_NSO_3 | 3 | 21 | |
|* 66 | CONNECT BY WITH FILTERING | | | | |
| 67 | NESTED LOOPS | | | | |
|* 68 | HASH JOIN | | 58 | 2262 | 5 |
| 69 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 70 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 71 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 72 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 73 | NESTED LOOPS | | | | |
| 74 | BUFFER SORT | | 3 | 54 | |
| 75 | CONNECT BY PUMP | | | | |
|* 76 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|* 77 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 78 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|* 79 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|* 80 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 81 | HASH JOIN | | | | |
| 82 | CONNECT BY PUMP | | | | |
| 83 | COUNT | | | | |
| 84 | VIEW | | 1352 | 5385K| 40 |
| 85 | SORT UNIQUE | | 1352 | 84128 | 40 |
| 86 | UNION-ALL | | | | |
|* 87 | HASH JOIN ANTI | | 16 | 1296 | 12 |
|* 88 | HASH JOIN | | 19 | 1406 | 9 |
| 89 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 90 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
|* 91 | TABLE ACCESS FULL | RETAILER | 32 | 1408 | 6 |
| 92 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
|* 93 | CONNECT BY WITH FILTERING | | | | |
| 94 | NESTED LOOPS | | | | |
|* 95 | HASH JOIN | | 58 | 2262 | 5 |
| 96 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|* 97 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 98 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 99 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 100 | NESTED LOOPS | | | | |
| 101 | BUFFER SORT | | 3 | 54 | |
| 102 | CONNECT BY PUMP | | | | |
|*103 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*104 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*105 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*106 | FILTER | | | | |
|*107 | CONNECT BY WITH FILTERING | | | | |
|*108 | FILTER | | | | |
| 109 | COUNT | | | | |
|*110 | HASH JOIN | | 1336 | 82832 | 9 |
| 111 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 112 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 113 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 114 | NESTED LOOPS | | 1 | 47 | 3 |
|*115 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*116 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*117 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|*118 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|*119 | VIEW | VW_NSO_3 | 3 | 21 | |
|*120 | CONNECT BY WITH FILTERING | | | | |
| 121 | NESTED LOOPS | | | | |
|*122 | HASH JOIN | | 58 | 2262 | 5 |
| 123 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
|*124 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 125 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 126 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 127 | NESTED LOOPS | | | | |
| 128 | BUFFER SORT | | 3 | 54 | |
| 129 | CONNECT BY PUMP | | | | |
|*130 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*131 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*132 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
| 133 | HASH JOIN | | | | |
| 134 | CONNECT BY PUMP | | | | |
| 135 | COUNT | | | | |
|*136 | HASH JOIN | | 1336 | 82832 | 9 |
| 137 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
| 138 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
| 139 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
| 140 | NESTED LOOPS | | 1 | 47 | 3 |
|*141 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*142 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*143 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
|*144 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
|*145 | VIEW | VW_NSO_3 | 3 | 21 | |
|*146 | CONNECT BY WITH FILTERING | | | | |
| 147 | NESTED LOOPS | | | | |
|*148 | HASH JOIN | | 58 | 2262 | 5 |
| 149 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
|*150 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
| 151 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
| 152 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
| 153 | NESTED LOOPS | | | | |
| 154 | BUFFER SORT | | 3 | 54 | |
| 155 | CONNECT BY PUMP | | | | |
|*156 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
|*157 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*158 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
|*159 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
|*160 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
11 - filter("B"."STATUS"='ACTIVE')
13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
24 - filter("A"."MANAGED_BY"='Y')
25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
."MANAGED_BY"='Y'))
27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
"SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE' -
What step need to take to tune the below query?
select LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(USER_ID,'/') AS USER_ID, user_nm USER_NM,LEVEL AS MAX_LEVEL from ( SELECT /*+ use_hash(GS_USER)*/ DISTINCT null PARENT_USER_ID, USER_ID user_id, user_nm FROM GSUSER WHERE GC_DEALER_USER_FLG='G' AND USER_ID IN ( SELECT B.PARENT_USER_ID FROM USER_HIERARCHY B,USER_COUNTRY_MAP A WHERE B.USER_ID=A.USER_ID AND A.COUNTRY_CD = ?)AND USER_ID NOT IN (SELECT B.USER_ID FROM USER_HIERARCHY B,USER_COUNTRY_MAP A WHERE B.USER_ID=A.USER_ID AND A.COUNTRY_CD = ?)AND ROLE_NM = 'GISU' AND UPPER(STATUS) = 'ACTIVE' UNION SELECT /*use_hash(B)*/ NULL as PARENT_USER_ID, B.USER_ID, USER_NM FROM GS_USER B, USER_COUNTRY_MAP A WHERE B.USER_ID=A.USER_ID AND A.COUNTRY_CD =? AND B.GC_DEALER_USER_FLG='G' AND B.ROLE_NM = 'GISU' AND UPPER(B.STATUS) = 'ACTIVE' AND B.USER_ID NOT IN ( SELECT PARENT_USER_ID FROM USER_HIERARCHY) AND B.USER_ID NOT IN ( SELECT USER_ID FROM USER_HIERARCHY) UNION SELECT /*use_hash(B)*/ DISTINCT a.parent_user_id PARENT_USER_ID,a.user_id USER_ID, b.user_nm FROM GS_USER B, USER_HIERARCHY A WHERE B.USER_ID=A.USER_ID AND B.ROLE_NM = 'GISU' AND UPPER(B.STATUS) = 'ACTIVE' AND B.GC_DEALER_USER_FLG ='G' START WITH A.PARENT_USER_ID in ( SELECT distinct a.USER_ID FROM GS_USER a, USER_HIERARCHY b, USER_COUNTRY_MAP c WHERE a.GC_DEALER_USER_FLG='G' AND a.USER_ID = b.parent_user_id AND b.user_id = c.user_id and c.COUNTRY_CD = ? AND a.user_id NOT IN (SELECT B.USER_ID FROM USER_HIERARCHY B,USER_COUNTRY_MAP A WHERE B.USER_ID=A.USER_ID AND A.COUNTRY_CD = c.country_cd ) AND ROLE_NM = 'GISU' AND UPPER(STATUS) = 'ACTIVE' ) CONNECT BY PRIOR A.USER_ID = A.PARENT_USER_ID ) start with parent_user_id is null connect by prior user_id = parent_user_id ORDER SIBLINGS BY UPPER(USER_NM) ASC
Please find below the explain plan for the same and some db parameter details:
NAME TYPE VALUE
filesystemio_options string
object_cache_optimal_size integer 102400
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_max_permutations integer 2000
optimizer_mode string ALL_ROWS
SQL> /
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 3681 | 373K| | 169 |
|* 1 | CONNECT BY WITH FILTERING | | | | | |
|* 2 | FILTER | | | | | |
| 3 | COUNT | | | | | |
| 4 | VIEW | | 3681 | 373K| | 99 |
| 5 | SORT UNIQUE | | 3681 | 319K| 776K| 99 |
| 6 | UNION-ALL | | | | | |
| 7 | NESTED LOOPS | | 1 | 119 | | 9 |
| 8 | NESTED LOOPS | | 1 | 106 | | 9 |
|* 9 | HASH JOIN ANTI | | 1 | 72 | | 7 |
| 10 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 6 | 330 | | 2 |
|* 11 | INDEX RANGE SCAN | INDX_GSSUSR_FLGROLESTS | 6 | | | 1 |
| 12 | VIEW | VW_NSO_1 | 642 | 10914 | | 4 |
| 13 | NESTED LOOPS | | 642 | 23754 | | 4 |
| 14 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 62543 | | 4 |
|* 15 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 16 | TABLE ACCESS BY INDEX ROWID | USER_HIERARCHY | 1 | 34 | | 2 |
|* 17 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|* 18 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 13 | | |
| 19 | NESTED LOOPS ANTI | | 1 | 109 | | 4 |
| 20 | NESTED LOOPS ANTI | | 1 | 92 | | 3 |
| 21 | NESTED LOOPS | | 1 | 75 | | 2 |
| 22 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 6 | 330 | | 2 |
|* 23 | INDEX RANGE SCAN | INDX_GSSUSR_FLGROLESTS | 6 | | | 1 |
|* 24 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
|* 25 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 3679 | 62543 | | 1 |
|* 26 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3679 | 62543 | | 1 |
|* 27 | FILTER | | | | | |
|* 28 | CONNECT BY WITH FILTERING | | | | | |
|* 29 | FILTER | | | | | |
| 30 | COUNT | | | | | |
|* 31 | HASH JOIN | | 3679 | 319K| | 20 |
| 32 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 122K| | 4 |
| 33 | TABLE ACCESS FULL | GSS_USER | 6580 | 353K| | 9 |
| 34 | NESTED LOOPS | | 1 | 94 | | 4 |
| 35 | NESTED LOOPS | | 3 | 222 | | 4 |
|* 36 | TABLE ACCESS BY INDEX ROWID| GSS_USER | 1 | 40 | | 2 |
|* 37 | INDEX UNIQUE SCAN | XPKGSS_USER | 6580 | | | 1 |
| 38 | TABLE ACCESS BY INDEX ROWID| USER_HIERARCHY | 3 | 102 | | 2 |
|* 39 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|* 40 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 41 | NESTED LOOPS | | 1 | 37 | | 2 |
|* 42 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 1 | 17 | | 2 |
|* 43 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 44 | HASH JOIN | | | | | |
| 45 | CONNECT BY PUMP | | | | | |
| 46 | COUNT | | | | | |
|* 47 | HASH JOIN | | 3679 | 319K| | 20 |
| 48 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 122K| | 4 |
| 49 | TABLE ACCESS FULL | GSS_USER | 6580 | 353K| | 9 |
| 50 | NESTED LOOPS | | 1 | 94 | | 4 |
| 51 | NESTED LOOPS | | 3 | 222 | | 4 |
|* 52 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 1 | 40 | | 2 |
|* 53 | INDEX UNIQUE SCAN | XPKGSS_USER | 6580 | | | 1 |
| 54 | TABLE ACCESS BY INDEX ROWID | USER_HIERARCHY | 3 | 102 | | 2 |
|* 55 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|* 56 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 57 | NESTED LOOPS | | 1 | 37 | | 2 |
|* 58 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 1 | 17 | | 2 |
|* 59 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 60 | HASH JOIN | | | | | |
| 61 | CONNECT BY PUMP | | | | | |
| 62 | COUNT | | | | | |
| 63 | VIEW | | 3681 | 373K| | 99 |
| 64 | SORT UNIQUE | | 3681 | 319K| 776K| 99 |
| 65 | UNION-ALL | | | | | |
| 66 | NESTED LOOPS | | 1 | 119 | | 9 |
| 67 | NESTED LOOPS | | 1 | 106 | | 9 |
|* 68 | HASH JOIN ANTI | | 1 | 72 | | 7 |
| 69 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 6 | 330 | | 2 |
|* 70 | INDEX RANGE SCAN | INDX_GSSUSR_FLGROLESTS | 6 | | | 1 |
| 71 | VIEW | VW_NSO_1 | 642 | 10914 | | 4 |
| 72 | NESTED LOOPS | | 642 | 23754 | | 4 |
| 73 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 62543 | | 4 |
|* 74 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 75 | TABLE ACCESS BY INDEX ROWID | USER_HIERARCHY | 1 | 34 | | 2 |
|* 76 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|* 77 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 13 | | |
| 78 | NESTED LOOPS ANTI | | 1 | 109 | | 4 |
| 79 | NESTED LOOPS ANTI | | 1 | 92 | | 3 |
| 80 | NESTED LOOPS | | 1 | 75 | | 2 |
| 81 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 6 | 330 | | 2 |
|* 82 | INDEX RANGE SCAN | INDX_GSSUSR_FLGROLESTS | 6 | | | 1 |
|* 83 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
|* 84 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 3679 | 62543 | | 1 |
|* 85 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3679 | 62543 | | 1 |
|* 86 | FILTER | | | | | |
|* 87 | CONNECT BY WITH FILTERING | | | | | |
|* 88 | FILTER | | | | | |
| 89 | COUNT | | | | | |
|* 90 | HASH JOIN | | 3679 | 319K| | 20 |
| 91 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 122K| | 4 |
| 92 | TABLE ACCESS FULL | GSS_USER | 6580 | 353K| | 9 |
| 93 | NESTED LOOPS | | 1 | 94 | | 4 |
| 94 | NESTED LOOPS | | 3 | 222 | | 4 |
|* 95 | TABLE ACCESS BY INDEX ROWID| GSS_USER | 1 | 40 | | 2 |
|* 96 | INDEX UNIQUE SCAN | XPKGSS_USER | 6580 | | | 1 |
| 97 | TABLE ACCESS BY INDEX ROWID| USER_HIERARCHY | 3 | 102 | | 2 |
|* 98 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|* 99 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 100 | NESTED LOOPS | | 1 | 37 | | 2 |
|*101 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 1 | 17 | | 2 |
|*102 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 103 | HASH JOIN | | | | | |
| 104 | CONNECT BY PUMP | | | | | |
| 105 | COUNT | | | | | |
|*106 | HASH JOIN | | 3679 | 319K| | 20 |
| 107 | INDEX FAST FULL SCAN | XPKGSS_USER_HIERARCHY | 3679 | 122K| | 4 |
| 108 | TABLE ACCESS FULL | GSS_USER | 6580 | 353K| | 9 |
| 109 | NESTED LOOPS | | 1 | 94 | | 4 |
| 110 | NESTED LOOPS | | 3 | 222 | | 4 |
|*111 | TABLE ACCESS BY INDEX ROWID | GSS_USER | 1 | 40 | | 2 |
|*112 | INDEX UNIQUE SCAN | XPKGSS_USER | 6580 | | | 1 |
| 113 | TABLE ACCESS BY INDEX ROWID | USER_HIERARCHY | 3 | 102 | | 2 |
|*114 | INDEX RANGE SCAN | GSS_USER_HIER_PARENT_USER_ID | 3 | | | 1 |
|*115 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
| 116 | NESTED LOOPS | | 1 | 37 | | 2 |
|*117 | INDEX RANGE SCAN | XPKGSS_USER_HIERARCHY | 1 | 17 | | 2 |
|*118 | INDEX UNIQUE SCAN | SYS_C005426 | 1 | 20 | | |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_001"."PARENT_USER_ID" IS NULL)
2 - filter("from$_subquery$_001"."PARENT_USER_ID" IS NULL)
9 - access("GSS_USER"."USER_ID"="VW_NSO_1"."$nso_col_1")
11 - access("GSS_USER"."GMAC_DEALER_USER_FLG"='G' AND "GSS_USER"."ROLE_NM"='GISU' AND "GSS_USER"."STATUS"='
ACTIVE')
15 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
17 - access("GSS_USER"."USER_ID"="B"."PARENT_USER_ID")
18 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
23 - access("B"."GMAC_DEALER_USER_FLG"='G' AND "B"."ROLE_NM"='GISU' AND "B"."STATUS"='ACTIVE')
24 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
25 - access("B"."USER_ID"="USER_HIERARCHY"."USER_ID")
26 - access("B"."USER_ID"="USER_HIERARCHY"."PARENT_USER_ID")
27 - filter("B"."ROLE_NM"='GISU' AND "B"."STATUS"='ACTIVE' AND "B"."GMAC_DEALER_USER_FLG"='G')
28 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "SYS_ALIAS_2","USER_HIERARCHY" "B","GSS_USER"
"SYS_ALIAS_1" WHERE "SYS_ALIAS_1"."USER_ID"=:B1 AND "SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AN
D "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."STATUS"='ACTIVE' AND "SYS_ALIAS_1"."USER_ID
"="B"."PARENT_USER_ID" AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID" AND "SYS_ALIAS_2"."COUNTRY_CD"
='AU' AND NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "
B"."USER_ID"=:B2 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B3)))
29 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "SYS_ALIAS_2","USER_HIERARCHY" "B","GSS_USER"
"SYS_ALIAS_1" WHERE "SYS_ALIAS_1"."USER_ID"=:B1 AND "SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AN
D "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."STATUS"='ACTIVE' AND "SYS_ALIAS_1"."USER_ID
"="B"."PARENT_USER_ID" AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID" AND "SYS_ALIAS_2"."COUNTRY_CD"
='AU' AND NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "
B"."USER_ID"=:B2 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B3)))
31 - access("B"."USER_ID"="SYS_ALIAS_1"."USER_ID")
36 - filter("SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AND "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."
STATUS"='ACTIVE')
37 - access("SYS_ALIAS_1"."USER_ID"=:B1)
39 - access("SYS_ALIAS_1"."USER_ID"="B"."PARENT_USER_ID")
40 - access("SYS_ALIAS_2"."COUNTRY_CD"='AU' AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID")
filter( NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "B"."USER_I
D"=:B1 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B2))
42 - access("B"."USER_ID"=:B1)
43 - access("A"."COUNTRY_CD"=:B1 AND "B"."USER_ID"="A"."USER_ID")
47 - access("B"."USER_ID"="SYS_ALIAS_1"."USER_ID")
52 - filter("SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AND "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."
STATUS"='ACTIVE')
53 - access("SYS_ALIAS_1"."USER_ID"=:B1)
55 - access("SYS_ALIAS_1"."USER_ID"="B"."PARENT_USER_ID")
56 - access("SYS_ALIAS_2"."COUNTRY_CD"='AU' AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID")
filter( NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "B"."USER_I
D"=:B1 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B2))
58 - access("B"."USER_ID"=:B1)
59 - access("A"."COUNTRY_CD"=:B1 AND "B"."USER_ID"="A"."USER_ID")
68 - access("GSS_USER"."USER_ID"="VW_NSO_1"."$nso_col_1")
70 - access("GSS_USER"."GMAC_DEALER_USER_FLG"='G' AND "GSS_USER"."ROLE_NM"='GISU' AND "GSS_USER"."STATUS"='
ACTIVE')
74 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
76 - access("GSS_USER"."USER_ID"="B"."PARENT_USER_ID")
77 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
82 - access("B"."GMAC_DEALER_USER_FLG"='G' AND "B"."ROLE_NM"='GISU' AND "B"."STATUS"='ACTIVE')
83 - access("A"."COUNTRY_CD"='AU' AND "B"."USER_ID"="A"."USER_ID")
84 - access("B"."USER_ID"="USER_HIERARCHY"."USER_ID")
85 - access("B"."USER_ID"="USER_HIERARCHY"."PARENT_USER_ID")
86 - filter("B"."ROLE_NM"='GISU' AND "B"."STATUS"='ACTIVE' AND "B"."GMAC_DEALER_USER_FLG"='G')
87 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "SYS_ALIAS_2","USER_HIERARCHY" "B","GSS_USER"
"SYS_ALIAS_1" WHERE "SYS_ALIAS_1"."USER_ID"=:B1 AND "SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AN
D "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."STATUS"='ACTIVE' AND "SYS_ALIAS_1"."USER_ID
"="B"."PARENT_USER_ID" AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID" AND "SYS_ALIAS_2"."COUNTRY_CD"
='AU' AND NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "
B"."USER_ID"=:B2 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B3)))
88 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "SYS_ALIAS_2","USER_HIERARCHY" "B","GSS_USER"
"SYS_ALIAS_1" WHERE "SYS_ALIAS_1"."USER_ID"=:B1 AND "SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AN
D "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."STATUS"='ACTIVE' AND "SYS_ALIAS_1"."USER_ID
"="B"."PARENT_USER_ID" AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID" AND "SYS_ALIAS_2"."COUNTRY_CD"
='AU' AND NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "
B"."USER_ID"=:B2 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B3)))
90 - access("B"."USER_ID"="SYS_ALIAS_1"."USER_ID")
95 - filter("SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AND "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."
STATUS"='ACTIVE')
96 - access("SYS_ALIAS_1"."USER_ID"=:B1)
98 - access("SYS_ALIAS_1"."USER_ID"="B"."PARENT_USER_ID")
99 - access("SYS_ALIAS_2"."COUNTRY_CD"='AU' AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID")
filter( NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "B"."USER_I
D"=:B1 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B2))
101 - access("B"."USER_ID"=:B1)
102 - access("A"."COUNTRY_CD"=:B1 AND "B"."USER_ID"="A"."USER_ID")
106 - access("B"."USER_ID"="SYS_ALIAS_1"."USER_ID")
111 - filter("SYS_ALIAS_1"."GMAC_DEALER_USER_FLG"='G' AND "SYS_ALIAS_1"."ROLE_NM"='GISU' AND "SYS_ALIAS_1"."
STATUS"='ACTIVE')
112 - access("SYS_ALIAS_1"."USER_ID"=:B1)
114 - access("SYS_ALIAS_1"."USER_ID"="B"."PARENT_USER_ID")
115 - access("SYS_ALIAS_2"."COUNTRY_CD"='AU' AND "B"."USER_ID"="SYS_ALIAS_2"."USER_ID")
filter( NOT EXISTS (SELECT /*+ */ 0 FROM "USER_COUNTRY_MAP" "A","USER_HIERARCHY" "B" WHERE "B"."USER_I
D"=:B1 AND "B"."USER_ID"="A"."USER_ID" AND "A"."COUNTRY_CD"=:B2))
117 - access("B"."USER_ID"=:B1)
118 - access("A"."COUNTRY_CD"=:B1 AND "B"."USER_ID"="A"."USER_ID")
Note: cpu costing is off
218 rows selected.
Please give me some tips or clue ,so that I can reduce the more cost for the same.
Thanks in adv. -
How to tune the below query?is taking 1min 15 sec to process 16,34,300 reco
SELECT
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt);Do you have multiprocessor CPU .
if the value is greater then 3 then you can try with parallel processing
select value from v$parameter where name ='cpu_count' ;Try this :-
ALTER SESSION ENABLE PARALLEL QUERY
SELECT /*+ parallel (a) */
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit),
min(start_time_utc) ,
max(end_time_utc),
min(srt.activedt),
min(srt.inactivedt)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid(+)
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt)Cheers
Nawneet
Edited by: Nawneet_Aswal on Aug 2, 2010 4:48 AM -
How to execute the output of the below query automatically
Hi All,
I want to execute the output of the below query automatically, instead of manually copying it and execute.
select 'alter database ['+name+'] set recovery simple' from master.sys.databases where database_id > 4 and state_desc = 'online'
Please provide me a script to do this.
ThanK
KateEXEC sp_MSforeachdb N'ALTER DATABASE [?] SET recovery simple';--- This will set the recovery model for all the system database.The query provided by Vikash16, meets my requirement. Thank you.
-
I am getting "Invalid Identifier" while running the below query
Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
select a.*, b.pog_description pog_description, b.start_date,
row_number() over(partition by b.pog_description order by b.start_date) c_rank
from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
where a.sku = c.pog_sku
and b.pog_id = c.pog_id
and b.pog_dept = c.pog_dept
and b.pog_number = c.pog_number
and b.pog_level = c.pog_level
and a.sku = 10263477
and c_rank = 1;>
Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
select a.*, b.pog_description pog_description, b.start_date,
row_number() over(partition by b.pog_description order by b.start_date) c_rank
from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
where a.sku = c.pog_sku
and b.pog_id = c.pog_id
and b.pog_dept = c.pog_dept
and b.pog_number = c.pog_number
and b.pog_level = c.pog_level
and a.sku = 10263477
and c_rank = 1;
>
You can't use 'c_rank' in the where clause because it doesn't exist; you are computing it in the SELECT clause.
Remove the last condition and wrap your query in another one to select by 'c_rank'. -
How the below query is working
Hi,
I am newly joined in the group.
the emp table has 5 rows as below
100 ram 10000.00 10
200 kumar 15000.00 10
300 william 20000.00 10
400 ravi 25000.00 10
500 victor 30000.00 10
i execute the below query
select ename,sal from emp_test where case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end < 20000
it gives the below output
ram 10000.00
kumar 15000.00
How the above query is working?
Please explain. thanks in advanceIf you want it to show the changed salary, it has to be in the select line not the where:
select ename,
(case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end) sal from emp_test
where case when sal < 10000 then sal + 1000
when sal < 20000 then sal + 2000
else sal
end < 20000 -
I had put apple tv to update and later noticed that it is requesting for connecting the micro USB plus the white light blinking
Yeah.
#FAIL #FAIL #FAIL
Since our preemie woke me at 04:00 this morning and I had nothing better to do--I let the ATV3 connected to our "main viewer" 'update'.
Got a screen showing what at first bleery-eyed glance looks like a HDMI-to-iPod/iPhone/Ipad cable wanting iTunes.
Fast blinking white indicator light.
Pretty much BRICKED.
I shall attempt the USB-mircoUSB after another cup of coffee.
Really GLAD I did not update the two ATV2s.
UPSIDE: discovered that one can make the same content play on ALL ATVs simultaneously from iTunes on the main machine... -
Reduce the execution time for the below query
Hi,
Please help me to reduce the execution time on the following query .. if any tuning is possible.
I have a table A with the columns :
ID , ORG_LINEAGE , INCLUDE_IND ( -- the org lineage is a string of ID's. If ID 5 reports to 4 and 4 to 1 .. the lineage for 5 will be stored as the string -1-4-5)
Below is the query ..
select ID
from A a
where INCLUDE_IND = '1' and
exists (
select 1
from A b
where b.ID = '5'
and b.ORG_LINEAGE like '%-'||a.ID||'-%'
order by ORG_LINEAGE;
The only constraint on the table A is the primary key on the ID column.
Following will be the execution plan :
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=406 Card=379 Bytes=2
653)
1 0 SORT (ORDER BY) (Cost=27 Card=379 Bytes=2653)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'A' (Cost=24 Card
=379 Bytes=2653)
4 2 TABLE ACCESS (BY INDEX ROWID) OF 'A' (Co
st=1 Card=1 Bytes=6)
5 4 INDEX (RANGE SCAN) OF 'ORG_LINEAGE'
(NON-UNIQUE)I order it by the org_lineage to get the first person. So it is a result problem? The order by doesn't give you the first person, it gives you a sorted result set (of which there may be zero, one, or thousands).
If you only want one row from that, then you're spending a lot of time tuning the wrong query.
How do you know which ORG_LINEAGE row you want?
Maybe it would help if you posted some sample data. -
Do I need to tune the base query of my materialized view ?
Hi gurus,
We implement materialized view (FAST REFRESH ON COMMIT) on base table used in OLTP system. In fact the MV itself is also queried by the OLTP system itself, interactively.
Currently user complain that after they input transaction, they see that the MV is not refresh as soon as they commit the transaction.
(it takes 5 to 10 minutes before they see the update on the MV)
The query of the MV is attached below, it consists of union all of two queries but actually the real query has 13 queries on a UNION ALL.
The question is :
Do I need to tune the query that forms the MV ?
Does it impact the refresh time of the MV ?
Thank you for your help,
xtanto
SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
F_Convert_Qty_K(GRND.PRODUCT, GRND.QTY, GRND.UOM) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'.....
FROM GRN_LOCAL_D GRND
JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
WHERE GRND.PRODUCT IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
UNION ALL
SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
F_Convert_Qty_K(GRND.PRODUCT_B, GRND.QTY_B, GRND.UOM_B) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'...
FROM GRN_LOCAL_D GRND
JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
WHERE GRND.PRODUCT_B IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
UNION ALL
......Hi Justin & APC,
Are they seeing a 5-10 minute delay in being able to commit their transaction?NO, the commit itself is completed normally, but after that when they go to the page (this is webbased app) that display data from the MV, the newly committed transactionis not there yet. Only after 5-10 minutes we can see the new data.
What does the F_Convert_Qty_K() function do?It is a function that convert the quantity from whatever Unit Of Measurement (UOM) into the smallest UOM. Below is the code.
So the question remains:
why intermittently theere is delay before the new data visible in the MV ?
Thanks you,
xtanto
CREATE OR REPLACE FUNCTION F_Convert_Qty (pProduct VARCHAR2, pQty NUMBER, pUOM VARCHAR2)
RETURN NUMBER
IS
vQtyBase NUMBER(13,5);
BEGIN
SELECT CASE WHEN pUOM = ( SELECT UOM_BASE FROM PRODUCTS WHERE PRODUCT = pProduct)
THEN pQty
ELSE
SELECT ROUND(pQty * Coefficient / Divisor, 5)
FROM (
SELECT Coefficient, Divisor FROM CONVERT_UOM
WHERE PRODUCT = pProduct AND UOM_CONVERT = pUOM
) tmp
END INTO vQtyBase FROM DUAL;
--RETURN (vQtyBase) ;
RETURN ( NVL(vQtyBase,0) ) ;
END F_Convert_Qty;
/ -
How can I replace the cursor in the below query?
I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
DECLARE db_cursor_ava CURSOR
FOR
SELECT t.[agent-id],
t.[start-date],
t.[end-date],
t.[monitor-days],
t.[monitor-start],
t.[monitor-end],
t.[timezone-offset]
FROM @tmpAgentPeriodTimeRange t
OPEN db_cursor_ava
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE
FROM @tmpMonitorPeriod
DELETE
FROM @tmpFinalResult
SET @runID = 1
IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
BEGIN
SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
END
INSERT INTO @tmpMonitorPeriod
EXEC core.usp_GetMonitoringPeriod
@startDate = @stDateTime_ava,
@endDate = @endDateTime_ava,
@monitoringDays = @monDays_ava,
@monitoringStart = @monSt_ava,
@monitoringEnd = @monEnd_ava
SELECT @maxID = MAX(tm.id)
FROM @tmpMonitorPeriod tm
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
END
CLOSE db_cursor_ava
DEALLOCATE db_cursor_ava
mayooran99You've been down this path before - and the response is exactly the same.
how to replace cursor logic
And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach. Who knows
- but it appears you may have prematurely assumed that the cursor is the problem. -
Need help on the below query or Pl-SQL
Hello Every one,
Please let me know if some one can help me out with the below scenario either in pl-sql or sql.
Source Data:
0000253800 0.25 0845A 0900A
0000253800 1 0900A 1000A
0000253800 1 1300P 1400P
0000253800 1 1500P 1600P
0000253800 1 1600P 1700P
Output needed:
0000253800 1.25 0845A 1000A
0000253800 1 1300P 1400P
0000253800 2 1500P 1700P
Thanks in Advance....
Edited by: user12564103 on Dec 11, 2011 5:54 PMHi,
Welcome to the forum!
Depending on your data and your requirements:
WITH got_times AS
SELECT column_1, column_2, column_3, column_4
, TO_DATE ( substr (column_3, 1, 4)
, 'HH24MI'
) AS time_3
, TO_DATE ( SUBSTR (column_4, 1, 4)
, 'HH24MI'
) AS time_4
FROM table_x
, got_grp_id AS
SELECT column_1, column_2, column_3, column_4
, time_3, time_4
, time_4 - SUM (time_4 - time_3) OVER ( PARTITION BY column_1
ORDER BY time_3
) AS grp_id
FROM got_times
SELECT column_1
, SUM (column_2) AS sum_2
, MIN (column_3) KEEP (DENSE_RANK FIRST ORDER BY time_3)
AS min_3
, MAX (column_4) KEEP (DENSE_RANK LAST ORDER BY time_4)
AS max_4
FROM got_grp_id
GROUP BY column_1
, grp_id
ORDER BY column_1
, grp_id
;Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, as well as the results you want from that data. Explain, with specific examples, how you get the results you want from that data.
Always say which version of Oracle you're using. The query above will work in Oracle 9.1 (and higher).
Since this is your first thread, I'll do this for you:
CREATE TABLE table_x
( column_1 NUMBER
, column_2 NUMBER
, column_3 VARCHAR2 (5)
, column_4 VARCHAR2 (5)
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, .25, '0845A', '0900A');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1, '0900A', '1000A');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1, '1300P', '1400P');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1, '1500P', '1600P');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1, '1600P', '1700P');Column_1 identifes a day.
Column_2 is an amount that I need to total.
Column_3 and column_4 are starting and ending times. We can assume that they are all valid times (in 'HH24MI' format, plus a redundant 'A' or 'P') on the same day, column_3 is always less than column_4, and that the range of two rows for the same value of column_1 never overlap. Column_4 of one row may be equal to column_3 of another rows with the same column_1, but it will never be greater.
Each row of the output represent a contiguous group of rows (each ending exactly when the next one begins) with the same column_1, with the common column_1, the total of column_2, and the range of the group.
For example, the first two rows for a single group, because they have the same value for column_1, and one ends exactly when the other begins (at 9:00 AM). This group represents day 253800, from 8:45 AM to 10:00 AM. The totla of column_2 fro this group is .25 + 1 = 1.25.
The next row (from 1:00 PM to 2:00 PM) is a group all by itself, because there is a gap one either side of it separating it from its nearest neighbor on the same day."
Of course, I'm guessing at lots of things.
Edited by: Frank Kulash on Dec 11, 2011 9:44 PM
Changed TO_DATE calls.
Edited by: Frank Kulash on Dec 11, 2011 9:52 PM
Added sample question. -
Tune the SQL Query need a Suggestion
Hi,
There is a view created which takes 17seconds to execute the query, When i split the query and execute each query takes .15 seconds to execute. Below it the query which i need to improve the performance of the code please need your suggestion in order to tweek so that time take for execution become less
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_1 "Product Name",
TRIM (UPPER (serial_number_1)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_1 != 'NULL'
AND Serial_Number_1 != 'NULL'
AND C.Amid = A.Amid(+)
UNION
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_2 "Product Name",
TRIM (UPPER (serial_number_2)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_2 != 'NULL'
AND serial_number_2 != 'NULL'
AND C.Amid = A.Amid(+)
UNION
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_3 "Product Name",
TRIM (UPPER (serial_number_3)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_3 != 'NULL'
AND serial_number_3 != 'NULL'
AND C.Amid = A.Amid(+)
UNION
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_4 "Product Name",
TRIM (UPPER (serial_number_4)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_4 != 'NULL'
AND serial_number_4 != 'NULL'
AND C.Amid = A.Amid(+)
UNION
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_5 "Product Name",
TRIM (UPPER (serial_number_5)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_5 != 'NULL'
AND serial_number_5 != 'NULL'
AND C.Amid = A.Amid(+)
UNION
SELECT 'ERP' "Source",
Imv.Bill_To "Distibutor",
Imv.Ship_To "Reseller",
Ship_To_City "Reseller City",
Ship_To_State "Reseller State",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
Cl.Company_Name "Customer Name",
Cl.City "Customer City",
Cl.State "Customer State",
Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
Imv.So_Booked_Date "Sales Book Date",
Imv.Ship_Date "Ship Date",
Imv.Order_Number "Sales Order Number",
Imv.Cust_Po_Number "PO Number",
Cp.Item_Name "Product Name",
Cp.Product_Serial_Number "Product Serial Number",
TO_CHAR(Imv.contract_number)"Contract ID",
Imv.Service_Description "Support Name",
Imv.Service_Start_Date "Start Date",
Imv.Service_End_Date "Expire Date",
Imv.Header_Status "Header Status",
Imv.Line_Status "Line Status",
Imv.Line_Type "Line Type",
Imv.Termination_Reason "Termination Reason",
Cl.Location_Id "Location_id",
cp.id "Product_id"
FROM ib_support_contracts_mv imv,
customer_products cp,
customer_locations cl
WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
AND Cp.Location_Id = Cl.Location_Id(+)
There is a union for each and every query, Please suggest how to tweek
Thanks
SudhirTry
select distinct a.*
from (SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_1 "Product Name",
TRIM (UPPER (serial_number_1)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_1 != 'NULL'
AND Serial_Number_1 != 'NULL'
AND C.Amid = A.Amid(+)
union all
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_2 "Product Name",
TRIM (UPPER (serial_number_2)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_2 != 'NULL'
AND serial_number_2 != 'NULL'
AND C.Amid = A.Amid(+)
union all
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_3 "Product Name",
TRIM (UPPER (serial_number_3)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_3 != 'NULL'
AND serial_number_3 != 'NULL'
AND C.Amid = A.Amid(+)
union all
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_4 "Product Name",
TRIM (UPPER (serial_number_4)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_4 != 'NULL'
AND serial_number_4 != 'NULL'
AND C.Amid = A.Amid(+)
union all
SELECT 'Parature' "Source",
NULL "Distibutor",
reseller_name "Reseller",
NULL "Reseller City",
NULL "Reseller State",
A.Country "Reseller Country",
DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
NULL "Customer Name",
NULL "Customer City",
NULL "Customer State",
NULL "Customer Country",
NULL "Customer Theater",
NULL "Sales Book Date",
NULL "Ship Date",
c.sales_order_number "Sales Order Number",
C.Po_Number "PO Number",
controller_model_number_5 "Product Name",
TRIM (UPPER (serial_number_5)) "Product Serial Number",
c.contract_id "Contract ID",
product_name "Support Name",
TO_DATE (c.contract_purchase_date) "Start Date",
TO_DATE (c.contract_expiration_date) "Expire Date",
NULL "Header Status",
NULL "Line Status",
NULL "Line Type",
NULL "Termination Reason",
NULL "Location_id",
NULL "Product_id"
FROM edb_assets c,
edb_accounts a
WHERE controller_model_number_5 != 'NULL'
AND serial_number_5 != 'NULL'
AND C.Amid = A.Amid(+)
union all
SELECT 'ERP' "Source",
Imv.Bill_To "Distibutor",
Imv.Ship_To "Reseller",
Ship_To_City "Reseller City",
Ship_To_State "Reseller State",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
Cl.Company_Name "Customer Name",
Cl.City "Customer City",
Cl.State "Customer State",
Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
Imv.So_Booked_Date "Sales Book Date",
Imv.Ship_Date "Ship Date",
Imv.Order_Number "Sales Order Number",
Imv.Cust_Po_Number "PO Number",
Cp.Item_Name "Product Name",
Cp.Product_Serial_Number "Product Serial Number",
TO_CHAR(Imv.contract_number)"Contract ID",
Imv.Service_Description "Support Name",
Imv.Service_Start_Date "Start Date",
Imv.Service_End_Date "Expire Date",
Imv.Header_Status "Header Status",
Imv.Line_Status "Line Status",
Imv.Line_Type "Line Type",
Imv.Termination_Reason "Termination Reason",
Cl.Location_Id "Location_id",
cp.id "Product_id"
FROM ib_support_contracts_mv imv,
customer_products cp,
customer_locations cl
WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
AND Cp.Location_Id = Cl.Location_Id(+)) a
Edited by: HuaMin on May 9, 2012 2:58 PM
Maybe you are looking for
-
DNS Issues - Can ping server name and IPs but not FQDNs.
Hi All, Hopefully some one can help me here, I am having an issue where one of my domain attached servers cannot ping any FQDNs in the environment but it can ping the host names and the IPs and look up the host names from a reverse look up. We have
-
Transfer article master from SAP R/3 To External Systems(Futura) Using IDOC
Dear Experts Please let me know how to Transfer article master from SAP R/3 To External Systems(Futura) or text file Using IDOCs. thanks
-
Unknown error when trying to log into Itunes
I just got Windows 8 and i installed Itunes on it, however when i go to log in to my account it keeps stating unknown error. and it wont allow me to log into.. however when i go on my laptop i have no issue. and it runs Windows 7, What should i do?
-
Port number from verizon to family account in FL, but I live in PA
Getting an iphone 4, I currently am with verizon and am looking to port my 917 (NYC) area code number to my family account, which is in FL.... But I live in PA. (I've moved a bunch) CSR told me that I'd have to get a number local to the area where th
-
There was an error in opening the doeument.. The file cannot be found
Hi, A user from our application (IE based) is having an error in opening a pdf document. He's getting the following message: There was an error in opening the doeument. The file cannot be found. The error is ecnountered when the link of the document