Fine Tune a SQl Query
Hello ,
Please find here a query I need to enhance , it takes now above 1 minute to complete and supposed to not exceed 5 sec.
appreciate your support,
declare @@StartDate as datetime,
@@EndDate as datetime,
@@CCODE as varchar(6)
set @@StartDate = '01/01/2014'
set @@EndDate = '01/31/2014'
set @@CCODE = '0077662'
select
'ALLOWED' as Descr, @@StartDate as StartDate, @@EndDate as EndDate, LEFT(ID,6) as CCODE,COUNT(*) as No_of_CUST,COUNT(IDs) as No_of_IDs
from dbo.tbl_tableMaster
where
date between @@startdate and @@Enddate
and Type = 0
and code = 1
and KindOFMaterial in ( '00','01')
and profile = 'VIP'
and LEFT(ID,6) = @@CCODE
GROUP BY LEFT(ID,6)
If you will be able to change this procedure and use single @, I would go for it.
I know it's a bit a bad habit, but personally I almost always fix the code to my liking when I am working with some code written by anyone else. Even knowing 'if it's ain't broken don't fix it' I would go ahead and fix it.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Similar Messages
-
How to tune past SQL query??
Hi Team,
Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
I am working on 10.2.0.4 version DB..
How to trace an sql query after its execution?? pls provide steps how to begin with..
regards
dkoracledkoracle wrote:
Hi Team,
Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
I am working on 10.2.0.4 version DB..
How to trace an sql query after its execution?? pls provide steps how to begin with..Can not be done.
ALTER SESSION SET SQL_TRACE=TRUE;
-- run query again -
Hi,
TKPROF: Release 8.1.7.0.0 - Production on Wed Sep 23 23:04:43 2009
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Trace file: pindb_ora_9943.trc
Sort options: prsela exeela fchela fchela
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
SELECT f.poid_id0, COUNT (*), SUM (amount), d.subscription_amt, d.free_mb
FROM event_t a,
event_bal_impacts_t b,
(SELECT DISTINCT a.obj_id0 AS account_obj_id0, a.node_location,
a.plan_obj_id0
FROM account_products_t a
WHERE plan_obj_id0 > 0 AND service_obj_id0 > 0
UNION
SELECT DISTINCT a.account_obj_id0, a.node_location, a.plan_obj_id0
FROM audit_account_products_t a
WHERE plan_obj_id0 > 0
AND service_obj_id0 > 0
AND effective_end_t > 0) c,
iq_prov_tags_t d,
event_session_dialup_t e,
plan_t f
WHERE a.poid_id0 = b.obj_id0
AND a.poid_id0 = e.obj_id0
AND b.node_location = c.node_location
AND a.account_obj_id0 = c.account_obj_id0
AND c.plan_obj_id0 = d.plan_poid_id0
AND d.plan_poid_id0 = f.poid_id0
AND a.end_t >= pin_date_to_seconds (TRUNC ( SYSDATE
- 1), NULL)
AND a.end_t < pin_date_to_seconds (TRUNC (SYSDATE), NULL)
AND b.resource_id IN (1000051)
GROUP BY f.poid_id0, d.subscription_amt, d.free_mb
call count cpu elapsed disk query current rows
Parse 1 0.09 0.08 0 0 0 0
Execute 2 0.07 0.07 0 0 0 0
Fetch 2 235.91 2295.25 1509704 1674184 346 11
total 5 236.07 2295.40 1509704 1674184 346 11
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 28
Rows Row Source Operation
11 SORT GROUP BY
69 NESTED LOOPS
70 NESTED LOOPS
70 NESTED LOOPS
70 HASH JOIN
70 HASH JOIN
300499 TABLE ACCESS BY INDEX ROWID EVENT_T
300500 INDEX RANGE SCAN (object id 26458)
816394 TABLE ACCESS BY INDEX ROWID EVENT_BAL_IMPACTS_T
816395 INDEX RANGE SCAN (object id 26463)
2385556 VIEW
2385556 SORT UNIQUE
3124105 UNION-ALL
638617 TABLE ACCESS FULL ACCOUNT_PRODUCTS_T
2485488 TABLE ACCESS FULL AUDIT_ACCOUNT_PRODUCTS_T
138 TABLE ACCESS BY INDEX ROWID IQ_PROV_TAGS_T
138 INDEX UNIQUE SCAN (object id 26554)
138 INDEX UNIQUE SCAN (object id 23148)
69 INDEX UNIQUE SCAN (object id 27372)
ALTER SESSION SET SQL_TRACE = TRUE
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer goal: CHOOSE
Parsing user id: 28
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 0.09 0.08 0 0 0 0
Execute 3 0.07 0.07 0 0 0 0
Fetch 2 235.91 2295.25 1509704 1674184 346 11
total 6 236.07 2295.40 1509704 1674184 346 11
Misses in library cache during parse: 1
Misses in library cache during execute: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 2 0.01 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 20 0.00 0.01 0 40 0 18
total 24 0.01 0.01 0 40 0 18
Misses in library cache during parse: 1
2 user SQL statements in session.
2 internal SQL statements in session.
4 SQL statements in session.
Trace file: pindb_ora_9943.trc
Trace file compatibility: 8.00.04
Sort options: prsela exeela fchela fchela
1 session in tracefile.
2 user SQL statements in trace file.
2 internal SQL statements in trace file.
4 SQL statements in trace file.
3 unique SQL statements in trace file.
118 lines in trace file.Inputs are appreciated
Prakash GRsorry hash joint for asking this type of question but i do not have any option since i am not query tuner i need inputs so that i can put some effort on this
Would you like a cup of tea with this my dear ?chilled beer will be offered if any inputs given
Thanks
Prakash GR -
TUNNING A SQL QUERY AND UNSERSTAND EXPLAIN PLAN
I was trying my handing in tunning sql queries -
Though I have manged to reduce the cost lil ..creating some index, but have genarated a g8 interesting in tunning - Can some experts ( I know there are lots available :-) ) help me on the approch on "HOW TO TUNE A QUERY"
moreover I also would like to understand - how to debug a explain plan, - please help ...
Regards..Hi,
Welcome to this forum...
I would suggest your to read first the official documentations :
- The concepts of an Oracle DBMS (this is important to know, because Oracle structures, processes, objects (etc) are the building blocks of your database)
- SQL reference guide
- PL/SQL reference guide
and then at a later stage the Performance and tuning guide:
You can start there:
http://download.oracle.com/docs/cd/B14117_01/nav/portal_1.htm
Once it's done maybe read the Performance and tuning guide:
http://download.oracle.com/docs/cd/B14117_01/server.101/b10752/toc.htm
(Chapter 19 explain ... how to interpret the explain plan ..)
I wish you good chance and be patient: I'm working with Oracle for more that 10 years and I'm still learning! ...
Rem: The Oracle website is full of interesting articles, and examples, just "search" your special points of interests .. -
How to tune this SQL Query?
Hi all expert out there,
I am using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options.
I have this ERP 11i query took 3-4hours to execute. can anyone help to have a look at the Query so make it more faster? I am already out of my idea of solving this. Kindly helpzzz...
SELECT
/*+ first_rows(1)*/
hou.name "OU" ,-- e.g. Seagate Technology USOP1 ,
mc.description,
oel.ordered_item "Product Part Number",
oeh.order_number "Order Num",
hp.party_name "Bill To Cust Name",
hcsu.location "Ship To Cust Num",
oel.line_number || '.' || oel.shipment_number "Order Line Num",
ft.nls_territory "Ship To Country",
mc.segment7 "designapplication",
ccm.formattedcapacity||'GB' "Capacity",
oel.attribute1 "Order Category",
oel.Subinventory "Subinventory",
to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
NVL(oel.shipped_quantity,0) "Net Units"
FROM
oe_order_headers_all oeh
,oe_order_lines_all oel
,apps.hz_parties hp
,apps.hz_cust_accounts hca
,apps.hz_cust_site_uses_all hcsu
,apps.hz_cust_acct_sites_all hcas
, apps.seaeng_ccfamilymodelinfo ccm
,apps.hz_party_sites hps
,apps.fnd_territories ft
,apps.hz_locations hl
,apps.hr_organization_units hou
,apps.mtl_parameters mp
,apps.mtl_item_categories mic
,apps.mtl_categories_b mc
,apps.fnd_lookup_values flv
WHERE
oeh.header_id = oel.header_id
AND oel.flow_status_code = 'CLOSED'
AND oeh.invoice_to_org_id = hcsu.site_use_id
AND hl.country = ft.territory_code
AND hps.location_id = hl.location_id
AND hcas.party_site_id = hps.party_site_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcas.cust_account_id = hca.cust_account_id
AND hca.party_id = hp.party_id
AND oeh.org_id = hou.organization_id
AND oel.ship_from_org_id = mp.organization_id
AND oel.inventory_item_id = mic.inventory_item_id
AND mic.category_id = mc.category_id
AND mic.category_set_id = 4
AND mc.description = ccm.stmodelnumber
AND flv.lookup_code = hca.sales_channel_code
AND flv.lookup_type = 'SALES_CHANNEL'
AND mc.segment7 IN ('PSG','ESG','NSG')
AND flv.lookup_code NOT IN ('RTL','AD-RTL','EU')
AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
AND hou.organization_id = 189
AND trunc(oel.actual_shipment_date) between TO_DATE('01-Jan-2009','DD-MON-YYYY') and TO_DATE('31-JAN-2009','DD-MON-YYYY')
regards,
Lygine
Edited by: user8989062 on Jun 7, 2010 6:39 PM5) The TKPROF output for this statement looks like the following:
SELECT
/*+ first_rows(1)*/
hou.name "OU" ,-- e.g. Seagate Technology USOP1 ,
mc.description,
oel.ordered_item "Product Part Number",
oeh.order_number "Order Num",
hp.party_name "Bill To Cust Name",
hcsu.location "Ship To Cust Num",
oel.line_number || '.' || oel.shipment_number "Order Line Num",
ft.nls_territory "Ship To Country",
mc.segment7 "designapplication",
ccm.formattedcapacity||'GB' "Capacity",
oel.attribute1 "Order Category",
oel.Subinventory "Subinventory",
to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
NVL(oel.shipped_quantity,0) "Net Units"
FROM
oe_order_headers_all oeh
,oe_order_lines_all oel
,apps.hz_parties hp
,apps.hz_cust_accounts hca
,apps.hz_cust_site_uses_all hcsu
,apps.hz_cust_acct_sites_all hcas
, apps.seaeng_ccfamilymodelinfo ccm
,apps.hz_party_sites hps
,apps.fnd_territories ft
,apps.hz_locations hl
,apps.hr_organization_units hou
,apps.mtl_parameters mp
,apps.mtl_item_categories mic
,apps.mtl_categories_b mc
,apps.fnd_lookup_values flv
WHERE
oeh.header_id = oel.header_id
AND oel.flow_status_code = 'CLOSED'
AND oeh.invoice_to_org_id = hcsu.site_use_id
AND hl.country = ft.territory_code
AND hps.location_id = hl.location_id
AND hcas.party_site_id = hps.party_site_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcas.cust_account_id = hca.cust_account_id
AND hca.party_id = hp.party_id
AND oeh.org_id = hou.organization_id
AND oel.ship_from_org_id = mp.organization_id
AND oel.inventory_item_id = mic.inventory_item_id
AND mic.category_id = mc.category_id
AND mic.category_set_id = 4
AND mc.description = ccm.stmodelnumber
AND flv.lookup_code = hca.sales_channel_code
AND flv.lookup_type = 'SALES_CHANNEL'
AND mc.segment7 IN ('PSG','ESG','NSG')
AND flv.lookup_code NOT IN ('RTL','AD-RTL','EU')
AND oel.attribute1 IN ('NB','NBEOL','NBSEA')
AND oel.subinventory IN ('KFGI','AFGI','SFGIF','FGIF')
AND hou.organization_id = 189
AND trunc(oel.actual_shipment_date) between TO_DATE('01-Jan-2009','DD-MON-YYYY') and TO_DATE('31-JAN-2009','DD-MON-YYYY')
call count cpu elapsed disk query current rows
Parse 1 0.79 0.79 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 7 22.23 240.85 19781 536082 0 592
total 9 23.02 241.64 19781 536082 0 592
Misses in library cache during parse: 1
Optimizer mode: FIRST_ROWS
Parsing user id: 173
Rows Row Source Operation
592 NESTED LOOPS (cr=536082 pr=19781 pw=0 time=240822989 us)
592 NESTED LOOPS (cr=534885 pr=19776 pw=0 time=239960969 us)
592 NESTED LOOPS (cr=533688 pr=19776 pw=0 time=239902332 us)
594 NESTED LOOPS (cr=532493 pr=19776 pw=0 time=239811721 us)
594 NESTED LOOPS (cr=531892 pr=19776 pw=0 time=239794703 us)
594 NESTED LOOPS (cr=530693 pr=19772 pw=0 time=239325284 us)
594 NESTED LOOPS (cr=529498 pr=19770 pw=0 time=239152940 us)
594 NESTED LOOPS (cr=527709 pr=19766 pw=0 time=236850676 us)
594 NESTED LOOPS (cr=525920 pr=19764 pw=0 time=235640068 us)
2990 NESTED LOOPS (cr=516943 pr=19688 pw=0 time=195144282 us)
2990 NESTED LOOPS (cr=516936 pr=19688 pw=0 time=195120297 us)
2990 NESTED LOOPS (cr=510806 pr=19682 pw=0 time=194678671 us)
3000 HASH JOIN (cr=504799 pr=19669 pw=0 time=193829763 us)
3000 NESTED LOOPS (cr=472280 pr=360 pw=0 time=49218087 us)
1 NESTED LOOPS (cr=1029 pr=34 pw=0 time=1745829 us)
1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=424 pr=25 pw=0 time=1361442 us)
1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=423 pr=25 pw=0 time=1361397 us)(object id 44637)
1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=605 pr=9 pw=0 time=384370 us)
1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 pr=0 pw=0 time=27 us)(object id 43498)
3000 TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=471251 pr=326 pw=0 time=47466249 us)
156922 INDEX RANGE SCAN OE_ORDER_LINES_N20 (cr=420 pr=7 pw=0 time=787919 us)(object id 37005064)
263469 TABLE ACCESS FULL MTL_ITEM_CATEGORIES (cr=32519 pr=19309 pw=0 time=144242743 us)
2990 TABLE ACCESS BY INDEX ROWID MTL_CATEGORIES_B (cr=6007 pr=13 pw=0 time=843569 us)
3000 INDEX UNIQUE SCAN MTL_CATEGORIES_B_U1 (cr=3007 pr=2 pw=0 time=162636 us)(object id 37199)
2990 TABLE ACCESS BY INDEX ROWID SEAENG_CCFAMILYMODELINFO (cr=6130 pr=6 pw=0 time=437784 us)
2990 INDEX UNIQUE SCAN SEAENG_CCFAMILYMODELINFO_U1 (cr=2997 pr=0 pw=0 time=52872 us)(object id 35838918)
2990 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=7 pr=0 pw=0 time=16332 us)(object id 37657)
594 TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=8977 pr=76 pw=0 time=40491633 us)
2990 INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=5987 pr=45 pw=0 time=2504442 us)(object id 41952)
594 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=1789 pr=2 pw=0 time=1208576 us)
594 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=1195 pr=1 pw=0 time=105934 us)(object id 25124976)
594 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCT_SITES_ALL (cr=1789 pr=4 pw=0 time=2300224 us)
594 INDEX UNIQUE SCAN HZ_CUST_ACCT_SITES_U1 (cr=1195 pr=2 pw=0 time=152238 us)(object id 25124996)
594 TABLE ACCESS BY INDEX ROWID HZ_PARTY_SITES (cr=1195 pr=2 pw=0 time=170875 us)
594 INDEX UNIQUE SCAN HZ_PARTY_SITES_U1 (cr=601 pr=1 pw=0 time=104550 us)(object id 25124993)
594 TABLE ACCESS BY INDEX ROWID HZ_LOCATIONS (cr=1199 pr=4 pw=0 time=467329 us)
594 INDEX UNIQUE SCAN HZ_LOCATIONS_U1 (cr=601 pr=0 pw=0 time=57749 us)(object id 25124992)
594 TABLE ACCESS BY INDEX ROWID FND_TERRITORIES (cr=601 pr=0 pw=0 time=15562 us)
594 INDEX UNIQUE SCAN FND_TERRITORIES_U1 (cr=7 pr=0 pw=0 time=6492 us)(object id 33083)
592 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=1195 pr=0 pw=0 time=88925 us)
594 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=601 pr=0 pw=0 time=27607 us)(object id 81600)
592 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=1197 pr=0 pw=0 time=56714 us)(object id 32878)
592 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=1197 pr=5 pw=0 time=860140 us)
592 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=599 pr=0 pw=0 time=51136 us)(object id 25126074)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 7 0.00 0.00
row cache lock 1 0.00 0.00
gc current block 2-way 24112 0.00 19.28
gc cr grant 2-way 406 0.00 0.19
db file sequential read 441 0.09 14.11
gc cr block 2-way 284 0.00 0.23
gc cr block busy 147 0.19 9.59
gc current block congested 2 0.00 0.00
gc cr multi block request 13079 0.00 3.98
SQL*Net message from client 7 0.27 1.87
gc cr failure 39 0.00 0.02
cr request retry 39 0.98 38.27
SQL*Net more data to client 12 0.00 0.00
db file scattered read 2446 0.13 132.58
gc cr disk read 5 0.00 0.00
********************************************************************************6) The DBMS_XPLAN.DISPLAY_CURSOR output:
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID b8pfhfxscqn1m, child number 0
SELECT /*+ gather_plan_statistics */ hou.name "OU" ,-- e.g. Seagate Technology USOP1 , mc.descript
oeh.order_number "Order Num", hp.party_name "Bill To Cust Name", hcsu.location "Ship To Cust Num",
Num", ft.nls_territory "Ship To Country", mc.segment7 "designapplication", ccm.formattedcapacity
oel.Subinventory "Subinventory", to_char(oel.actual_shipment_date,'MM/DD/YYYY DY') "Shipment Date",
oe_order_headers_all oeh ,oe_order_lines_all oel ,apps.hz_parties hp ,apps.hz_cust
,apps.hz_cust_acct_sites_all hcas , apps.seaeng_ccfamilymodelinfo ccm ,apps.hz_party_sites hps
,apps.hr_organization_units hou ,apps.mtl_paramete
Plan hash value: 414863479
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | O
| 1 | NESTED LOOPS | | 1 | 1 | 592 |00:02:25.13 | 535K| 57267 | |
| 2 | NESTED LOOPS | | 1 | 1 | 592 |00:02:24.22 | 533K| 57185 |
| 3 | NESTED LOOPS | | 1 | 1 | 592 |00:02:24.15 | 532K| 57183 |
| 4 | NESTED LOOPS | | 1 | 1 | 594 |00:02:24.00 | 531K| 57171 |
| 5 | NESTED LOOPS | | 1 | 1 | 594 |00:02:23.98 | 530K| 57170 |
| 6 | NESTED LOOPS | | 1 | 1 | 594 |00:02:23.49 | 529K| 57129 |
| 7 | NESTED LOOPS | | 1 | 1 | 594 |00:02:23.08 | 528K| 57096 |
| 8 | NESTED LOOPS | | 1 | 1 | 594 |00:02:22.51 | 526K| 57031 | |
| 9 | NESTED LOOPS | | 1 | 1 | 594 |00:02:21.79 | 524K| 56968 | |
| 10 | NESTED LOOPS | | 1 | 1 | 2990 |00:02:09.65 | 515K| 55703 |
| 11 | NESTED LOOPS | | 1 | 1 | 2990 |00:02:09.62 | 515K| 55703 |
| 12 | NESTED LOOPS | | 1 | 1 | 2990 |00:02:08.47 | 509K| 55599 |
|* 13 | HASH JOIN | | 1 | 2 | 3000 |00:02:07.88 | 503K| 55516 | 974K
| 14 | NESTED LOOPS | | 1 | 2 | 3000 |00:01:39.07 | 471K| 23025 |
| 15 | NESTED LOOPS | | 1 | 1 | 1 |00:00:00.01 | 4 | 0 |
| 16 | TABLE ACCESS BY INDEX ROWID| HR_ALL_ORGANIZATION_UNITS_TL | 1 | 1 | 1 |00:00
|* 17 | INDEX UNIQUE SCAN | HR_ALL_ORGANIZATION_UNTS_TL_PK | 1 | 1 | 1 |00:00:00.0
|* 18 | TABLE ACCESS BY INDEX ROWID| HR_ALL_ORGANIZATION_UNITS | 1 | 1 | 1 |00:00:
|* 19 | INDEX UNIQUE SCAN | HR_ORGANIZATION_UNITS_PK | 1 | 1 | 1 |00:00:00.01
|* 20 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_LINES_ALL | 1 | 2 | 3000 |00:01
|* 21 | INDEX RANGE SCAN | OE_ORDER_LINES_N20 | 1 | 47575 | 156K|00:00:01.76 | 420
|* 22 | TABLE ACCESS FULL | MTL_ITEM_CATEGORIES | 1 | 96977 | 263K|00:00:28.49
|* 23 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORIES_B | 3000 | 1 | 2990 |00:00:0
|* 24 | INDEX UNIQUE SCAN | MTL_CATEGORIES_B_U1 | 3000 | 1 | 3000 |00:00:00.21
| 25 | TABLE ACCESS BY INDEX ROWID | SEAENG_CCFAMILYMODELINFO | 2990 | 1 | 2990 |
|* 26 | INDEX UNIQUE SCAN | SEAENG_CCFAMILYMODELINFO_U1 | 2990 | 1 | 2990 |00:00:
|* 27 | INDEX UNIQUE SCAN | MTL_PARAMETERS_U1 | 2990 | 1 | 2990 |00:00:00.02 |
|* 28 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_HEADERS_ALL | 2990 | 1 | 594 |00:00:
|* 29 | INDEX UNIQUE SCAN | OE_ORDER_HEADERS_U1 | 2990 | 1 | 2990 |00:00:04.29 |
| 30 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 594 | 1 | 594 |00:00:
|* 31 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 594 | 1 | 594 |00:00:00.31 |
| 32 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 594 | 1 | 594 |00:00:
|* 33 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 594 | 1 | 594 |00:00:00.23 |
| 34 | TABLE ACCESS BY INDEX ROWID | HZ_PARTY_SITES | 594 | 1 | 594 |00:00:0
|* 35 | INDEX UNIQUE SCAN | HZ_PARTY_SITES_U1 | 594 | 1 | 594 |00:00:00.17 | 601
| 36 | TABLE ACCESS BY INDEX ROWID | HZ_LOCATIONS | 594 | 1 | 594 |00:00:00.4
|* 37 | INDEX UNIQUE SCAN | HZ_LOCATIONS_U1 | 594 | 1 | 594 |00:00:00.17 |
| 38 | TABLE ACCESS BY INDEX ROWID | FND_TERRITORIES | 594 | 1 | 594 |00:00:00
|* 39 | INDEX UNIQUE SCAN | FND_TERRITORIES_U1 | 594 | 1 | 594 |00:00:00.02
|* 40 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS | 594 | 1 | 592 |00:00:0
|* 41 | INDEX UNIQUE SCAN | HZ_CUST_ACCOUNTS_U1 | 594 | 1 | 594 |00:00:00.04 |
|* 42 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U1 | 592 | 1 | 592 |00:00:00.06 |
| 43 | TABLE ACCESS BY INDEX ROWID | HZ_PARTIES | 592 | 1 | 592 |00:00:00.91 |
|* 44 | INDEX UNIQUE SCAN | HZ_PARTIES_U1 | 592 | 1 | 592 |00:00:00.40 | 599
Predicate Information (identified by operation id):
13 - access("OEL"."INVENTORY_ITEM_ID"="MIC"."INVENTORY_ITEM_ID")
17 - access("HAOTL"."ORGANIZATION_ID"=189 AND "HAOTL"."LANGUAGE"=USERENV('LANG'))
filter(DECODE("HR_SECURITY"."VIEW_ALL"(),'Y','TRUE',"HR_SECURITY"."SHOW_RECORD"('HR_ALL_ORGAN
18 - filter("HAO"."BUSINESS_GROUP_ID"=DECODE("HR_GENERAL"."GET_XBG_PROFILE"(),'Y',"HAO"."BUSINESS_
19 - access("HAO"."ORGANIZATION_ID"=189)
20 - filter(("OEL"."FLOW_STATUS_CODE"='CLOSED' AND INTERNAL_FUNCTION("OEL"."ATTRIBUTE1") AND INTER
21 - access("OEL"."SYS_NC00342$">=TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "O
'syyyy-mm-dd hh24:mi:ss'))
22 - filter("MIC"."CATEGORY_SET_ID"=4)
23 - filter(("MC"."DESCRIPTION" IS NOT NULL AND INTERNAL_FUNCTION("MC"."SEGMENT7")))
24 - access("MIC"."CATEGORY_ID"="MC"."CATEGORY_ID")
26 - access("MC"."DESCRIPTION"="CCM"."STMODELNUMBER")
27 - access("OEL"."SHIP_FROM_ORG_ID"="MP"."ORGANIZATION_ID")
28 - filter("OEH"."ORG_ID"=189)
29 - access("OEH"."HEADER_ID"="OEL"."HEADER_ID")
31 - access("OEH"."INVOICE_TO_ORG_ID"="HCSU"."SITE_USE_ID")
33 - access("HCSU"."CUST_ACCT_SITE_ID"="HCAS"."CUST_ACCT_SITE_ID")
35 - access("HCAS"."PARTY_SITE_ID"="HPS"."PARTY_SITE_ID")
37 - access("HPS"."LOCATION_ID"="HL"."LOCATION_ID")
39 - access("HL"."COUNTRY"="FT"."TERRITORY_CODE")
40 - filter(("HCA"."SALES_CHANNEL_CODE"<>'RTL' AND "HCA"."SALES_CHANNEL_CODE"<>'AD-RTL' AND "HCA".
41 - access("HCAS"."CUST_ACCOUNT_ID"="HCA"."CUST_ACCOUNT_ID")
42 - access("FLV"."LOOKUP_TYPE"='SALES_CHANNEL' AND "FLV"."LOOKUP_CODE"="HCA"."SALES_CHANNEL_CODE"
filter(("FLV"."LOOKUP_CODE"<>'RTL' AND "FLV"."LOOKUP_CODE"<>'AD-RTL' AND "FLV"."LOOKUP_CODE"<
44 - access("HCA"."PARTY_ID"="HP"."PARTY_ID")
90 rows selected.
{code} &nbs -
Hello,
database is oracle 10.2.0.4.0
a query is
SELECT * FROM OPTIVA.SFI_AP_BATCH_ING_LTS_SUBLTS_V WHERE Plant = 'GB' and Batch_no = 000361602;
its explain plan is
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Inst |IN-OUT|
| 0 | SELECT STATEMENT | | 1 | 1567 | | 44518 (9)| 00:08:55 | | |
| 1 | NESTED LOOPS | | 1 | 1567 | | 44518 (9)| 00:08:55 | | |
|* 2 | HASH JOIN | | 1 | 1548 | | 44517 (9)| 00:08:55 | | |
| 3 | MERGE JOIN CARTESIAN | | 1 | 1531 | | 44402 (9)| 00:08:53 | | |
|* 4 | HASH JOIN | | 1 | 1488 | | 44179 (9)| 00:08:51 | | |
|* 5 | HASH JOIN | | 1 | 1188 | | 37416 (2)| 00:07:29 | | |
| 6 | REMOTE | | 12000 | 738K| | 1675 (2)| 00:00:21 | OPTIV~ | R->S |
| 7 | MERGE JOIN CARTESIAN | | 2900 | 3186K| | 35740 (2)| 00:07:09 | | |
|* 8 | HASH JOIN | | 1 | 1103 | | 35517 (2)| 00:07:07 | | |
|* 9 | HASH JOIN | | 1 | 627 | | 18611 (2)| 00:03:44 | | |
| 10 | VIEW | SFI_PLM_BATCH_HDR_V | 1 | 140 | | 16906 (2)| 00:03:23 | | |
| 11 | SORT ORDER BY | | 1 | 283 | | 16906 (2)| 00:03:23 | | |
| 12 | SORT UNIQUE | | 1 | 283 | | 16905 (2)| 00:03:23 | | |
|* 13 | HASH JOIN | | 1 | 283 | | 16904 (2)| 00:03:23 | | |
| 14 | MERGE JOIN CARTESIAN | | 38 | 7486 | | 15914 (2)| 00:03:11 | | |
| 15 | REMOTE | GME_BATCH_HEADER | 1 | 162 | | 15531 (2)| 00:03:07 | OPTIV~ | R->S |
| 16 | BUFFER SORT | | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
|* 17 | TABLE ACCESS FULL | FSFORMULA | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
| 18 | REMOTE | FM_FORM_MST | 413K| 33M| | 985 (3)| 00:00:12 | OPTIV~ | R->S |
| 19 | VIEW | SFI_AP_INVENTORY_V_MOD | 1 | 487 | | 1705 (2)| 00:00:21 | | |
| 20 | SORT ORDER BY | | 1 | 411 | | 1705 (2)| 00:00:21 | | |
| 21 | NESTED LOOPS | | 1 | 411 | | 1704 (2)| 00:00:21 | | |
| 22 | NESTED LOOPS OUTER | | 1 | 252 | | 1702 (2)| 00:00:21 | | |
| 23 | NESTED LOOPS | | 1 | 204 | | 1700 (2)| 00:00:21 | | |
| 24 | MERGE JOIN CARTESIAN | | 1 | 152 | | 1695 (2)| 00:00:21 | | |
| 25 | MERGE JOIN CARTESIAN| | 1 | 65 | | 5 (0)| 00:00:01 | | |
| 26 | NESTED LOOPS | | 1 | 57 | | 4 (0)| 00:00:01 | | |
| 27 | REMOTE | ORG_ORGANIZATION_DEFINITIONS | 1 | 22 | | 3 (0)| 00:00:01 | OPTIV~ | R->S |
| 28 | REMOTE | MTL_PARAMETERS | 1 | 35 | | 1 (0)| 00:00:01 | OPTIV~ | R->S |
| 29 | BUFFER SORT | | 1 | 8 | | 4 (0)| 00:00:01 | | |
| 30 | REMOTE | IC_WHSE_MST | 1 | 8 | | 1 (0)| 00:00:01 | OPTIV~ | R->S |
| 31 | BUFFER SORT | | 239 | 20793 | | 1694 (2)| 00:00:21 | | |
| 32 | REMOTE | IC_ITEM_MST | 239 | 20793 | | 1690 (2)| 00:00:21 | OPTIV~ | R->S |
| 33 | REMOTE | IC_LOCT_INV | 1 | 52 | | 5 (0)| 00:00:01 | OPTIV~ | R->S |
| 34 | REMOTE | BULK_ASSAYS | 1 | 48 | | 2 (0)| 00:00:01 | OPTIV~ | R->S |
| 35 | REMOTE | IC_LOTS_MST | 1 | 159 | | 2 (0)| 00:00:01 | OPTIV~ | R->S |
| 36 | VIEW | SFI_PLM_BATCH_HDR_V | 1 | 476 | | 16906 (2)| 00:03:23 | | |
| 37 | SORT ORDER BY | | 1 | 283 | | 16906 (2)| 00:03:23 | | |
| 38 | SORT UNIQUE | | 1 | 283 | | 16905 (2)| 00:03:23 | | |
|* 39 | HASH JOIN | | 1 | 283 | | 16904 (2)| 00:03:23 | | |
| 40 | MERGE JOIN CARTESIAN | | 38 | 7486 | | 15914 (2)| 00:03:11 | | |
| 41 | REMOTE | GME_BATCH_HEADER | 1 | 162 | | 15531 (2)| 00:03:07 | OPTIV~ | R->S |
| 42 | BUFFER SORT | | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
|* 43 | TABLE ACCESS FULL | FSFORMULA | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
| 44 | REMOTE | FM_FORM_MST | 413K| 33M| | 985 (3)| 00:00:12 | OPTIV~ | R->S |
| 45 | BUFFER SORT | | 2900 | 63800 | | 35740 (2)| 00:07:09 | | |
|* 46 | TABLE ACCESS FULL | FSITEM | 2900 | 63800 | | 223 (2)| 00:00:03 | | |
| 47 | VIEW | SFI_AP_FLAT_FORMULA_V | 24429 | 2099K| | 6722 (50)| 00:01:21 | | |
| 48 | SORT GROUP BY | | 24429 | 2457K| 5768K| 6722 (50)| 00:01:21 | | |
|* 49 | HASH JOIN | | 24429 | 2457K| | 6145 (55)| 00:01:14 | | |
|* 50 | TABLE ACCESS FULL | FSFORMULA | 2204 | 154K| | 383 (2)| 00:00:05 | | |
|* 51 | TABLE ACCESS FULL | FSFORMULATECHPARAM | 145K| 4394K| | 5760 (59)| 00:01:10 | | |
| 52 | BUFFER SORT | | 34797 | 1461K| | 44402 (9)| 00:08:53 | | |
|* 53 | TABLE ACCESS FULL | FSITEM | 34797 | 1461K| | 223 (2)| 00:00:03 | | |
|* 54 | TABLE ACCESS FULL | FSFORMULAINGRED | 44332 | 735K| | 114 (4)| 00:00:02 | | |
|* 55 | TABLE ACCESS BY INDEX ROWID | FSFORMULA | 1 | 19 | | 1 (0)| 00:00:01 | | |
|* 56 | INDEX UNIQUE SCAN | FS_FORMULA_PK | 1 | | | 0 (0)| 00:00:01 | | |
it runs about 2 minutes 45 seconds, I use hint (like parallel and DRIVING_SITE), can make it faster as 2 minutes, but can't gain more,
any better idea?
thanks a lot
Edited by: 951932 on Sep 7, 2012 4:12 PM951932 wrote:
its explain plan is
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Inst |IN-OUT|
| 0 | SELECT STATEMENT | | 1 | 1567 | | 44518 (9)| 00:08:55 | | |
| 1 | NESTED LOOPS | | 1 | 1567 | | 44518 (9)| 00:08:55 | | |
|* 2 | HASH JOIN | | 1 | 1548 | | 44517 (9)| 00:08:55 | | |
| 3 | MERGE JOIN CARTESIAN | | 1 | 1531 | | 44402 (9)| 00:08:53 | | |
|* 4 | HASH JOIN | | 1 | 1488 | | 44179 (9)| 00:08:51 | | |
|* 5 | HASH JOIN | | 1 | 1188 | | 37416 (2)| 00:07:29 | | |
| 6 | REMOTE | | 12000 | 738K| | 1675 (2)| 00:00:21 | OPTIV~ | R->S |
| 7 | MERGE JOIN CARTESIAN | | 2900 | 3186K| | 35740 (2)| 00:07:09 | | |
|* 8 | HASH JOIN | | 1 | 1103 | | 35517 (2)| 00:07:07 | | |
|* 9 | HASH JOIN | | 1 | 627 | | 18611 (2)| 00:03:44 | | |
| 10 | VIEW | SFI_PLM_BATCH_HDR_V | 1 | 140 | | 16906 (2)| 00:03:23 | | |
| 11 | SORT ORDER BY | | 1 | 283 | | 16906 (2)| 00:03:23 | | |
| 12 | SORT UNIQUE | | 1 | 283 | | 16905 (2)| 00:03:23 | | |
|* 13 | HASH JOIN | | 1 | 283 | | 16904 (2)| 00:03:23 | | |
| 14 | MERGE JOIN CARTESIAN | | 38 | 7486 | | 15914 (2)| 00:03:11 | | |
| 15 | REMOTE | GME_BATCH_HEADER | 1 | 162 | | 15531 (2)| 00:03:07 | OPTIV~ | R->S |
| 16 | BUFFER SORT | | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
|* 17 | TABLE ACCESS FULL | FSFORMULA | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
| 18 | REMOTE | FM_FORM_MST | 413K| 33M| | 985 (3)| 00:00:12 | OPTIV~ | R->S |
| 19 | VIEW | SFI_AP_INVENTORY_V_MOD | 1 | 487 | | 1705 (2)| 00:00:21 | | |
| 20 | SORT ORDER BY | | 1 | 411 | | 1705 (2)| 00:00:21 | | |
| 21 | NESTED LOOPS | | 1 | 411 | | 1704 (2)| 00:00:21 | | |
| 22 | NESTED LOOPS OUTER | | 1 | 252 | | 1702 (2)| 00:00:21 | | |
| 23 | NESTED LOOPS | | 1 | 204 | | 1700 (2)| 00:00:21 | | |
| 24 | MERGE JOIN CARTESIAN | | 1 | 152 | | 1695 (2)| 00:00:21 | | |
| 25 | MERGE JOIN CARTESIAN| | 1 | 65 | | 5 (0)| 00:00:01 | | |
| 26 | NESTED LOOPS | | 1 | 57 | | 4 (0)| 00:00:01 | | |
| 27 | REMOTE | ORG_ORGANIZATION_DEFINITIONS | 1 | 22 | | 3 (0)| 00:00:01 | OPTIV~ | R->S |
| 28 | REMOTE | MTL_PARAMETERS | 1 | 35 | | 1 (0)| 00:00:01 | OPTIV~ | R->S |
| 29 | BUFFER SORT | | 1 | 8 | | 4 (0)| 00:00:01 | | |
| 30 | REMOTE | IC_WHSE_MST | 1 | 8 | | 1 (0)| 00:00:01 | OPTIV~ | R->S |
| 31 | BUFFER SORT | | 239 | 20793 | | 1694 (2)| 00:00:21 | | |
| 32 | REMOTE | IC_ITEM_MST | 239 | 20793 | | 1690 (2)| 00:00:21 | OPTIV~ | R->S |
| 33 | REMOTE | IC_LOCT_INV | 1 | 52 | | 5 (0)| 00:00:01 | OPTIV~ | R->S |
| 34 | REMOTE | BULK_ASSAYS | 1 | 48 | | 2 (0)| 00:00:01 | OPTIV~ | R->S |
| 35 | REMOTE | IC_LOTS_MST | 1 | 159 | | 2 (0)| 00:00:01 | OPTIV~ | R->S |
| 36 | VIEW | SFI_PLM_BATCH_HDR_V | 1 | 476 | | 16906 (2)| 00:03:23 | | |
| 37 | SORT ORDER BY | | 1 | 283 | | 16906 (2)| 00:03:23 | | |
| 38 | SORT UNIQUE | | 1 | 283 | | 16905 (2)| 00:03:23 | | |
|* 39 | HASH JOIN | | 1 | 283 | | 16904 (2)| 00:03:23 | | |
| 40 | MERGE JOIN CARTESIAN | | 38 | 7486 | | 15914 (2)| 00:03:11 | | |
| 41 | REMOTE | GME_BATCH_HEADER | 1 | 162 | | 15531 (2)| 00:03:07 | OPTIV~ | R->S |
| 42 | BUFFER SORT | | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
|* 43 | TABLE ACCESS FULL | FSFORMULA | 2204 | 77140 | | 383 (2)| 00:00:05 | | |
| 44 | REMOTE | FM_FORM_MST | 413K| 33M| | 985 (3)| 00:00:12 | OPTIV~ | R->S |
| 45 | BUFFER SORT | | 2900 | 63800 | | 35740 (2)| 00:07:09 | | |
|* 46 | TABLE ACCESS FULL | FSITEM | 2900 | 63800 | | 223 (2)| 00:00:03 | | |
| 47 | VIEW | SFI_AP_FLAT_FORMULA_V | 24429 | 2099K| | 6722 (50)| 00:01:21 | | |
| 48 | SORT GROUP BY | | 24429 | 2457K| 5768K| 6722 (50)| 00:01:21 | | |
|* 49 | HASH JOIN | | 24429 | 2457K| | 6145 (55)| 00:01:14 | | |
|* 50 | TABLE ACCESS FULL | FSFORMULA | 2204 | 154K| | 383 (2)| 00:00:05 | | |
|* 51 | TABLE ACCESS FULL | FSFORMULATECHPARAM | 145K| 4394K| | 5760 (59)| 00:01:10 | | |
| 52 | BUFFER SORT | | 34797 | 1461K| | 44402 (9)| 00:08:53 | | |
|* 53 | TABLE ACCESS FULL | FSITEM | 34797 | 1461K| | 223 (2)| 00:00:03 | | |
|* 54 | TABLE ACCESS FULL | FSFORMULAINGRED | 44332 | 735K| | 114 (4)| 00:00:02 | | |
|* 55 | TABLE ACCESS BY INDEX ROWID | FSFORMULA | 1 | 19 | | 1 (0)| 00:00:01 | | |
|* 56 | INDEX UNIQUE SCAN | FS_FORMULA_PK | 1 | | | 0 (0)| 00:00:01 | | |
it runs about 2 minutes 45 seconds, I use hint (like parallel and DRIVING_SITE), can make it faster as 2 minutes, but can't gain more,
This isn't a complete execution plan - you've omitted the predicate section, and you've omitted the "remote SQL" section. However, even with those bits in place you're probably not going to find anyone who can unravel the plan to figure why you have a problem - even if you supply the definitions of all the views involved.
Given the earlier comments about cartesian merge joins, it's possible that the statistics on the remote database (particularly) are sufficiently stale that the optimizer's estimates are completely wrecked - so check stats.
To get a handle on where the time is going, and where you most need to spend your energy, you could run the query with the /*+ gather_plan_statistics */ hint (or set statistics_level=all) and they use dbms_xplan.display_cursor() with the 'allstats last' format option to show us where the work was done.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Author: <b><em>Oracle Core</em></b>
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.) -
Hi,
PLease help me to tune the query
select primary_rep,
rep_ssn,
nvl(product_type_desc, 'UNKNOWN') as productName,
ROUND(sum(contributions)) as contribution,
ROUND(sum(withdrawls)) as withdrawls,
ROUND(sum(netflow)) as netflow
from dev.NETFLOW_VIEW_TSS_P
where bd = 'TSS'
and actvtydate between '01-Jan-2011' and '30-Sep-2011'
and rep_ssn IN (select tax_id from broker_view where broker_id = '600468')
group by primary_rep, rep_ssn, nvl(product_type_desc, 'UNKNOWN');
explain plan details below
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 79 | 158K| | 74348 (1)| 00:14:53 | | |
| 1 | HASH GROUP BY | | 79 | 158K| | 74348 (1)| 00:14:53 | | |
|* 2 | HASH JOIN | | 79 | 158K| | 74347 (1)| 00:14:53 | | |
| 3 | VIEW | VW_NSO_1 | 1 | 6 | | 18 (17)| 00:00:01 | | |
| 4 | HASH UNIQUE | | 1 | 100 | | 18 (17)| 00:00:01 | | |
| 5 | NESTED LOOPS OUTER | | 1 | 100 | | 17 (12)| 00:00:01 | | |
| 6 | MERGE JOIN CARTESIAN | | 1 | 92 | | 17 (12)| 00:00:01 | | |
| 7 | NESTED LOOPS OUTER | | 1 | 71 | | 15 (14)| 00:00:01 | | |
| 8 | NESTED LOOPS OUTER | | 1 | 67 | | 12 (17)| 00:00:01 | | |
|* 9 | HASH JOIN OUTER | | 1 | 63 | | 10 (20)| 00:00:01 | | |
| 10 | NESTED LOOPS OUTER | | 1 | 56 | | 6 (0)| 00:00:01 | | |
| 11 | NESTED LOOPS OUTER | | 1 | 52 | | 4 (0)| 00:00:01 | | |
| 12 | TABLE ACCESS BY INDEX ROWID | AFFILIATE | 1 | 45 | | 2 (0)| 00:00:01 | | |
|* 13 | INDEX UNIQUE SCAN | AFFILIATE_PK | 1 | | | 1 (0)| 00:00:01 | | |
|* 14 | TABLE ACCESS FULL | PORTAL_BROKER | 1 | 7 | | 2 (0)| 00:00:01 | | |
| 15 | VIEW PUSHED PREDICATE | | 1 | 4 | | 2 (0)| 00:00:01 | | |
| 16 | NESTED LOOPS | | 1 | 28 | | 2 (0)| 00:00:01 | | |
| 17 | NESTED LOOPS | | 1 | 21 | | 2 (0)| 00:00:01 | | |
|* 18 | TABLE ACCESS BY INDEX ROWID | LOCATION_GROUP_TYPE_DESC | 1 | 5 | | 1 (0)| 00:00:01 | | |
|* 19 | INDEX UNIQUE SCAN | LOCATION_GROUP_TYPE_DESC_PK | 1 | | | 0 (0)| 00:00:01 | | |
|* 20 | INDEX RANGE SCAN | LOCATION_GROUP_UK | 1 | 16 | | 1 (0)| 00:00:01 | | |
|* 21 | INDEX UNIQUE SCAN | CONTACT_METHOD_PK | 1 | 7 | | 0 (0)| 00:00:01 | | |
| 22 | VIEW | | 1 | 7 | | 3 (34)| 00:00:01 | | |
| 23 | HASH UNIQUE | | 1 | 11 | | 3 (34)| 00:00:01 | | |
|* 24 | INDEX RANGE SCAN | AFFILIATE_TYPE_PK | 1 | 11 | | 2 (0)| 00:00:01 | | |
| 25 | VIEW PUSHED PREDICATE | | 1 | 4 | | 2 (0)| 00:00:01 | | |
| 26 | NESTED LOOPS | | 1 | 28 | | 2 (0)| 00:00:01 | | |
| 27 | NESTED LOOPS | | 1 | 21 | | 2 (0)| 00:00:01 | | |
|* 28 | TABLE ACCESS BY INDEX ROWID | LOCATION_GROUP_TYPE_DESC | 1 | 5 | | 1 (0)| 00:00:01 | | |
|* 29 | INDEX UNIQUE SCAN | LOCATION_GROUP_TYPE_DESC_PK | 1 | | | 0 (0)| 00:00:01 | | |
|* 30 | INDEX RANGE SCAN | LOCATION_GROUP_UK | 1 | 16 | | 1 (0)| 00:00:01 | | |
|* 31 | INDEX UNIQUE SCAN | CONTACT_METHOD_PK | 1 | 7 | | 0 (0)| 00:00:01 | | |
| 32 | VIEW PUSHED PREDICATE | | 1 | 4 | | 3 (0)| 00:00:01 | | |
| 33 | NESTED LOOPS OUTER | | 1 | 35 | | 3 (0)| 00:00:01 | | |
| 34 | NESTED LOOPS | | 1 | 32 | | 3 (0)| 00:00:01 | | |
| 35 | NESTED LOOPS | | 1 | 22 | | 2 (0)| 00:00:01 | | |
|* 36 | TABLE ACCESS BY INDEX ROWID | LOCATION_GROUP_TYPE_DESC | 1 | 5 | | 1 (0)| 00:00:01 | | |
|* 37 | INDEX UNIQUE SCAN | LOCATION_GROUP_TYPE_DESC_PK | 1 | | | 0 (0)| 00:00:01 | | |
|* 38 | INDEX RANGE SCAN | LOCATION_GROUP_UK | 1 | 17 | | 1 (0)| 00:00:01 | | |
| 39 | TABLE ACCESS BY INDEX ROWID | ADDRESS | 1 | 10 | | 1 (0)| 00:00:01 | | |
|* 40 | INDEX UNIQUE SCAN | ADDRESS_PK | 1 | | | 0 (0)| 00:00:01 | | |
|* 41 | INDEX UNIQUE SCAN | PROV_STDSC_PK | 1 | 3 | | 0 (0)| 00:00:01 | | |
| 42 | BUFFER SORT | | 1 | 21 | | 14 (15)| 00:00:01 | | |
|* 43 | INDEX RANGE SCAN | I_BROKER_BKBRCMB | 1 | 21 | | 2 (0)| 00:00:01 | | |
|* 44 | INDEX UNIQUE SCAN | BROKER_BRANCH_PK | 1 | 8 | | 0 (0)| 00:00:01 | | |
| 45 | VIEW | NETFLOW_VIEW_TSS_P | 391K| 766M| | 74325 (1)| 00:14:52 | | |
| 46 | UNION-ALL | | | | | | | | |
|* 47 | HASH JOIN RIGHT OUTER | | 11645 | 1671K| | 49023 (1)| 00:09:49 | | |
| 48 | VIEW | | 1 | 38 | | 13602 (1)| 00:02:44 | | |
|* 49 | FILTER | | | | | | | | |
| 50 | TABLE ACCESS FULL | SALES_REPORT_REP_MAPPING | 9023 | 326K| | 58 (2)| 00:00:01 | | |
|* 51 | FILTER | | | | | | | | |
| 52 | SORT GROUP BY NOSORT | | 1 | 11 | | 3 (0)| 00:00:01 | | |
| 53 | TABLE ACCESS BY INDEX ROWID | SALES_REPORT_REP_MAPPING | 1 | 11 | | 3 (0)| 00:00:01 | | |
|* 54 | INDEX RANGE SCAN | I_SAL_REP_MAP_REPID | 1 | | | 2 (0)| 00:00:01 | | |
| 55 | NESTED LOOPS | | 11645 | 1239K| | 35420 (1)| 00:07:06 | | |
|* 56 | HASH JOIN RIGHT OUTER | | 11645 | 898K| | 12112 (1)| 00:02:26 | | |
| 57 | INDEX FAST FULL SCAN | I_VENDORS_ACCTLOC | 986 | 3944 | | 2 (0)| 00:00:01 | | |
|* 58 | HASH JOIN RIGHT OUTER | | 11645 | 852K| | 12109 (1)| 00:02:26 | | |
|* 59 | MAT_VIEW ACCESS FULL | SECS_DESC | 26777 | 418K| | 3082 (1)| 00:00:37 | | |
|* 60 | FILTER | | | | | | | | |
|* 61 | HASH JOIN RIGHT OUTER | | 11645 | 670K| | 9026 (1)| 00:01:49 | | |
| 62 | MAT_VIEW ACCESS FULL | ENTRYCODES | 1640 | 11480 | | 8 (0)| 00:00:01 | | |
|* 63 | HASH JOIN | | 34936 | 1774K| | 9017 (1)| 00:01:49 | | |
|* 64 | INDEX FULL SCAN | I_CODE | 30 | 420 | | 1 (0)| 00:00:01 | | |
| 65 | PARTITION RANGE ALL | | 342K| 12M| | 9013 (1)| 00:01:49 | 1 | 20 |
| 66 | TABLE ACCESS BY LOCAL INDEX ROWID| BKPG | 342K| 12M| | 9013 (1)| 00:01:49 | 1 | 20 |
|* 67 | INDEX RANGE SCAN | I_BKPG_ACT_REC_IDX | 342K| | | 1412 (1)| 00:00:17 | 1 | 20 |
| 68 | TABLE ACCESS BY INDEX ROWID | ACCT_CUBE | 1 | 30 | | 2 (0)| 00:00:01 | | |
|* 69 | INDEX UNIQUE SCAN | ACCT_CUBE_PK | 1 | | | 1 (0)| 00:00:01 | | |
|* 70 | HASH JOIN RIGHT OUTER | | 379K| 52M| | 25303 (1)| 00:05:04 | | |
| 71 | VIEW | | 1 | 38 | | 13602 (1)| 00:02:44 | | |
|* 72 | FILTER | | | | | | | | |
| 73 | TABLE ACCESS FULL | SALES_REPORT_REP_MAPPING | 9023 | 326K| | 58 (2)| 00:00:01 | | |
|* 74 | FILTER | | | | | | | | |
| 75 | SORT GROUP BY NOSORT | | 1 | 11 | | 3 (0)| 00:00:01 | | |
| 76 | TABLE ACCESS BY INDEX ROWID | SALES_REPORT_REP_MAPPING | 1 | 11 | | 3 (0)| 00:00:01 | | |
|* 77 | INDEX RANGE SCAN | I_SAL_REP_MAP_REPID | 1 | | | 2 (0)| 00:00:01 | | |
|* 78 | HASH JOIN | | 379K| 39M| 33M| 11696 (2)| 00:02:21 | | |
|* 79 | HASH JOIN | | 379K| 28M| | 3210 (2)| 00:00:39 | | |
|* 80 | INDEX FAST FULL SCAN | I_VENDORS_ACCTLOC | 986 | 3944 | | 2 (0)| 00:00:01 | | |
|* 81 | HASH JOIN | | 379K| 27M| 14M| 3204 (2)| 00:00:39 | | |
| 82 | INDEX FAST FULL SCAN | SECS_DESC_PK | 744K| 6545K| | 457 (3)| 00:00:06 | | |
|* 83 | FILTER | | | | | | | | |
|* 84 | HASH JOIN RIGHT OUTER | | 379K| 24M| | 569 (3)| 00:00:07 | | |
| 85 | MAT_VIEW ACCESS FULL | MFENTRYCODES | 6853 | 61677 | | 15 (0)| 00:00:01 | | |
| 86 | PARTITION RANGE ALL | | 1138K| 62M| | 542 (1)| 00:00:07 | 1 | 15 |
|* 87 | TABLE ACCESS BY LOCAL INDEX ROWID | MFBKPG | 1138K| 62M| | 542 (1)| 00:00:07 | 1 | 15 |
|* 88 | INDEX RANGE SCAN | I_MFBKPGP_ACTDT_ACCT_TST | 904 | | | 107 (0)| 00:00:02 | 1 | 15 |
| 89 | INDEX FAST FULL SCAN | I_ACCT_CUBE_REPID_MKT | 1952K| 52M| | 3096 (2)| 00:00:38 | | |
Predicate Information (identified by operation id):
2 - access("REP_SSN"="$nso_col_1")
9 - access("A"."AFFILIATE_ID"="MGR"."AFFILIATE_ID"(+))
13 - access("A"."AFFILIATE_ID"='600468')
14 - filter("PORTAL_BROKER"."BROKER_ID"(+)='600468')
18 - filter("LT"."ADDRESS_CONTACT_IND"='C')
19 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WF')
20 - access("L"."LOCATION_GROUP_TYPE_CODE"='WF' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
21 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
24 - access("AFFILIATE_ID"='600468')
filter("AFFILIATE_TYPE"='BBE' OR "AFFILIATE_TYPE"='BRM' OR "AFFILIATE_TYPE"='ISP')
28 - filter("LT"."ADDRESS_CONTACT_IND"='C')
29 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WT')
30 - access("L"."LOCATION_GROUP_TYPE_CODE"='WT' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
31 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
36 - filter("LT"."ADDRESS_CONTACT_IND"='A')
37 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WM')
38 - access("L"."LOCATION_GROUP_TYPE_CODE"='WM' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
filter("L"."ADDRESS_ID" IS NOT NULL)
40 - access("L"."ADDRESS_ID"="A"."ADDRESS_ID")
41 - access("A"."PROVINCE_STATE_CODE"="S"."PROVINCE_STATE_CODE"(+))
43 - access("B"."BROKER_ID"='600468')
44 - access("B"."BRANCH_ID"="BR"."BRANCH_ID"(+))
47 - access("B"."REPID"="K"."REPID"(+))
49 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
SUM(NVL("PCT",100))=100))
51 - filter(SUM(NVL("PCT",100))=100)
54 - access("REPID"=:B1)
56 - access(NVL("V"."VENDOR_CD"(+),'xxx')=NVL("VENDOR_CD",'yyy'))
58 - access("CUSIP"(+)="A"."CUSIP")
59 - filter("COMM_SECTYPE"(+)='MF')
60 - filter(NVL("Z"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
61 - access("A"."ENTRYCODE"="Z"."ENTRYCODE"(+))
63 - access("CODE_IN"=SUBSTR("A"."ACCT",1,3))
64 - access("CODE_TYPE"='NETFLOW')
filter("CODE_TYPE"='NETFLOW')
67 - access("A"."ACTVTYDATE">=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."ACTVTYDATE"<=TO_DATE(' 2011-09-30
00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
69 - access("B"."ACCOUNTKEY"='11,,,'||"A"."ACCT")
70 - access("A"."REPID"="K"."REPID"(+))
72 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
SUM(NVL("PCT",100))=100))
74 - filter(SUM(NVL("PCT",100))=100)
77 - access("REPID"=:B1)
78 - access("A"."ACCOUNTKEY"='20,'||"B"."VENDOR_CD"||','||"B"."FUNDNO"||','||"B"."ACCT")
79 - access("V"."VENDOR_CD"="B"."VENDOR_CD")
80 - filter("V"."VENDOR_CD"<>'HNR' AND "V"."VENDOR_CD"<>'CNL' AND "V"."VENDOR_CD"<>'IRE' AND "V"."VENDOR_CD"<>'WLR' AND
"V"."VENDOR_CD"<>'WLP' AND "V"."VENDOR_CD"<>'PER' AND "V"."VENDOR_CD"<>'BHV')
81 - access("SD"."CUSIP"="B"."CUSIP")
83 - filter(NVL("E"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
84 - access("B"."ENTRYCODE"="E"."ENTRYCODE"(+))
87 - filter("B"."VENDOR_CD"<>'HNR' AND "B"."VENDOR_CD"<>'CNL' AND "B"."VENDOR_CD"<>'IRE' AND "B"."VENDOR_CD"<>'WLR' AND
"B"."VENDOR_CD"<>'WLP' AND "B"."VENDOR_CD"<>'PER' AND "B"."VENDOR_CD"<>'BHV')
88 - access(SYS_OP_DESCEND("ACTVTYDATE")>=HEXTORAW('8790F6E1FEF8FEFAFF') AND SYS_OP_DESCEND("ACTVTYDATE")<=HEXTORAW('8790FEF8FEF8FEFAFF')
filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))>=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))<=TO_DATE(' 2011-09-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
158 rows selected.ThanksSo this is a VIEW with I think 18 tables (I may have missed one or two), some of which are referenced more than one. Some of these tables have tens of miilions of rows. What exactly are you expecting from us?
I guess this is a data warehouse or BI query. Sometimes such queries just take an age to run and there's nothing which can be done except result caching. Other times the queries can be tuned, but iit requires way more context and domain knowledge than you have provided.
Please start by reading [url https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003]this FAQ. .
Cheers, APC -
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 -
Performance Tunning of Sql query
Hi,
I have table A with size 120 Million and two more tables are of size 2 Million on Table B and less than 1 Million size on table C.
I had created Partition and Parallel degree 4 on the table A. Created table B with Parallel degree 2 and Created table C with NOPARALLEL.
My query is using above tables with joins and inserting into table D using HINT /*+ APPEND NOLOGGING*/
I had executed the explain on the above criteria the cost is showing 20767.
Later created Tables A,B and C with NOPARALLEL. Applied HINT on Table D /*+ APPEND NOLOGGING*/
and als applied HINT /*+ PARALLEL(A, 4) PARALLEL(B C, 2) on select query which uses to insert into Table D.
My question which is best practice on PARALLEL degree creation at table level or query level:
a) Creating table with Paralle (degree 4)
b) Applying HINT /*+ PARALLEL (TABLE A , 4) */ at query level
Regards,
Prakash957901 wrote:
Hi,
I have table A with size 120 Million and two more tables are of size 2 Million on Table B and less than 1 Million size on table C.
I had created Partition and Parallel degree 4 on the table A. Created table B with Parallel degree 2 and Created table C with NOPARALLEL.
My query is using above tables with joins and inserting into table D using HINT /*+ APPEND NOLOGGING*/
I had executed the explain on the above criteria the cost is showing 20767. Cost is meaningless out of context.
Later created Tables A,B and C with NOPARALLEL. Applied HINT on Table D /*+ APPEND NOLOGGING*/
and als applied HINT /*+ PARALLEL(A, 4) PARALLEL(B C, 2) on select query which uses to insert into Table D.
My question which is best practice on PARALLEL degree creation at table level or query level:
a) Creating table with Paralle (degree 4)
b) Applying HINT /*+ PARALLEL (TABLE A , 4) */ at query level Whichever works best for what you're needing to achieve.
Which is another way of saying you haven't provided enough information for anyone here to make any informed decision or suggestion for you.
{message:id=9360002}
For performance issues/tuning requests, read the two threads linked to by this FAQ: {message:id=9360003} -
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 All,
I need to fine tune my select query . I am giving a sample query which is model of my Query .
Sample Tables: Employee, Manager, Department
Select a.employee_name,a.employee_age,decode(a.employee_status,'Y','Promoted','Still in Progress'), NVL(b.employee_details , 0),c.department_name from employee a, manager b , department c where a.employee_id =b.employee_id(+) and a.employee_id = c.employee_id(+) and c.department_status in ('Y',A') order by a.employee_joining_date
This is a sample query. In my query which should be fine tune has lot of decode and nvl functions. This query is passed to oracle as string from Java .It takes 2 seconds but it should be taking only fraction of seconds..
What shall i do?
Shall i create materialise views or a function in oracle with return value as sys_refucursor to Java code. does function based index should be used in where clause only. If so what should i do to minimise decode and nvl functions.Please help me>
Select a.employee_name,a.employee_age,decode(a.employee_status,'Y','Promoted','Still in Progress'),
NVL(b.employee_details , 0),c.department_name from employee a, manager b , department c
where a.employee_id =b.employee_id(+) and a.employee_id = c.employee_id(+) and c.department_status
in ('Y',A') order by a.employee_joining_date I'm wondering why an "employee_details" field is 0 - doesn't make much sense to me.
Also, the (+) syntax is deprecated - use standard ANSI join syntax instead (Mr. Google is your friend).
This is a sample query. In my query which should be fine tune has lot of decode and nvl functions.
This query is passed to oracle as string from Java .It takes 2 seconds but it should be taking only fraction of seconds..Why should it take only a fraction of a second? How do you know this for a fact? TKProf should be
able to tell you what's happening.
What shall i do?
Shall i create materialise views or a function in oracle with return value as sys_refucursor to Java code.
does function based index should be used in where clause only. If so what should i do to minimise
decode and nvl functions.Please help meSounds to me like you're thrashing around desperately in search of a "fancy" solution.
Read some performance books on Oracle - you don't mention your version of Oracle
or your OS, so it's difficult to help with that.
Christopher Lawson's book is an excellent and very readable into to Oracle performance.
Also, Oracle Performance 101 - as well as anything by Tom Kyte. More advanced stuff is
available from Jonathan Lewis and Christian Antognini. Also, take a look at the FAQ for
this group (as recommended by the other poster) and don't forget the docco*
or (short version) RTFM*.
HTH,
Paul... -
Hi , I would like to ask the expert here..how could i fine tune the below query..now it return data within 60 seconds. however my client require the data should return <5 second
SELECT DECODE (CURR.START_DATE, '', PREV.START_DATE, CURR.START_DATE) START_DATE,
DECODE (CURR.START_HOUR, '', PREV.START_HOUR, CURR.START_HOUR) START_HOUR,
DECODE (CURR.IN_PARTNER, '', PREV.IN_PARTNER, CURR.IN_PARTNER) IN_PARTNER,
DECODE (CURR.OUT_PARTNER, '', PREV.OUT_PARTNER, CURR.OUT_PARTNER) OUT_PARTNER,
DECODE (CURR.SUBSCRIBER_TYPE, '', PREV.SUBSCRIBER_TYPE, CURR.SUBSCRIBER_TYPE) SUBSCRIBER_TYPE,
DECODE (CURR.TRAFFIC_TYPE, '', PREV.TRAFFIC_TYPE, CURR.TRAFFIC_TYPE) TRAFFIC_TYPE,
DECODE (CURR.EVENT_TYPE, '', PREV.EVENT_TYPE, CURR.EVENT_TYPE) EVENT_TYPE,
DECODE (CURR.INTERVAL_PERIOD, '', PREV.INTERVAL_PERIOD, CURR.INTERVAL_PERIOD) INTERVAL_PERIOD,
--DECODE (CURR.THRESHOLD, '', PREV.THRESHOLD, CURR.THRESHOLD) THRESHOLD,
DECODE (CURR.CALLED_NO_GRP, '', PREV.CALLED_NO_GRP, CURR.CALLED_NO_GRP) CALLED_NO_GRP,
SUM (DECODE (CURR.EVENT_COUNT, '', 0, CURR.EVENT_COUNT)) EVENT_COUNT,
--SUM (DECODE (CURR.EVENT_DURATION, '', 0, CURR.EVENT_DURATION)) EVENT_DURATION,
--SUM (DECODE (CURR.DATA_VOLUME, '', 0, CURR.DATA_VOLUME)) DATA_VOLUME,
--AVG (DECODE (CURR.AVERAGE_DURATION, '', 0, CURR.AVERAGE_DURATION)) AVERAGE_DURATION,
SUM (DECODE (PREV.EVENT_COUNT_PREV, '', 0, PREV.EVENT_COUNT_PREV)) EVENT_COUNT_PREV,
--SUM ( DECODE (PREV.EVENT_DURATION_PREV, '', 0, PREV.EVENT_DURATION_PREV)) EVENT_DURATION_PREV,
--SUM (DECODE (PREV.DATA_VOLUME_PREV, '', 0, PREV.DATA_VOLUME_PREV)) DATA_VOLUME_PREV,
--AVG ( DECODE (PREV.AVERAGE_DURATION_PREV, '', 0, PREV.AVERAGE_DURATION_PREV)) AVERAGE_DURATION_PREV,
ABS ( SUM (DECODE (CURR.EVENT_COUNT, '', 0, CURR.EVENT_COUNT)) - SUM ( DECODE (PREV.EVENT_COUNT_PREV, '', 0, PREV.EVENT_COUNT_PREV))) EVENT_COUNT_DIFF
FROM ------------------------------- CURR
(SELECT START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
--rd_thr.param_value THRESHOLD,
rd.param_value INTERVAL_PERIOD,
CALLED_NO_GRP,
--SUM (DATA_VOLUME) AS DATA_VOLUME,
--SUM (EVENT_DURATION) AS EVENT_DURATION,
--DECODE ( SUM (NVL (EVENT_COUNT / 1000000, 0)), 0, 0, ROUND ( SUM (EVENT_DURATION / 1000000) / SUM (NVL (EVENT_COUNT / 1000000, 0)), 2)) AS AVERAGE_DURATION,
SUM (EVENT_COUNT) AS EVENT_COUNT
FROM MSC_OUT_AGG,
raid_t_parameters rd,
raid_t_parameters rd_min,
raid_t_parameters rd_max,
raid_t_parameters rd_thr
WHERE TRUNC (SYSDATE - TO_DATE (START_DATE, 'YYYYMMDD')) <= rd_min.param_value
AND rd_min.param_id = 'histMD_IN_MSC'
AND rd_min.param_id2 = 'DASHBOARD_THRESHOLD_MIN'
AND rd.param_id = 'histMD_IN_MSC'
AND rd.param_id2 = 'INTERVAL_PERIOD'
AND rd_max.param_id = 'histMD_IN_MSC'
AND rd_max.param_id2 = 'DASHBOARD_THRESHOLD_MAX'
AND rd_thr.param_id = 'histMD_IN_MSC'
AND rd_thr.param_id2 = 'PER_THRESHOLD_W'
AND TO_DATE (START_DATE, 'YYYYMMDD') < SYSDATE - rd_max.param_value
AND SOURCE = 'MD_IN_MSC_HUA'
GROUP BY START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value,
CALLED_NO_GRP,
rd_thr.param_value
) CURR
FULL OUTER JOIN
---------------------------------- PREV --------------------------
SELECT TO_CHAR ( TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')), 'YYYYMMDD') START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value INTERVAL_PERIOD,
CALLED_NO_GRP,
--rd_thr.param_value THRESHOLD,
SUM (EVENT_COUNT) AS EVENT_COUNT_PREV
--SUM (EVENT_DURATION) AS EVENT_DURATION_PREV,
--DECODE ( SUM (NVL (EVENT_COUNT / 1000000, 0)), 0, 0, ROUND ( SUM (EVENT_DURATION / 1000000) / SUM (NVL (EVENT_COUNT / 1000000, 0)), 2)) AS AVERAGE_DURATION_PREV,
--SUM (DATA_VOLUME) AS DATA_VOLUME_PREV
FROM MSC_OUT_AGG,
raid_t_parameters rd,
raid_t_parameters rd_min,
raid_t_parameters rd_max,
raid_t_parameters rd_thr
WHERE TRUNC ( SYSDATE - TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD'))) <= rd_min.param_value
AND rd.param_id = 'histMD_IN_MSC'
AND rd.param_id2 = 'INTERVAL_PERIOD'
AND rd_min.param_id = 'histMD_IN_MSC'
AND rd_min.param_id2 = 'DASHBOARD_THRESHOLD_MIN'
AND rd_max.param_id = 'histMD_IN_MSC'
AND rd_max.param_id2 = 'DASHBOARD_THRESHOLD_MAX'
AND rd_thr.param_id = 'histMD_IN_MSC'
AND rd_thr.param_id2 = 'PER_THRESHOLD_W'
AND TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')) < SYSDATE - rd_max.param_value
AND SOURCE = 'MD_IN_MSC_HUA'
GROUP BY TO_CHAR ( TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')), 'YYYYMMDD'),
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value,
CALLED_NO_GRP,
rd_thr.param_value
) PREV
-------------------------- join ------------------
ON ( CURR.START_DATE = PREV.START_DATE
AND CURR.START_HOUR = PREV.START_HOUR
AND CURR.IN_PARTNER = PREV.IN_PARTNER
AND CURR.OUT_PARTNER = PREV.OUT_PARTNER
AND CURR.SUBSCRIBER_TYPE = PREV.SUBSCRIBER_TYPE
AND CURR.TRAFFIC_TYPE = PREV.TRAFFIC_TYPE
AND CURR.INTERVAL_PERIOD = PREV.INTERVAL_PERIOD
--AND CURR.THRESHOLD = PREV.THRESHOLD
AND CURR.EVENT_TYPE = PREV.EVENT_TYPE
AND CURR.CALLED_NO_GRP = PREV.CALLED_NO_GRP)
GROUP BY DECODE (CURR.START_DATE, '', PREV.START_DATE, CURR.START_DATE),
DECODE (CURR.START_HOUR, '', PREV.START_HOUR, CURR.START_HOUR),
DECODE (CURR.IN_PARTNER, '', PREV.IN_PARTNER, CURR.IN_PARTNER),
DECODE (CURR.OUT_PARTNER, '', PREV.OUT_PARTNER, CURR.OUT_PARTNER),
DECODE (CURR.SUBSCRIBER_TYPE, '', PREV.SUBSCRIBER_TYPE, CURR.SUBSCRIBER_TYPE),
DECODE (CURR.TRAFFIC_TYPE, '', PREV.TRAFFIC_TYPE, CURR.TRAFFIC_TYPE),
DECODE (CURR.INTERVAL_PERIOD, '', PREV.INTERVAL_PERIOD, CURR.INTERVAL_PERIOD),
--DECODE (CURR.THRESHOLD, '', PREV.THRESHOLD, CURR.THRESHOLD),
DECODE (CURR.EVENT_TYPE, '', PREV.EVENT_TYPE, CURR.EVENT_TYPE),
DECODE (CURR.CALLED_NO_GRP, '', PREV.CALLED_NO_GRP, CURR.CALLED_NO_GRP);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------I changed to query as below, however the performance not much difference compare to original
WITH CURR AS
SELECT /*+ MATERIALIZE */ START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
--rd_thr.param_value THRESHOLD,
rd.param_value INTERVAL_PERIOD,
CALLED_NO_GRP,
--SUM (DATA_VOLUME) AS DATA_VOLUME,
--SUM (EVENT_DURATION) AS EVENT_DURATION,
--DECODE ( SUM (NVL (EVENT_COUNT / 1000000, 0)), 0, 0, ROUND ( SUM (EVENT_DURATION / 1000000) / SUM (NVL (EVENT_COUNT / 1000000, 0)), 2)) AS AVERAGE_DURATION,
SUM (EVENT_COUNT) AS EVENT_COUNT
FROM MSC_OUT_AGG,
raid_t_parameters rd,
raid_t_parameters rd_min,
raid_t_parameters rd_max,
raid_t_parameters rd_thr
WHERE TRUNC (SYSDATE - TO_DATE (START_DATE, 'YYYYMMDD')) <= rd_min.param_value
AND rd_min.param_id = 'histMD_IN_MSC'
AND rd_min.param_id2 = 'DASHBOARD_THRESHOLD_MIN'
AND rd.param_id = 'histMD_IN_MSC'
AND rd.param_id2 = 'INTERVAL_PERIOD'
AND rd_max.param_id = 'histMD_IN_MSC'
AND rd_max.param_id2 = 'DASHBOARD_THRESHOLD_MAX'
AND rd_thr.param_id = 'histMD_IN_MSC'
AND rd_thr.param_id2 = 'PER_THRESHOLD_W'
AND TO_DATE (START_DATE, 'YYYYMMDD') < SYSDATE - rd_max.param_value
AND SOURCE = 'MD_IN_MSC_HUA'
GROUP BY START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value,
CALLED_NO_GRP,
rd_thr.param_value
), PREV AS
SELECT /*+ MATERIALIZE */ TO_CHAR ( TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')), 'YYYYMMDD') START_DATE,
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value INTERVAL_PERIOD,
CALLED_NO_GRP,
--rd_thr.param_value THRESHOLD,
SUM (EVENT_COUNT) AS EVENT_COUNT_PREV
--SUM (EVENT_DURATION) AS EVENT_DURATION_PREV,
--DECODE ( SUM (NVL (EVENT_COUNT / 1000000, 0)), 0, 0, ROUND ( SUM (EVENT_DURATION / 1000000) / SUM (NVL (EVENT_COUNT / 1000000, 0)), 2)) AS AVERAGE_DURATION_PREV,
--SUM (DATA_VOLUME) AS DATA_VOLUME_PREV
FROM MSC_OUT_AGG,
raid_t_parameters rd,
raid_t_parameters rd_min,
raid_t_parameters rd_max,
raid_t_parameters rd_thr
WHERE TRUNC ( SYSDATE - TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD'))) <= rd_min.param_value
AND rd.param_id = 'histMD_IN_MSC'
AND rd.param_id2 = 'INTERVAL_PERIOD'
AND rd_min.param_id = 'histMD_IN_MSC'
AND rd_min.param_id2 = 'DASHBOARD_THRESHOLD_MIN'
AND rd_max.param_id = 'histMD_IN_MSC'
AND rd_max.param_id2 = 'DASHBOARD_THRESHOLD_MAX'
AND rd_thr.param_id = 'histMD_IN_MSC'
AND rd_thr.param_id2 = 'PER_THRESHOLD_W'
AND TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')) < SYSDATE - rd_max.param_value
AND SOURCE = 'MD_IN_MSC_HUA'
GROUP BY TO_CHAR ( TRUNC ( rd.param_value + TO_DATE (START_DATE, 'YYYYMMDD')), 'YYYYMMDD'),
START_HOUR,
IN_PARTNER,
OUT_PARTNER,
SUBSCRIBER_TYPE,
TRAFFIC_TYPE,
EVENT_TYPE,
rd.param_value,
CALLED_NO_GRP,
rd_thr.param_value
SELECT /*+ USE_HASH(T1 T2) */ DECODE (CURR.START_DATE, '', PREV.START_DATE, CURR.START_DATE) START_DATE,
DECODE (CURR.START_HOUR, '', PREV.START_HOUR, CURR.START_HOUR) START_HOUR,
DECODE (CURR.IN_PARTNER, '', PREV.IN_PARTNER, CURR.IN_PARTNER) IN_PARTNER,
DECODE (CURR.OUT_PARTNER, '', PREV.OUT_PARTNER, CURR.OUT_PARTNER) OUT_PARTNER,
DECODE (CURR.SUBSCRIBER_TYPE, '', PREV.SUBSCRIBER_TYPE, CURR.SUBSCRIBER_TYPE) SUBSCRIBER_TYPE,
DECODE (CURR.TRAFFIC_TYPE, '', PREV.TRAFFIC_TYPE, CURR.TRAFFIC_TYPE) TRAFFIC_TYPE,
DECODE (CURR.EVENT_TYPE, '', PREV.EVENT_TYPE, CURR.EVENT_TYPE) EVENT_TYPE,
DECODE (CURR.INTERVAL_PERIOD, '', PREV.INTERVAL_PERIOD, CURR.INTERVAL_PERIOD) INTERVAL_PERIOD,
--DECODE (CURR.THRESHOLD, '', PREV.THRESHOLD, CURR.THRESHOLD) THRESHOLD,
DECODE (CURR.CALLED_NO_GRP, '', PREV.CALLED_NO_GRP, CURR.CALLED_NO_GRP) CALLED_NO_GRP,
SUM (DECODE (CURR.EVENT_COUNT, '', 0, CURR.EVENT_COUNT)) EVENT_COUNT,
--SUM (DECODE (CURR.EVENT_DURATION, '', 0, CURR.EVENT_DURATION)) EVENT_DURATION,
--SUM (DECODE (CURR.DATA_VOLUME, '', 0, CURR.DATA_VOLUME)) DATA_VOLUME,
--AVG (DECODE (CURR.AVERAGE_DURATION, '', 0, CURR.AVERAGE_DURATION)) AVERAGE_DURATION,
SUM (DECODE (PREV.EVENT_COUNT_PREV, '', 0, PREV.EVENT_COUNT_PREV)) EVENT_COUNT_PREV,
--SUM ( DECODE (PREV.EVENT_DURATION_PREV, '', 0, PREV.EVENT_DURATION_PREV)) EVENT_DURATION_PREV,
--SUM (DECODE (PREV.DATA_VOLUME_PREV, '', 0, PREV.DATA_VOLUME_PREV)) DATA_VOLUME_PREV,
--AVG ( DECODE (PREV.AVERAGE_DURATION_PREV, '', 0, PREV.AVERAGE_DURATION_PREV)) AVERAGE_DURATION_PREV,
ABS ( SUM (DECODE (CURR.EVENT_COUNT, '', 0, CURR.EVENT_COUNT)) - SUM ( DECODE (PREV.EVENT_COUNT_PREV, '', 0, PREV.EVENT_COUNT_PREV))) EVENT_COUNT_DIFF
FROM CURR
FULL OUTER JOIN
PREV
ON ( CURR.START_DATE = PREV.START_DATE
AND CURR.START_HOUR = PREV.START_HOUR
AND CURR.IN_PARTNER = PREV.IN_PARTNER
AND CURR.OUT_PARTNER = PREV.OUT_PARTNER
AND CURR.SUBSCRIBER_TYPE = PREV.SUBSCRIBER_TYPE
AND CURR.TRAFFIC_TYPE = PREV.TRAFFIC_TYPE
AND CURR.INTERVAL_PERIOD = PREV.INTERVAL_PERIOD
--AND CURR.THRESHOLD = PREV.THRESHOLD
AND CURR.EVENT_TYPE = PREV.EVENT_TYPE
AND CURR.CALLED_NO_GRP = PREV.CALLED_NO_GRP)
GROUP BY DECODE (CURR.START_DATE, '', PREV.START_DATE, CURR.START_DATE),
DECODE (CURR.START_HOUR, '', PREV.START_HOUR, CURR.START_HOUR),
DECODE (CURR.IN_PARTNER, '', PREV.IN_PARTNER, CURR.IN_PARTNER),
DECODE (CURR.OUT_PARTNER, '', PREV.OUT_PARTNER, CURR.OUT_PARTNER),
DECODE (CURR.SUBSCRIBER_TYPE, '', PREV.SUBSCRIBER_TYPE, CURR.SUBSCRIBER_TYPE),
DECODE (CURR.TRAFFIC_TYPE, '', PREV.TRAFFIC_TYPE, CURR.TRAFFIC_TYPE),
DECODE (CURR.INTERVAL_PERIOD, '', PREV.INTERVAL_PERIOD, CURR.INTERVAL_PERIOD),
--DECODE (CURR.THRESHOLD, '', PREV.THRESHOLD, CURR.THRESHOLD),
DECODE (CURR.EVENT_TYPE, '', PREV.EVENT_TYPE, CURR.EVENT_TYPE),
DECODE (CURR.CALLED_NO_GRP, '', PREV.CALLED_NO_GRP, CURR.CALLED_NO_GRP); -
Hi DBA,
i am new to this field.
i can see from EM some sql are taking 8%- 95% of Db . i get the SQL_ID from the Em how to fine tune this?
also can you please help me out with some standard recommendations to run the DB in best manner.
Thanks in advance.As a generic recommendation for slow sql queries, read the following thread ,
When your query takes too long ...
HTH
Aman.... -
Hi,
I am having below two queries. 2nd query is taking more time & it gives time out error. Can anybody tell how to fine tune below query. Thanks.
1st Query.
SELECT EKETEBELN EKETEBELP EKETETENR EKETEINDT
EKETMENGE EKETWEMNG
INTO TABLE I_EKET
FROM EKET
WHERE EKETMENGE <> EKETWEMNG
AND
EKET~EINDT IN S_EINDT.
DESCRIBE TABLE I_EKET LINES V_ZLINES.
IF V_ZLINES > 0.
2nd Query.
SELECT EKKOEBELN EKKOAEDAT EKKOLIFNR EKPOEBELP EKPO~MATNR
EKPO~WERKS
EKPOLOEKZ EKPOELIKZ EKPOTXZ01 EKPONETPR LFA1~NAME1
INTO TABLE I_PODEL
FROM EKKO
INNER JOIN EKPO ON EKKOEBELN = EKPOEBELN
INNER JOIN LFA1 ON EKKOLIFNR = LFA1LIFNR
FOR ALL ENTRIES IN I_EKET
WHERE EKKO~EBELN = I_EKET-EBELN AND
EKPO~EBELP = I_EKET-EBELP AND
EKPO~MATNR IN S_MATNR AND
EKPO~WERKS IN S_WERKS AND
EKPO~WERKS NE 'W001' AND
EKKO~EKORG = P_EKORG AND
EKKO~LIFNR IN S_LIFNR AND
EKKO~LOEKZ NE 'X' AND
EKPO~LOEKZ NE 'S' AND
EKPO~ELIKZ NE 'X' AND
EKPO~LOEKZ NE 'L' AND
EKKO~AEDAT IN S_AEDAT.
ELSE.
WRITE 'No POs found for the selection criteria!'.
ENDIF.Not the right forum to ask this question.
VJ -
Hi,
How I can tune sql query? what are the steps for tuning.First important step: Infomation gathering. One part can be learning to use the powerful search engine. E.g. search this forum for: "When your query takes too long".
Second step: Information processing. Check the data you found and apply it to your problem
Third step: Testing. Compare the result of the applied change before and after. Was there any performance gain as expected?
Maybe you are looking for
-
How to remove credit card info
i used a isa gift card on my account and now that it ran out itunes wont let me by anything else because it thinks that my bank account is empty please help!!
-
Add a new field in va02,va03 and vf02 & data tran. in these fields VOFM
Hi All, I have a requirement, I need to add a new field in the sales order header part and even a field in the billing document, once I add this field up in both the documents in the header part i need to create a copy routine using the VOFM transact
-
How to sync video in iphone3gs
i am facing problem in synchronizing video in iphone
-
Attach a autocad DWG files to Table in database
Hi How could i attach Auto Cad Drawing files to a Table? Thank you
-
Calculated Account by Entity but exlcude Parents
I have an account in our outline (Calced Income Tax) which uses the following formula: If(@ISMBR("Actual")) "TAX"; Elseif(@ISMBR(@LIST("Budget","Q1RF","Q2RF","Q3RF","Q4RF"))) if(@ISMBR(@RELATIVE("Entity",0))) "Calced Earnings Before Income Tax"*"Corp