Need to tune this oracle query
Hi gurus,
this query is taking 1 min to execute and i have to reduce its execution time...Any suggesstions to improve is appreciated
SELECT SUM(TotalCount) As NoOfRecordsToTranslate
From
SELECT Count(*) as TotalCount
FROM Function_ Fn
INNER JOIN Function_Translation Ft
ON Ft.Functionid = Fn.Id
AND Ft.Active =1
AND Fn.Active =1
INNER JOIN Text_Translation TT
ON TT.Textid = Ft.Textid
AND TT.Active =1
AND (TT.Short <> 'Null'
OR TT.Medium <> 'Null'
OR TT.Extended <> 'Null')
INNER JOIN Function_Type Fnty
ON Fn.Functiontype=Fnty.Functiontype
AND Fnty.Active =1
INNER JOIN Operation_Step_Function Osf
ON (Osf.Functionid=Fn.Id)
AND Osf.Active =1
INNER JOIN Operation_Step Os
ON Os.Id =Osf.Operationstepid
AND Os.Active=1
INNER JOIN Operation Op
ON Op.Id = Os.Operationid
AND op.defaultoperationrevision = 1
AND Op.Active =1
And Op.Revisionstatusid Not In (2) -- 2 means Operation Staus =Cancelled
WHERE TT.Languageid =:Langid-- {IMES_ENV} {SQL} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
FROM Function_Output Fo
INNER JOIN Function_Output_Routing Forout
ON Forout.Functionoutputid = Fo.Id
INNER JOIN Text_Translation TT
ON TT.Textid = Forout.PromptTextid
AND (TT.Short <> 'Null'
OR TT.Medium <> 'Null'
OR TT.Extended <> 'Null')
INNER JOIN Function_Output_Routing_Type Fort
ON Fort.Id=Forout.Outputroutingtypeid
INNER JOIN Text_Translation Ttdt
ON Ttdt.Textid = Fort.Textid
AND Ttdt.Languageid =:Langid
AND Upper(Ttdt.Extended) = Upper('User')
INNER JOIN Function_ Fn
ON Fn.Id = Fo.Functionid
INNER JOIN Function_Type Fnty
ON Fn.Functiontype=Fnty.Functiontype
INNER JOIN Operation_Step_Function Osf
ON (Osf.Functionid=Fn.Id)
INNER JOIN Operation_Step Os
ON Os.Id=Osf.Operationstepid
INNER JOIN Operation Op
ON Op.Id = Os.Operationid
AND op.defaultoperationrevision = 1
And Op.Revisionstatusid Not In (2) -- 2 means Operation Staus =Cancelled
WHERE TT.Languageid =:Langid --{IMES_ENV} {SQL} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
FROM Function_Input Fi
INNER JOIN Text_Translation TT
ON ( TT.Textid = Fi.Prompttextid
AND TT.Active =1)
AND (TT.Short <> 'Null'
OR TT.Medium <> 'Null'
OR TT.Extended <> 'Null')
INNER JOIN Function_Input_Source_Type Fist
ON Fist.Id = Fi.Inputsourcetypeid
AND Fist.Active=1
INNER JOIN Text_Translation Ttdt
ON Ttdt.Textid = Fist.Textid
AND Ttdt.Active =1
AND Ttdt.Languageid = :Langid
AND Upper(Ttdt.Extended) = Upper('User')
INNER JOIN Function_ Fn
ON Fn.Id = Fi.Functionid
AND Fn.Active=1
INNER JOIN Function_Type Fnty
ON Fn.Functiontype=Fnty.Functiontype
AND Fnty.Active =1
INNER JOIN Operation_Step_Function Osf
ON Osf.Functionid=Fn.Id
AND Osf.Active =1
INNER JOIN Operation_Step Os
ON Os.Id =Osf.Operationstepid
AND Os.Active=1
INNER JOIN Operation Op
ON Op.Id = Os.Operationid
AND op.defaultoperationrevision = 1
AND Op.Active =1
And Op.Revisionstatusid Not In (2) -- 2 means Operation Staus =Cancelled
WHERE TT.Languageid = :Langid --{IMES_ENV} {SQL} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
FROM Function_Input_value Fiv
INNER JOIN function_input fi
ON fi.id=fiv.functioninputid
INNER JOIN Text_Translation TT
ON ( TT.Textid = Fiv.textid
AND TT.Active =1)
AND (TT.Short <> 'Null'
OR TT.Medium <> 'Null'
OR TT.Extended <> 'Null')
INNER JOIN Function_Input_Source_Type Fist
ON Fist.Id = Fi.Inputsourcetypeid
AND Fist.Active=1
INNER JOIN Text_Translation Ttdt
ON Ttdt.Textid = Fist.Textid
AND Ttdt.Active =1
AND Ttdt.Languageid = :Langid
AND Upper(Ttdt.Extended) = Upper('User')
INNER JOIN Function_ Fn
ON Fn.Id = Fi.Functionid
AND Fn.Active=1
INNER JOIN Function_Type Fnty
ON Fn.Functiontype=Fnty.Functiontype
AND Fnty.Active =1
INNER JOIN Operation_Step_Function Osf
ON Osf.Functionid=Fn.Id
AND Osf.Active =1
INNER JOIN Operation_Step Os
ON Os.Id =Osf.Operationstepid
AND Os.Active=1
INNER JOIN Operation Op
ON Op.Id = Os.Operationid
AND op.defaultoperationrevision = 1
AND Op.Active =1
And Op.Revisionstatusid Not In (2) -- 2 means Operation Staus =Cancelled
WHERE TT.Languageid = :Langid --{IMES_ENV} {SQL} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
from cob_t_ngmes_master_data ctnmt
inner join text_translation tt
on tt.textid = ctnmt.textid
where
tt.languageid =:Langid-- {SQL} {IMES_ENV_1} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
FROM Reason_Code RC
INNER JOIN Reason_Type RT
on RT.ReasonType = RC.ReasonType
INNER JOIN text_translation TT1 ON TT1.textid= RT.textid AND RT.ACTIVE =1 AND TT1.ACTIVE=1
AND (TT1.Short <> 'Null'
OR TT1.Medium <> 'Null'
OR TT1.Extended <> 'Null')
INNER JOIN text_translation TT ON TT.textid= RC.textid AND RC.ACTIVE =1 AND TT.ACTIVE=1
AND (TT.Short <> 'Null'
OR TT.Medium <> 'Null'
OR TT.Extended <> 'Null')
WHERE TT1.Languageid = :Langid
AND TT.Languageid = :Langid
-- {SQL} {IMES_ENV_2} {FilterSQL}
UNION
SELECT Count(*) as TotalCount
FROM NSPT_T_Event_Type ET
INNER JOIN text_translation TT1
ON TT1.TextID = ET.TextID
INNER JOIN Text_Translation TT
ON TT.TextID = TT1.TextID
WHERE TT1.ACTIVE=1
AND (TT1.Short <> 'Null'
OR TT1.Medium <> 'Null'
OR TT1.Extended <> 'Null')
AND TT1.Languageid = :Langid --{SQL} {IMES_ENV_2} {FilterSQL}
)Edited by: 964145 on Oct 16, 2012 6:50 AM
Please read the forum FAQ
{thread:id=2174552}
{message:id=9360002}
{message:id=9360003}
Similar Messages
-
Please help me what other way i can tune this select query..
Hello Guru,
I have a select query which retrieve data from 10 tables and around 4 tables having 2-4 Lac record and rest are having 80,000 - 1 Lac record.
It is taking around 7-8 seconds to fetch 55000 record.
I was strictly told by the client that i should not use HINTS in my query. My query is below. Please help me what other way i can tune this select query..
select
CT.CUST_ID
,CT.ROMANISED_SURNAME
,CT.SURNAME
,CT.ROMANISED_GIVEN_NAME
,CT.GIVEN_NAME
,CT.ROMANISED_MIDDLE_NAME
,CT.MIDDLE_NAME
,CT.ROMANISED_NAME_SUFFIX
,CT.NAME_SUFFIX
,CT.ROMANISED_TITLE
,CT.TITLE
,CT.ROMANISED_NAME_INITIALS
,CT.NAME_INITIALS
,CT.NAME_TEXT
,CT.CUST_JRNY_ID
,RK.REMARK_TYPE
,RK.REMARK_ID+CT.CUST_ID as REMARK_ID
,RK.REMARK_STATUS
,RK.REMARK_TEXT
,RK.HOST_ONLY_IND
,RK.SUPERVISORY_IND
,RK.CUST_COMM_IND
,RK.REMARK_SEQ
,RK.REMARK_CODE
,RK.DEFAULT_CUST_REL_IND
,RK.DEFAULT_FLIGHT_SEG_REL_IND
,RK.IATA_CODE
,RK.ICAO_CODE
,CJ.RECORD_LOCATOR "SITA_RECORD_LOCATOR"
,Cjv.Record_Locator "ORIGINATOR_RECORD_LOCATOR"
,FS.TRAVELLING_GROUP_CODE
,CG.GROUP_NAME
FROM FLIGHT_LEG FL
,CUST_FLIGHT_LEG CFL
,CUST CT
,CUST_REMARK CTR
,REMARK RK
,FLIGHT_SEG_FLIGHT_LEG FSFL
,FLIGHT_SEG FS
,CUST_JRNY CJ
,CUST_JRNY_VERSION CJV
,CUST_GROUP CG
WHERE FL.OPR_FLIGHT_NUMBER = 1--I_OPR_FLIGHT_NUMBER
and FL.HISTORY_VERSION_NUMBER = 0
and FL.DEPARTURE_STATION_CODE = 'DEL'--I_DEPARTURE_STATION_CODE
and FL.DEPARTURE_DATETIME = TO_DATE('10-DEC-2012 18.45.00', 'DD-MON-YYYY HH24.MI.SS')
and FL.OPR_SERVICE_PROVIDER_CODE= 'AI'--i_opr_service_provider_code
and FL.OPR_FLIGHT_SUFFIX = 'A'--NVL(I_OPR_FLIGHT_SUFFIX, FL.OPR_FLIGHT_SUFFIX)
AND FL.FLIGHT_LEG_ID = CFL.FLIGHT_LEG_ID
AND CFL.CUST_ID = CT.CUST_ID
AND FL.FLIGHT_LEG_ID=FSFL.FLIGHT_LEG_ID
AND FSFL.FLIGHT_SEG_ID=FS.FLIGHT_SEG_ID
AND CT.CUST_ID = CTR.CUST_ID(+)
AND CTR.REMARK_ID = RK.REMARK_ID(+)
AND FL.CUST_JRNY_ID = CJ.CUST_JRNY_ID
and CJ.CUST_JRNY_ID = CJV.CUST_JRNY_ID
AND CG.CUST_JRNY_ID(+) = CT.CUST_JRNY_ID
AND CFL.HISTORY_VERSION_NUMBER = 0
AND CT.HISTORY_VERSION_NUMBER = 0
AND NVL(CTR.HISTORY_VERSION_NUMBER,0) = 0
AND NVL(RK.HISTORY_VERSION_NUMBER,0) = 0
AND FS.HISTORY_VERSION_NUMBER = 0
AND FSFL.HISTORY_VERSION_NUMBER = 0
-- AND CJ.HISTORY_VERSION_NUMBER = 0
and CJV.VERSION_NUMBER = 0 --- Need to check
AND NVL(CG.HISTORY_VERSION_NUMBER,0) = 0
order by CT.CUST_JRNY_ID,CT.CUST_ID;
The Tables having record:
select COUNT(*) from FLIGHT_LEG -----241756
select COUNT(*) from CUST_FLIGHT_LEG---632585
select COUNT(*) from CUST---240015
select COUNT(*) from CUST_REMARK---73724
select COUNT(*) from REMARK---73654
select COUNT(*) from FLIGHT_SEG_FLIGHT_LEG---241789
select COUNT(*) from FLIGHT_SEG----260004
select COUNT(*) from CUST_JRNY----74288
select COUNT(*) from CUST_JRNY_VERSION----74477
select COUNT(*) from CUST_GROUP----55819
Thanks,
HP..Plan hash value: 3771714931
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 10239 | 2949K| | 7515 (1)| 00:01:31 | | |
| 1 | SORT ORDER BY | | 10239 | 2949K| 3160K| 7515 (1)| 00:01:31 | | |
|* 2 | HASH JOIN | | 10239 | 2949K| | 6864 (1)| 00:01:23 | | |
| 3 | PARTITION HASH ALL | | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
|* 4 | TABLE ACCESS FULL | CUST_JRNY_VERSION | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
|* 5 | HASH JOIN | | 10239 | 2799K| | 6445 (1)| 00:01:18 | | |
| 6 | PARTITION HASH ALL | | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
| 7 | TABLE ACCESS FULL | CUST_JRNY | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
|* 8 | FILTER | | | | | | | | |
|* 9 | HASH JOIN RIGHT OUTER | | 10239 | 2679K| | 6267 (1)| 00:01:16 | | |
| 10 | PARTITION HASH ALL | | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
| 11 | TABLE ACCESS FULL | CUST_GROUP | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
|* 12 | FILTER | | | | | | | | |
|* 13 | HASH JOIN OUTER | | 10240 | 2540K| 2056K| 6129 (1)| 00:01:14 | | |
|* 14 | FILTER | | | | | | | | |
|* 15 | HASH JOIN RIGHT OUTER | | 10242 | 1930K| | 5531 (1)| 00:01:07 | | |
| 16 | INDEX FAST FULL SCAN | CUST_REMARK_PK | 73677 | 935K| | 190 (0)| 00:00:03 | | |
|* 17 | HASH JOIN | | 10257 | 1802K| | 5339 (1)| 00:01:05 | | |
|* 18 | HASH JOIN | | 10257 | 701K| | 3516 (1)| 00:00:43 | | |
|* 19 | HASH JOIN | | 3963 | 220K| | 2476 (1)| 00:00:30 | | |
|* 20 | HASH JOIN | | 3963 | 181K| | 1300 (1)| 00:00:16 | | |
| 21 | PARTITION HASH ALL | | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
|* 22 | TABLE ACCESS FULL | FLIGHT_LEG | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
|* 23 | INDEX FAST FULL SCAN| FLIGHT_SEG_FLIGHT_LEG_PK | 240K| 3059K| | 571 (1)| 00:00:07 | | |
| 24 | PARTITION HASH ALL | | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
|* 25 | TABLE ACCESS FULL | FLIGHT_SEG | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
| 26 | PARTITION HASH ALL | | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
|* 27 | TABLE ACCESS FULL | CUST_FLIGHT_LEG | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
| 28 | PARTITION HASH ALL | | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
|* 29 | TABLE ACCESS FULL | CUST | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
| 30 | PARTITION HASH ALL | | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
| 31 | TABLE ACCESS FULL | REMARK | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
Predicate Information (identified by operation id):
2 - access("CJ"."CUST_JRNY_ID"="CJV"."CUST_JRNY_ID")
4 - filter("CJV"."VERSION_NUMBER"=0)
5 - access("FL"."CUST_JRNY_ID"="CJ"."CUST_JRNY_ID")
8 - filter(NVL("CG"."HISTORY_VERSION_NUMBER",0)=0)
9 - access("CG"."CUST_JRNY_ID"(+)="CT"."CUST_JRNY_ID")
12 - filter(NVL("RK"."HISTORY_VERSION_NUMBER",0)=0)
13 - access("CTR"."REMARK_ID"="RK"."REMARK_ID"(+))
14 - filter(NVL("CTR"."HISTORY_VERSION_NUMBER",0)=0)
15 - access("CT"."CUST_ID"="CTR"."CUST_ID"(+))
17 - access("CFL"."CUST_ID"="CT"."CUST_ID")
18 - access("FL"."FLIGHT_LEG_ID"="CFL"."FLIGHT_LEG_ID")
19 - access("FSFL"."FLIGHT_SEG_ID"="FS"."FLIGHT_SEG_ID")
20 - access("FL"."FLIGHT_LEG_ID"="FSFL"."FLIGHT_LEG_ID")
22 - filter("FL"."DEPARTURE_STATION_CODE"='DEL' AND "FL"."DEPARTURE_DATETIME"=TO_DATE(' 2012-12-10 18:45:00', 'syyyy-mm-dd
hh24:mi:ss') AND "FL"."OPR_SERVICE_PROVIDER_CODE"='AI' AND "FL"."OPR_FLIGHT_NUMBER"=1 AND "FL"."OPR_FLIGHT_SUFFIX"='A' AND
"FL"."HISTORY_VERSION_NUMBER"=0)
23 - filter("FSFL"."HISTORY_VERSION_NUMBER"=0)
25 - filter("FS"."HISTORY_VERSION_NUMBER"=0)
27 - filter("CFL"."HISTORY_VERSION_NUMBER"=0)
29 - filter("CT"."HISTORY_VERSION_NUMBER"=0) -
Tune this "contains" query in Oracle 11g EE 11.2.0.3.0
I have a query like below. It runs for ever. The size of this table is not very big, it has around 30 millions rows. The owner column is very selective, and I've added "owner' column in the "filter by" clause of the domain index against description. Do you have any recommendation how I can tune this query? Any help would be greatly appreciated.
select count(*) from items s where contains(s.description, '%111%' ) > 0 and s.owner = 1234;
Thanks.You need to use SDATA to access the owner column through the index. You may also get better performance on your wildcard searches by using a wordlist with attributes as shown below. Please see the demonstration below.
SCOTT@orcl_11gR2> create table items as
2 select object_id as owner, object_name as description
3 from all_objects
4 /
Table created.
SCOTT@orcl_11gR2> insert into items values (1234, 'A111B')
2 /
1 row created.
SCOTT@orcl_11gR2> select count(*) from items
2 /
COUNT(*)
75048
1 row selected.
SCOTT@orcl_11gR2> begin
2 ctx_ddl.create_preference('mywordlist', 'BASIC_WORDLIST');
3 ctx_ddl.set_attribute('mywordlist','PREFIX_INDEX','TRUE');
4 ctx_ddl.set_attribute('mywordlist','PREFIX_MIN_LENGTH', 1);
5 ctx_ddl.set_attribute('mywordlist','SUBSTRING_INDEX', 'YES');
6 ctx_ddl.set_attribute('mywordlist', 'wildcard_maxterms', 50000) ;
7 end;
8 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> create index items_idx
2 on items (description)
3 indextype is ctxsys.context
4 filter by owner
5 parameters ('wordlist mywordlist')
6 /
Index created.
SCOTT@orcl_11gR2> set autotrace on explain
SCOTT@orcl_11gR2> select count(*) from items
2 where contains (description, '%111% and (sdata (owner = 1234))') > 0
3 /
COUNT(*)
1
1 row selected.
Execution Plan
Plan hash value: 1238254566
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 29 | 12 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 29 | | |
|* 2 | DOMAIN INDEX | ITEMS_IDX | 39 | 1131 | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("CTXSYS"."CONTAINS"("DESCRIPTION",'%111% and (sdata
(owner = 1234))')>0)
Note
- dynamic sampling used for this statement (level=2)
SCOTT@orcl_11gR2> -
Hi
I dont know anything about tuning
can anybody help to tune this query
SQL> set autotrace traceonly explain
SQL> select count(*) from ibs_x_t_receipts c
2 where exists
3 (Select 1 from ibs_s_i_doc_receipt a,ibs_x_t_bill b
4 where A.app_fr_doc_no = c.receipt_no
5 and a.app_to_doc_no = b.doc_no
6 and a.app_to_tr_type = 'TRN001'
7 and A.app_fr_tr_type = 'TRN002'
8 and b.bill_month <= '31-dec-2008'
9 and b.balance_ser_amt = 0
10 and b.balance_tax_amt = 0)
11 /
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=212880 Card=1 Byte
s=21)
1 0 SORT (AGGREGATE)
2 1 NESTED LOOPS (Cost=212880 Card=1 Bytes=21)
3 2 VIEW OF 'VW_SQ_1' (VIEW) (Cost=212878 Card=1 Bytes=14)
4 3 HASH (UNIQUE)
5 4 NESTED LOOPS
6 5 NESTED LOOPS (Cost=212878 Card=1 Bytes=66)
7 6 VIEW OF 'index$_join$_002' (VIEW) (Cost=30021
Card=91387 Bytes=3564093)
8 7 HASH JOIN
9 8 INDEX (RANGE SCAN) OF 'SIDOC_INDX1' (INDEX
) (Cost=171215 Card=91387 Bytes=3564093)
10 8 INDEX (RANGE SCAN) OF 'SIDOC_INDX2' (INDEX
) (Cost=366130 Card=91387 Bytes=3564093)
11 6 INDEX (UNIQUE SCAN) OF 'ITL_PK2' (INDEX (UNIQU
E)) (Cost=1 Card=1)
12 5 TABLE ACCESS (BY INDEX ROWID) OF 'IBS_X_T_BILL'
(TABLE) (Cost=2 Card=1 Bytes=27)
13 2 INDEX (UNIQUE SCAN) OF 'RECEIPTS_PK2' (INDEX (UNIQUE))
(Cost=1 Card=1 Bytes=7)it is running like anything, i didn't get the result.
Please help me
kanish--untested
SELECT COUNT (*)
FROM ibs_x_t_receipts c
WHERE EXISTS (
SELECT 1
FROM ibs_s_i_doc_receipt a
WHERE a.app_fr_doc_no = c.receipt_no
AND a.app_to_tr_type = 'TRN001'
AND a.app_fr_tr_type = 'TRN002'
AND EXISTS (
SELECT 1
FROM ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= '31-dec-2008'
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0))regards,
friend
Edited by: most wanted!!!! on Apr 17, 2012 3:51 AM -
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;
/ -
Help tune this monster query please
Hi, I have a query that runs for a long time. Its a system generated query but I need to improve its performance. I have enough indexes on the tables. Here is the query, its explain plan and the tkprof:
The QUERY
SELECT FD.FORM_ID, FD.FIELD_NAME, FD.FIELD_TEXT, FD.OPTION_TEXT, FD.OPTION_TYPE, FD.FIELD_ORDER, FD.LIST_ORDER,
FD.MULTIPLE_ANSWER, FD.FIELD_INSTANCE, NVL(AD.APPS,0) APPS
FROM (
SELECT FIELD_NAME, FIELD_VALUE, INSTANCE, COUNT(0) APPS
FROM APPLICATION_DATA AD
WHERE APPLICATION_ID IN (
SELECT A.APPLICATION_ID
FROM APPLICATIONS A
WHERE A.DELETED = 0 AND DECODE(A.TRAY,'Incomplete','Incomplete','Complete') = 'Complete' AND A.JOB_ID IN (
SELECT JOB_ID
FROM JOBS J
WHERE J.ACCOUNT_ID IN (
SELECT ACCOUNT_ID
FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = J.ACCOUNT_ID ) ) AND A.ACCOUNT_ID IN (
SELECT ACCOUNT_ID
FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = 113346 ) AND FIELD_NAME IN (
SELECT FIELD_NAME FROM APPLICATION_FIELDS
WHERE FIELD_TYPE IN ('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara') ) )
GROUP BY FIELD_NAME, FIELD_VALUE, INSTANCE ) AD, (
SELECT AF.FORM_ID, AF.FIELD_NAME, AF.FIELD_TEXT, AFO.OPTION_TEXT, AFO.OPTION_TYPE, AF.FIELD_ORDER, AFO.LIST_ORDER,
DECODE(AF.FIELD_TYPE,'Checkbox',1,'SelectM',1,0) MULTIPLE_ANSWER, AF.FIELD_INSTANCE
FROM APPLICATION_FIELDS AF, APPLICATION_FIELD_OPTIONS AFO, JOB_FORMS JF
WHERE AFO.FIELD_NAME = AF.FIELD_NAME AND AFO.FORM_ID = AF.FORM_ID AND JF.FORM_ID = AF.FORM_ID AND AF.FIELD_TYPE IN
('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara') AND JF.JOB_ID IN (
SELECT JOB_ID
FROM JOBS J
WHERE J.ACCOUNT_ID IN (
SELECT ACCOUNT_ID
FROM AGENCY_ACCOUNTS CONNECT BY ACCOUNT_ID = PRIOR AGENCY_ID START WITH ACCOUNT_ID = 113346 ) ) ) FD
WHERE AD.FIELD_NAME = FD.FIELD_NAME AND AD.FIELD_VALUE = FD.OPTION_TEXT AND AD.INSTANCE = FD.FIELD_INSTANCE
GROUP BY FD.FORM_ID, FD.FIELD_NAME, FD.FIELD_TEXT, FD.OPTION_TEXT, FD.OPTION_TYPE, FD.FIELD_ORDER, FD.LIST_ORDER,
FD.MULTIPLE_ANSWER, FD.FIELD_INSTANCE, NVL(AD.APPS,0)
ORDER BY FD.FORM_ID ASC, FD.FIELD_ORDER ASCEXPLAIN PLAN OUTPUT
PLAN_TABLE_OUTPUT
Plan hash value: 3519364953
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 120 | 763 (2)| 00:00:10 |
| 1 | SORT GROUP BY | | 1 | 120 | 763 (2)| 00:00:10 |
| 2 | VIEW | | 1 | 120 | 762 (1)| 00:00:10 |
| 3 | HASH GROUP BY | | 1 | 220 | 762 (1)| 00:00:10 |
|* 4 | FILTER | | | | | |
|* 5 | TABLE ACCESS BY INDEX ROWID | APPLICATION_DATA | 1 | 45 | 6 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
| 6 | NESTED LOOPS | | 40 | 8800 | 486 (2)| 00:00:06 |
|* 7 | HASH JOIN | | 60 | 10500 | 125 (4)| 00:00:02 |
|* 8 | HASH JOIN | | 60 | 7320 | 53 (6)| 00:00:01 |
| 9 | NESTED LOOPS | | 11 | 297 | 9 (12)| 00:00:01 |
| 10 | VIEW | VW_NSO_3 | 3 | 15 | 5 (0)| 00:00:01 |
| 11 | HASH UNIQUE | | 3 | 69 | | |
| 12 | TABLE ACCESS BY INDEX ROWID | JOBS | 3 | 30 | 3 (0)| 00:00:01 |
| 13 | NESTED LOOPS | | 3 | 69 | 5 (0)| 00:00:01 |
| 14 | VIEW | VW_NSO_1 | 1 | 13 | 2 (0)| 00:00:01 |
|* 15 | CONNECT BY WITH FILTERING | | | | | |
| 16 | TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS | | | | |
PLAN_TABLE_OUTPUT
|* 17 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | 5 | 1 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | | | | |
| 19 | BUFFER SORT | | | | | |
| 20 | CONNECT BY PUMP | | | | | |
| 21 | TABLE ACCESS BY INDEX ROWID| AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
|* 22 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | | 1 (0)| 00:00:01 |
|* 23 | TABLE ACCESS FULL | AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
|* 24 | INDEX RANGE SCAN | JOBS_ACCOUNT_ID | 3 | | 1 (0)| 00:00:01 |
|* 25 | INDEX RANGE SCAN | JOBS_FORMS_JID_FID | 4 | 88 | 1 (0)| 00:00:01 |
|* 26 | TABLE ACCESS FULL | APPLICATION_FIELDS | 3579 | 332K| 43 (3)| 00:00:01 |
| 27 | TABLE ACCESS FULL | APPLICATION_FIELD_OPTIONS | 32897 | 1702K| 72 (3)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 28 | INDEX RANGE SCAN | IDX$$_B8D40001 | 4 | | 3 (0)| 00:00:01 |
|* 29 | FILTER | | | | | |
| 30 | MERGE JOIN CARTESIAN | | 3 | 225 | 11 (0)| 00:00:01 |
| 31 | NESTED LOOPS | | 1 | 53 | 6 (0)| 00:00:01 |
| 32 | NESTED LOOPS | | 1 | 40 | 4 (0)| 00:00:01 |
|* 33 | TABLE ACCESS BY INDEX ROWID | APPLICATIONS | 1 | 30 | 3 (0)| 00:00:01 |
|* 34 | INDEX UNIQUE SCAN | APPS_APP_ID | 1 | | 2 (0)| 00:00:01 |
| 35 | TABLE ACCESS BY INDEX ROWID | JOBS | 18780 | 183K| 1 (0)| 00:00:01 |
|* 36 | INDEX UNIQUE SCAN | JOBS_JOB_ID | 1 | | 0 (0)| 00:00:01 |
|* 37 | VIEW | VW_NSO_2 | 1 | 13 | 2 (0)| 00:00:01 |
|* 38 | CONNECT BY WITH FILTERING | | | | | |
PLAN_TABLE_OUTPUT
| 39 | TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS | | | | |
|* 40 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | 5 | 1 (0)| 00:00:01 |
| 41 | NESTED LOOPS | | | | | |
| 42 | BUFFER SORT | | | | | |
| 43 | CONNECT BY PUMP | | | | | |
| 44 | TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
|* 45 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | | 1 (0)| 00:00:01 |
|* 46 | TABLE ACCESS FULL | AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
| 47 | BUFFER SORT | | 3 | 66 | 9 (0)| 00:00:01 |
| 48 | INLIST ITERATOR | | | | | |
|* 49 | INDEX RANGE SCAN | IDX$$_91CA0001 | 3 | 66 | 5 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 50 | FILTER | | | | | |
|* 51 | CONNECT BY WITH FILTERING | | | | | |
| 52 | TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS | | | | |
|* 53 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | 5 | 1 (0)| 00:00:01 |
| 54 | NESTED LOOPS | | | | | |
| 55 | BUFFER SORT | | | | | |
| 56 | CONNECT BY PUMP | | | | | |
| 57 | TABLE ACCESS BY INDEX ROWID | AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
|* 58 | INDEX UNIQUE SCAN | AGENCY_ACCOUNTS_ACCOUNT_ID | 1 | | 1 (0)| 00:00:01 |
|* 59 | TABLE ACCESS FULL | AGENCY_ACCOUNTS | 1 | 10 | 2 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
4 - filter( EXISTS (SELECT 0 FROM "APPLICATIONS" "A","JOBS" "SYS_ALIAS_1", (SELECT "ACCOUNT_ID" "$nso_col_1"
FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL) "VW_NSO_2","APPLICATION_FIELDS"
"APPLICATION_FIELDS" WHERE EXISTS (SELECT 0 FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL AND
("ACCOUNT_ID"=:B1)) AND ("FIELD_TYPE"='Checkbox' OR "FIELD_TYPE"='Radio' OR "FIELD_TYPE"='RadioHoriz' OR
"FIELD_TYPE"='RadioPara' OR "FIELD_TYPE"='Select' OR "FIELD_TYPE"='SelectM') AND "FIELD_NAME"=:B2 AND
"A"."ACCOUNT_ID"="$nso_col_1" AND "A"."JOB_ID"="JOB_ID" AND "A"."APPLICATION_ID"=:B3 AND
DECODE("A"."TRAY",'Incomplete','Incomplete','Complete')='Complete' AND "A"."DELETED"=0))
PLAN_TABLE_OUTPUT
5 - filter("FIELD_NAME"="AF"."FIELD_NAME" AND "INSTANCE"="AF"."FIELD_INSTANCE")
7 - access("AFO"."FIELD_NAME"="AF"."FIELD_NAME" AND "AFO"."FORM_ID"="AF"."FORM_ID")
8 - access("JF"."FORM_ID"="AF"."FORM_ID")
15 - filter("ACCOUNT_ID"=113346)
17 - access("ACCOUNT_ID"=113346)
22 - access("ACCOUNT_ID"=NULL)
23 - access("ACCOUNT_ID"=NULL)
24 - access("J"."ACCOUNT_ID"="$nso_col_1")
25 - access("JF"."JOB_ID"="$nso_col_1")
26 - filter("AF"."FIELD_TYPE"='Checkbox' OR "AF"."FIELD_TYPE"='Radio' OR "AF"."FIELD_TYPE"='RadioHoriz' OR
"AF"."FIELD_TYPE"='RadioPara' OR "AF"."FIELD_TYPE"='Select' OR "AF"."FIELD_TYPE"='SelectM')
PLAN_TABLE_OUTPUT FOR THE QUERY
28 - access("FIELD_VALUE"="AFO"."OPTION_TEXT")
29 - filter( EXISTS (SELECT 0 FROM "AGENCY_ACCOUNTS" "AGENCY_ACCOUNTS" WHERE "ACCOUNT_ID"=NULL AND
("ACCOUNT_ID"=:B1)))
33 - filter(DECODE("A"."TRAY",'Incomplete','Incomplete','Complete')='Complete' AND "A"."DELETED"=0)
34 - access("A"."APPLICATION_ID"=:B1)
36 - access("A"."JOB_ID"="JOB_ID")
37 - filter("A"."ACCOUNT_ID"="$nso_col_1")
38 - filter("ACCOUNT_ID"=113346)
40 - access("ACCOUNT_ID"=113346)
45 - access("ACCOUNT_ID"=NULL)
46 - access("ACCOUNT_ID"=NULL)
PLAN_TABLE_OUTPUT
49 - access("FIELD_NAME"=:B1 AND ("FIELD_TYPE"='Checkbox' OR "FIELD_TYPE"='Radio' OR "FIELD_TYPE"='RadioHoriz'
OR "FIELD_TYPE"='RadioPara' OR "FIELD_TYPE"='Select' OR "FIELD_TYPE"='SelectM'))
50 - filter("ACCOUNT_ID"=:B1)
51 - filter("ACCOUNT_ID"=:B1)
53 - access("ACCOUNT_ID"=:B1)
58 - access("ACCOUNT_ID"=NULL)
59 - access("ACCOUNT_ID"=NULL)
106 rows selected.TKPROF FOR THE QUERY
call count cpu elapsed disk query current rows
Parse 1 0.05 0.08 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 17 1040.45 1018.36 0 48926569 0 229
total 19 1040.50 1018.44 0 48926569 0 229
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 68
Rows Row Source Operation
229 SORT GROUP BY (cr=48926569 pr=0 pw=0 time=1018362160 us)
454 VIEW (cr=48926569 pr=0 pw=0 time=1018361382 us)
454 HASH GROUP BY (cr=48926569 pr=0 pw=0 time=1018360468 us)
185302 FILTER (cr=48926569 pr=0 pw=0 time=877249113 us)
1440799 TABLE ACCESS BY INDEX ROWID APPLICATION_DATA (cr=11309333 pr=0 pw=0 time=213262026 us)
82907114 NESTED LOOPS (cr=174051 pr=0 pw=0 time=166906535 us)
1790 HASH JOIN (cr=625 pr=0 pw=0 time=41617 us)
121 HASH JOIN (cr=310 pr=0 pw=0 time=11263 us)
39 NESTED LOOPS (cr=121 pr=0 pw=0 time=6894 us)
44 VIEW VW_NSO_3 (cr=75 pr=0 pw=0 time=6424 us)
44 HASH UNIQUE (cr=75 pr=0 pw=0 time=6333 us)
44 TABLE ACCESS BY INDEX ROWID JOBS (cr=75 pr=0 pw=0 time=3090 us)
52 NESTED LOOPS (cr=32 pr=0 pw=0 time=58177 us)
7 VIEW VW_NSO_1 (cr=23 pr=0 pw=0 time=1242 us)
7 CONNECT BY WITH FILTERING (cr=23 pr=0 pw=0 time=1212 us)
1 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=3 pr=0 pw=0 time=185 us)
1 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=2 pr=0 pw=0 time=100 us)(object id 60086)
6 NESTED LOOPS (cr=20 pr=0 pw=0 time=590 us)
7 BUFFER SORT (cr=0 pr=0 pw=0 time=248 us)
7 CONNECT BY PUMP (cr=0 pr=0 pw=0 time=95 us)
6 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=20 pr=0 pw=0 time=314 us)
6 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=14 pr=0 pw=0 time=188 us)(object id 60086)
0 TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)
44 INDEX RANGE SCAN JOBS_ACCOUNT_ID (cr=9 pr=0 pw=0 time=280 us)(object id 60253)
39 INDEX RANGE SCAN JOBS_FORMS_JID_FID (cr=46 pr=0 pw=0 time=968 us)(object id 60299)
3579 TABLE ACCESS FULL APPLICATION_FIELDS (cr=189 pr=0 pw=0 time=14469 us)
32524 TABLE ACCESS FULL APPLICATION_FIELD_OPTIONS (cr=315 pr=0 pw=0 time=32629 us)
82905323 INDEX RANGE SCAN IDX$$_B8D40001 (cr=173426 pr=0 pw=0 time=83870105 us)(object id 60121)
185297 FILTER (cr=37617236 pr=0 pw=0 time=749052070 us)
185297 MERGE JOIN CARTESIAN (cr=37617196 pr=0 pw=0 time=742583363 us)
185297 NESTED LOOPS (cr=35393366 pr=0 pw=0 time=706772617 us)
1139675 NESTED LOOPS (cr=9180841 pr=0 pw=0 time=84949686 us)
1140164 TABLE ACCESS BY INDEX ROWID APPLICATIONS (cr=5760834 pr=0 pw=0 time=46774108 us)
1440060 INDEX UNIQUE SCAN APPS_APP_ID (cr=4320774 pr=0 pw=0 time=24380604 us)(object id 60107)
1139675 TABLE ACCESS BY INDEX ROWID JOBS (cr=3420007 pr=0 pw=0 time=28126171 us)
1139675 INDEX UNIQUE SCAN JOBS_JOB_ID (cr=2280328 pr=0 pw=0 time=14563524 us)(object id 60252)
185297 VIEW VW_NSO_2 (cr=26212525 pr=0 pw=0 time=613602445 us)
6866175 CONNECT BY WITH FILTERING (cr=26212525 pr=0 pw=0 time=614183170 us)
1139675 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=3419025 pr=0 pw=0 time=24323520 us)
1139675 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=2279350 pr=0 pw=0 time=13905212 us)(object id 60086)
6838050 NESTED LOOPS (cr=22793500 pr=0 pw=0 time=388173853 us)
7977725 BUFFER SORT (cr=0 pr=0 pw=0 time=178812411 us)
7977725 CONNECT BY PUMP (cr=0 pr=0 pw=0 time=57522094 us)
6838050 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=22793500 pr=0 pw=0 time=179425469 us)
6838050 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=15955450 pr=0 pw=0 time=113988543 us)(object id 60086)
0 TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)
185297 BUFFER SORT (cr=2223830 pr=0 pw=0 time=24721936 us)
1208625 INLIST ITERATOR (cr=2223830 pr=0 pw=0 time=26470412 us)
1208625 INDEX RANGE SCAN IDX$$_91CA0001 (cr=2223830 pr=0 pw=0 time=18174073 us)(object id 60129)
2 FILTER (cr=40 pr=0 pw=0 time=1292 us)
2 CONNECT BY WITH FILTERING (cr=40 pr=0 pw=0 time=1276 us)
2 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=6 pr=0 pw=0 time=86 us)
2 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=4 pr=0 pw=0 time=46 us)(object id 60086)
10 NESTED LOOPS (cr=34 pr=0 pw=0 time=791 us)
12 BUFFER SORT (cr=0 pr=0 pw=0 time=369 us)
12 CONNECT BY PUMP (cr=0 pr=0 pw=0 time=127 us)
10 TABLE ACCESS BY INDEX ROWID AGENCY_ACCOUNTS (cr=34 pr=0 pw=0 time=376 us)
10 INDEX UNIQUE SCAN AGENCY_ACCOUNTS_ACCOUNT_ID (cr=24 pr=0 pw=0 time=242 us)(object id 60086)
0 TABLE ACCESS FULL AGENCY_ACCOUNTS (cr=0 pr=0 pw=0 time=0 us)Any help in tuning this query to run faster will be highly appreciated. I also noticed merge join certesian on the tkprof and explain plan. Any idea in takling that will also be appreciated.
Cheers,
AdeIt's quite hard to tune a query without seeing the table structure and available indices as well as relationship between each other but I'll try.
In your sql which you've given the table alias AD, you have this filter criteria
AND FIELD_NAME IN (
SELECT FIELD_NAME
FROM APPLICATION_FIELDS
WHERE FIELD_TYPE IN ('Checkbox','Radio','Select','SelectM', 'RadioHoriz','RadioPara')
) </br>
My question is, is FIELD_NAME a column in the APPLICATION_DATA table? If it is, try moving this clause outside of the current sub-query it is in, i.e. one more level up. It looks like you put them inside the wrong level.
I would also try converting this <COL> IN <SUB-QUERY> to a join, if that wouldn't affect the no. of rows returned. I can't tell for sure since I dont know the relationship between your tables.
It looks to me like you're doing this
SELECT <col list>
FROM ( SELECT -- LEVEL 1
FROM APPLICATION_DATA AD
WHERE AD.APPLICAITON_ID IN ( -- LEVEL 2
SELECT
FROM APPLICATIONS A
WHERE A.JOB_ID IN (
<SUBQUERY>
AND A.ACCOUNT_ID IN (
<SUBQUERY>
AND FIELDNAME IN ( -- SHOULD BE INSIDE LEVEL1
<SUBQUERY>
) AD,
( SELECT ....
) FD
WHERE .... -
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 -
Need to tune the hierarchical query
Hi Guys,
Can you guys tune in the possible ways...as this is taking 30-40 sec.. No indexes on this table as of now.
SELECT org_id,
parent_id,
organization,
(SELECT LISTAGG(parent_id, ', ') WITHIN GROUP( ORDER BY org_id)
FROM organization_master where org_id in(SELECT org_id
FROM organization_master
START WITH org_id = a.org_id
CONNECT BY NOCYCLE prior parent_id = org_id))
FROM t_org a
WHERE upper(organization) like upper('%Greater%');
Thanks in advance!
Rgds,
LrkSo 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 -
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 -
Need help in this sql query to use Case Statement
hi All,
I have the below query -
SELECT DISTINCT OFFC.PROV_ID
,OFFC.WK_DAY
,CASE
WHEN OFFC.WK_DAY ='MONDAY' THEN 1
WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
END AS DOW
,OFFC.OFFC_OPENG_TIME
,OFFC.OFFC_CLSNG_TIME
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID='0000600'
WITH UR;
this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
can somebody help me in achieving that.
thanks,
iamhereHi,
Welcome to the forum!
That's called a Pivot .
Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
SELECT OFFC.PROV_ID
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_OPENG_TIME END) AS mon_opn
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS mon_cls
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_OPENG_TIME END) AS tue_opn
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS tue_cls
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID = '0000600'
GROUP BY offc.prov_id
;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
Edited by: Frank Kulash on Jan 6, 2011 8:22 PM -
Please need help on this SQL query ..
hi peers,
here is my situation :
Field1 Field2 Field3
xa group1 req_id1
xb group2 req_id2
xc group3 req_id3
xa group4 req_id4
xb group5 req_id5
i need to pull only the group3 record that comes right away after group2. Req_id's are in chronological order and groupx are texts
: i.e : req_id1 < req_id2 < req_id3 <.....
in other terms, i need the record that comes after the re cord flagged by group2..knowing that req_id3 is right after req_id2.
any thoughts ?
thanksHi,
Use the analytic LAG function to get a value from an earlier row:
WITH got_prev_field2 AS
SELECT field1, field2, field3
, LAG (field2) OVER (ORDER BY field3) AS prev_field2
FROM my_situation
SELECT field1, field2, field3
FROM got_prev_field2
WHERE prev_field2 = 'group2'
;Like all analytic functions, LAG is computed after the WHERE clause is applied. To use the value returned by LAG in a WHERE clause, we have to compute it in a sub-query.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. -
Need to resolve this tricky query
Dear friends,
I just come accross a problem which I need to be resolved on high priority. Well I have following table structures for a doctor database.
Table1 : Doctor Master
Doctor ID...............Doctor Name
1...............................Ali
2...............................Saleem
3...............................Arshad
Table2 : mst_flex_field
Master_Key_ID.........Master Key Value
1..............................Qualifications
2..............................Specility
3..............................Magazine
4..............................Affiliation
Table3: mst_flex_field_Value
Flex Field Id...............Master_Key_ID............Flex Field Value
1......................................1..............................BDS
2......................................1..............................DTCD
3......................................1..............................FRCOG
4......................................1..............................MCPS
5......................................1..............................MD
6......................................1..............................MBBS
7......................................1..............................DABM
8......................................1..............................FRCP
9......................................1..............................MRC OG
10....................................2..............................ANST.
11....................................2..............................FOREMED
12....................................2..............................NEPHROLOGISTS
13....................................2..............................RHEUMATOLOGIST
14....................................2..............................CARDIOLOGIST
15....................................2..............................G.P
16....................................3..............................PROF MAG
17....................................3..............................ARTHOPY
Table4: Doctor Detail Table
Detail Table Id.......Doctor id.........Flex Field Id
1..............................1.....................6
2..............................1.....................2
3..............................1.....................3
4..............................1.....................16
5..............................1.....................17
6..............................1.....................15
7..............................2.....................10
8.............................. 2.....................6
9.............................. 2.....................8
10............................3.....................1
11............................3.....................10
12............................3.....................11
13............................3.....................17
Output Required for this structure.
Out Put
Doctor ID....Doc Name........Qualifications.............Specility..........Magazine
1..............Ali.......................MBBS.......................G.P................PROF MAG
1..............Ali.......................DTCD..............................................ARTHOPY
1..............Ali.......................FRCOG
2..............Saleem................MBBS.......................ANST.
2..............Saleem................FRCP
3..............Arshad.................BDS.......................ANST.................ARTHOPY
3..............Arshad..............................................FOREMED
One thing more I would like to make view of that query.
Best Regards,
ShahDear guys,
I finally got the solution of my problem.
Below is the solution.
select doctor_id,
coalesce( rn1, rn2, rn5 , rn6 , rn7 ) rn,
max(Qualification) "Qualification",
max(Speciality) "Speciality",
max(Personal_Hobbies) "Personal_Hobbies",
max(Professional_Interest) "Professional_Interest",
max(Designation) "Designation"
from (
select t.doctor_id,
decode (t.mst_key_id , 1 , t.rn , null) rn1,
decode (t.mst_key_id , 1 , t.flex_field_value_id) Qualification,
decode (t.mst_key_id , 2 , t.rn , null) rn2,
decode (t.mst_key_id , 2 , t.flex_field_value_id) Speciality,
decode (t.mst_key_id , 5 , t.rn , null) rn5,
decode (t.mst_key_id , 5 , t.flex_field_value_id) Personal_Hobbies,
decode (t.mst_key_id , 6 , t.rn , null) rn6,
decode (t.mst_key_id , 6 , t.flex_field_value_id) Professional_Interest,
decode (t.mst_key_id , 7 , t.rn , null) rn7,
decode (t.mst_key_id , 7 , t.flex_field_value_id) Designation
from (
select d.doctor_id , v.mst_key_id , v.flex_field_value_id,
row_number() over ( partition by d.doctor_id, v.mst_key_id
order by v.mst_key_id ) rn
from mst_doctor_other_info d,
mst_flex_field_values v
where d.flex_field_value_id = v.flex_field_value_id
-- and d.doctor_id in ( 1 , 2 , 3)
) t
group by doctor_id,
coalesce( rn1, rn2, rn5 , rn6 , rn7 )
order by 1, 2
Thanks everybody for the generous help.
Best Regards,
Shah -
the following query returns me the correct no of rows:
select col1 from tab1 where
col1 like '%'||chr(32)||'%';
but i need to use my query in the following form and it doesn't return any row:
select col1 from tab1 where
col1 IN ('%'||chr(32)||'%');
what am I doing worng?
thanks in advance.Or in 10g (just recycling another example):
WITH t AS (SELECT 'OPTI1457' || CHR(32) col1
FROM dual
UNION
SELECT 'OPT123' || CHR(9)
FROM dual
UNION
SELECT 'OPTIM12345'
FROM dual
SELECT t.*
FROM t
WHERE REGEXP_LIKE(t.col1, CHR(32) || '|' || CHR(9))
; C. -
Need to tune this Update statement.
Hi..
I have an update which I suspect is performing bad.
UPDATE
PS_OI_RNV_RCN_RECV R
SET (VOUCHER_ID, VOUCHER_LINE_NUM) =
(SELECT
M.VOUCHER_ID ,
M.VOUCHER_LINE_NUM
FROM
PS_VCHR_RECV_MTCH M
WHERE
M.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
AND M.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
AND M.RECEIVER_ID = R.RECEIVER_ID
AND M.RECV_LN_NBR = R.RECV_LN_NBR
AND (M.RECEIVER_ID, M.RECV_LN_NBR) IN ( SELECT M3.RECEIVER_ID ,M3.RECV_LN_NBR
FROM PS_VCHR_RECV_MTCH M3
WHERE
M3.BUSINESS_UNIT =R.BUSINESS_UNIT_GL
AND M3.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
AND M3.RECEIVER_ID = R.RECEIVER_ID
AND M3.RECV_LN_NBR = R.RECV_LN_NBR
HAVING COUNT(*) = :"SYS_B_0"
GROUP BY M3.RECEIVER_ID , M3.RECV_LN_NBR
WHERE
R.USERID = :"SYS_B_1"
AND R.RUN_CNTL_ID = :"SYS_B_2"
AND R.VOUCHER_ID = :"SYS_B_3"
AND R.OI_RNV_STATUS = :"SYS_B_4"
AND EXISTS ( SELECT VOUCHER_ID ,VOUCHER_LINE_NUM FROM PS_VCHR_RECV_MTCH M2
WHERE
M2.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
AND M2.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
AND M2.RECEIVER_ID = R.RECEIVER_ID
AND M2.RECV_LN_NBR = R.RECV_LN_NBR
AND (M2.RECEIVER_ID, M2.RECV_LN_NBR) IN ( SELECT M4.RECEIVER_ID ,M4.RECV_LN_NBR
FROM PS_VCHR_RECV_MTCH M4
WHERE M4.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
AND M4.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
AND M4.RECEIVER_ID = R.RECEIVER_ID
AND M4.RECV_LN_NBR = R.RECV_LN_NBR
HAVING COUNT(*) = :"SYS_B_5"
GROUP BY M4.RECEIVER_ID , M4.RECV_LN_NBR
)Plan for this Statement is
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 1 | 59 | 7413 (1)| 00:01:29 |
| 1 | UPDATE | PS_OI_RNV_RCN_RECV | | | | |
|* 2 | FILTER | | | | | |
|* 3 | TABLE ACCESS FULL | PS_OI_RNV_RCN_RECV | 1 | 59 | 750 (1)| 00:00:09 |
|* 4 | INDEX RANGE SCAN | PS_VCHR_RECV_MTCH | 1 | 27 | 1110 (1)| 00:00:14 |
|* 5 | FILTER | | | | | |
| 6 | SORT GROUP BY NOSORT| | 1 | 27 | 1110 (1)| 00:00:14 |
|* 7 | INDEX RANGE SCAN | PS_VCHR_RECV_MTCH | 1 | 27 | 1110 (1)| 00:00:14 |
|* 8 | INDEX RANGE SCAN | PS_VCHR_RECV_MTCH | 1 | 40 | 1110 (1)| 00:00:14 |
|* 9 | FILTER | | | | | |
| 10 | SORT GROUP BY NOSORT | | 1 | 27 | 1110 (1)| 00:00:14 |
|* 11 | INDEX RANGE SCAN | PS_VCHR_RECV_MTCH | 1 | 27 | 1110 (1)| 00:00:14 |
Predicate Information (identified by operation id):
2 - filter( EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "SYS_ALIAS_10" WHERE
"M2"."BUSINESS_UNIT"=:B1 AND "M2"."RECEIVER_ID"=:B2 AND "M2"."RECV_LN_NBR"=:B3 AND
"M2"."BUSINESS_UNIT_PO"=:B4 AND EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M4" WHERE
"M4"."BUSINESS_UNIT"=:B5 AND "M4"."RECEIVER_ID"=:B6 AND "M4"."RECV_LN_NBR"=:B7 AND
"M4"."BUSINESS_UNIT_PO"=:B8 GROUP BY "M4"."RECEIVER_ID","M4"."RECV_LN_NBR" HAVING
PLAN_TABLE_OUTPUT
"M4"."RECEIVER_ID"=:B9 AND "M4"."RECV_LN_NBR"=:B10 AND COUNT(*)=TO_NUMBER(:SYS_B_5))))
3 - filter("R"."VOUCHER_ID"=:SYS_B_3 AND "R"."RUN_CNTL_ID"=:SYS_B_2 AND
"R"."OI_RNV_STATUS"=:SYS_B_4 AND "R"."USERID"=:SYS_B_1)
4 - access("M2"."BUSINESS_UNIT"=:B1 AND "M2"."RECEIVER_ID"=:B2 AND
"M2"."RECV_LN_NBR"=:B3 AND "M2"."BUSINESS_UNIT_PO"=:B4)
filter("M2"."RECEIVER_ID"=:B1 AND "M2"."RECV_LN_NBR"=:B2 AND
"M2"."BUSINESS_UNIT_PO"=:B3 AND EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M4" WHERE
"M4"."BUSINESS_UNIT"=:B4 AND "M4"."RECEIVER_ID"=:B5 AND "M4"."RECV_LN_NBR"=:B6 AND
"M4"."BUSINESS_UNIT_PO"=:B7 GROUP BY "M4"."RECEIVER_ID","M4"."RECV_LN_NBR" HAVING
"M4"."RECEIVER_ID"=:B8 AND "M4"."RECV_LN_NBR"=:B9 AND COUNT(*)=TO_NUMBER(:SYS_B_5)))
5 - filter("M4"."RECEIVER_ID"=:B1 AND "M4"."RECV_LN_NBR"=:B2 AND
COUNT(*)=TO_NUMBER(:SYS_B_5))
7 - access("M4"."BUSINESS_UNIT"=:B1 AND "M4"."RECEIVER_ID"=:B2 AND
"M4"."RECV_LN_NBR"=:B3 AND "M4"."BUSINESS_UNIT_PO"=:B4)
filter("M4"."RECEIVER_ID"=:B1 AND "M4"."RECV_LN_NBR"=:B2 AND
"M4"."BUSINESS_UNIT_PO"=:B3)
8 - access("M"."BUSINESS_UNIT"=:B1 AND "M"."RECEIVER_ID"=:B2 AND
"M"."RECV_LN_NBR"=:B3 AND "M"."BUSINESS_UNIT_PO"=:B4)
filter("M"."RECEIVER_ID"=:B1 AND "M"."RECV_LN_NBR"=:B2 AND
"M"."BUSINESS_UNIT_PO"=:B3 AND EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M3" WHERE
"M3"."BUSINESS_UNIT"=:B4 AND "M3"."RECEIVER_ID"=:B5 AND "M3"."RECV_LN_NBR"=:B6 AND
"M3"."BUSINESS_UNIT_PO"=:B7 GROUP BY "M3"."RECEIVER_ID","M3"."RECV_LN_NBR" HAVING
"M3"."RECEIVER_ID"=:B8 AND "M3"."RECV_LN_NBR"=:B9 AND COUNT(*)=TO_NUMBER(:SYS_B_0)))
9 - filter("M3"."RECEIVER_ID"=:B1 AND "M3"."RECV_LN_NBR"=:B2 AND
COUNT(*)=TO_NUMBER(:SYS_B_0))
11 - access("M3"."BUSINESS_UNIT"=:B1 AND "M3"."RECEIVER_ID"=:B2 AND
"M3"."RECV_LN_NBR"=:B3 AND "M3"."BUSINESS_UNIT_PO"=:B4)
PLAN_TABLE_OUTPUT
filter("M3"."RECEIVER_ID"=:B1 AND "M3"."RECV_LN_NBR"=:B2 AND
"M3"."BUSINESS_UNIT_PO"=:B3)
DBMS_METADATA.GET_DDL('INDEX','PS_VCHR_RECV_MTCH')
CREATE UNIQUE INDEX "SYSADM"."PS_VCHR_RECV_MTCH" ON "SYSADM"."PS_VCHR_RECV_MTC
H" ("BUSINESS_UNIT", "VOUCHER_ID", "VOUCHER_LINE_NUM", "BUSINESS_UNIT_RECV", "RE
CEIVER_ID", "RECV_LN_NBR", "RECV_SHIP_SEQ_NBR", "BUSINESS_UNIT_PO", "PO_ID", "LI
NE_NBR", "SCHED_NBR")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 40960 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "PSINDEX"
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 2007.68 2012.83 2 182564670 4260 4070
Fetch 0 0.00 0.00 0 0 0 0
total 2 2007.68 2012.83 2 182564670 4260 4070Thanks...
Edited by: Oceaner on May 24, 2012 7:15 AMHi Gokul,
in case of no statistics most likely the optimizer would do a dynamic sampling, so ironically, no statistics is often better than statistics.
It could be that some of the tables is used as a temp table (i.e. is filled with data to carry out some operations, and then purged), in which case the stats job could've caught it when it was empty. But even if the cardinalities would have been fine, I don't really think the optimizer has a lot of options with the query as is stands, because the aggregate subqueries restrict the ability of the optimizer to apply query transforms.
Still, worth a shot to check if stats are accurate -- that's an easy thing to do and couldn't possibly do any harm.
Best regards,
Nikolay -
CalcScript. Need help tunning this up, please
I have the following:
FIX ("mbrDim1",@RELATIVE("dim2",0), "mbrDim3", @RELATIVE("dim4",-1), "mbrDim5")
DATACOPY "No_mbrDim_6_"->"AUX_mbr*1*Dim_7_" TO "No_mbrDim_7_"->"mbr*1*Dim_6_";
DATACOPY "No_mbrDim_6_"->"AUX_mbr*2*Dim_7_" TO "No_mbrDim_7_"->"mbr*2*Dim_6_";
DATACOPY "No_mbrDim_6_"->"AUX_mbr*3*Dim_7_" TO "No_mbrDim_7_"->"mbr*3*Dim_6_";
DATACOPY "No_mbrDim_6_"->"AUX_mbr*4*Dim_7_" TO "No_mbrDim_7_"->"mbr*4*Dim_6_";
This is: Provided the foreseen FIX statement, I need to copy data from the "No_mbrDim6"->"AUX_mbr*Dim7" to the "No_mbrDim7"->"mbr*Dim6", so the AUX_ members on dim7 have to find their correspondent in dim6. There are technical reasons for this outline arrangement.
I've tried the following:
"No_mbrDim7" = "No_mbrDim6" -> @MEMBER(@SUBSTRING(@NAME(@CURRMBR("dim7Name")),4)); >>>> +Error: 1200370 Error executing formula for [No_mbrDim7] (line 0): attempt to cross a null member in function [@X]+
"No_mbrDim7" = "No_mbrDim6" -> @MEMBER(@SUBSTRING(@NAME(@RELATIVE("ParentMbr_AUX_mbrDim7",0)),4)); >>>> +Error: 1200497 Error compiling formula for [No_mbrDim7] (line 93): unknown member name ["ParentMbr_AUX_mbrDim7"] in function [@RELATIVE].+
(In both cases, the 4 is intended to remove the AUX_ prefix so member names in both dim6 and dim7 dimensions match).
As you can guess, even if the first option is bomb-proof, it's not a good option since the AUX_mbr*Dim7 and mbr*Dim6 members could vary oftenly.
Any ideas, please?
Many thanks!
Edited by: 836559 on Feb 14, 2011 8:18 AMHi,
If your refering like running the recovery you may check this thread for details -- >
http://laptopforums.toshiba.com/tshb/board/message?message.uid=683#U683
"I'm Not the Message... Just the Messenger.. i Don't Play the Music... The music plays through me... Im just a Channel..... That's all I AM "
Maybe you are looking for
-
I've recently started having a few problems with iTunes, and was wondering if anyone could offer advice on how to go about fixing them. First of all, iTunes opens up (it takes quite a long time) and then everything goes slow. It keeps automatically u
-
I am wondering if using a Mac Mini with a 26" HDTV would give me equivalent or better image quality than I would merely get by using a 27" iMac? I want to use my Mac in 2 different locations (staying in each for several mos at a time), and am conside
-
I know this may sound like a strange request, but if there is anyone here with a Nokia 7373 phone, i was hoping you might be able to help me. I have one of these, but i have managed to crush my display so i can't see anything on it. So if there is so
-
If I update to ios 7 then will it set my phone to factory settings?
If I update to ios 7 then will it set my phone to factory settings?
-
Attributing Documents in the public area of a Collaboration Room
Is there a way you can attribute documents to your taxonomy that are stored in the public area of a collaboration room?