Please help me tune this query
Hi,
Could you please suggest how the below query can be tuned? At present the query takes an hour to execute for a single transaction.
===================================================================
/* Formatted on 2009/07/27 17:44 (Formatter Plus v4.8.8) */
SELECT 'x' x,
SUBSTR (cn.trx_number, 1, INSTR (cn.trx_number, 'CN') - 1) invoice_num,
DECODE (INSTR (cn.trx_number, 'CNT'),
0, '¿¿¿¿¿¿¿¿ (CREDIT NOTE)',
'¿¿¿¿¿¿¿¿ (CREDIT NOTE) / ¿¿¿¿¿¿¿¿¿¿¿'
) report_name,
INSTR (cn.trx_number, 'CNT') v_or_nv,
xxth_get_info.get_org_name (:org_id) head_office_name, lc.location_id,
lc.location_code, lc.attribute1 tax_regis_number,
lc.attribute2 tax_payer_id, lc.attribute14 branch_number,
lc.attribute15 name_of_place_of_business,
lc.address_line_1 || ' ' || lc.address_line_2 address_line1,
lc.address_line_3 || ' ' || lc.region_1 address_line2,
lc.region_2
|| ' '
|| lc.town_or_city
|| ' '
|| lc.postal_code
|| ' '
|| lc.country address_line3,
cn.type_cn, cn.rac_bill_to_customer_name, cn.address1,
cn.raa_bill_to_address3, cn.bill_to_site_use_id, cn.trx_date,
cn.trx_number, cn.rac_bill_to_customer_num, cn.description,
ABS (cn.extended_amount) extended_amount, ABS (cn.tax_amt) tax_amt,
rc.trx_rec_number, rc.apply_date, rc.cash_receipt_id
FROM ra_cust_trx_types cc,
hr_locations_v lc,
(SELECT b.cash_receipt_id, a.trx_number, b.trx_rec_number,
b.apply_date
FROM ar_payment_schedules a, ar_app_adj_v b,ar_cash_receipts c
WHERE b.payment_schedule_id = a.payment_schedule_id
AND c.cash_receipt_id=b.cash_receipt_id
AND c.status='APP'
AND b.CLASS = 'Payment'
group by b.cash_receipt_id, a.trx_number, b.trx_rec_number,b.apply_date) rc,
(SELECT 'B' type_cn, a.customer_trx_id, a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1
|| ' '
|| a.raa_bill_to_address2 address1,
a.raa_bill_to_address3, a.bill_to_site_use_id, a.trx_date,
a.trx_number,
( SUBSTR (a.trx_number, 1,
INSTR (a.trx_number, 'CN', -1) - 1)
|| SUBSTR (a.trx_number, INSTR (a.trx_number, 'CN', -1) + 2)
) trx_number_cmp,
a.rac_bill_to_customer_num,
ctl.description, -- b.description
sum(nvl(ctl.gross_extended_amount, ctl.extended_amount)) extended_amount, -- V2.0
-- SUM (c.extended_amount) tax_amt -- V2.0
select SUM (ctl_tax.extended_amount)
from ra_customer_trx_lines ctl_tax,
ra_customer_trx_lines ctl_line
WHERE ctl_tax.link_to_cust_trx_line_id = ctl_line.customer_trx_line_id
AND ctl_tax.line_type = 'TAX'
AND ctl_tax.customer_trx_id = a.customer_trx_id
) tax_amt
FROM ra_customer_trx_partial_v a,
ra_customer_trx_lines ctl,
ra_customer_trx ct,
ra_cust_trx_types ctt,
hz_cust_acct_sites radd,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses site
-- ra_customer_trx_lines_v b
-- ar_tax_summ_v c
WHERE a.ctt_class = 'CM'
AND ctl.line_type = 'LINE'
&P_CUSTOMER_NUM_CLAUSE
&P_CUST_TRX_NUM_CLAUSE
-- AND b.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = ct.customer_trx_id
AND ct.cust_trx_type_id = ctt.cust_trx_type_id
AND ctt.TYPE NOT IN ('DEP', 'GUAR', 'BR')
AND ct.bill_to_site_use_id = site.site_use_id
AND site.cust_acct_site_id = radd.cust_acct_site_id
AND radd.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
-- AND c.customer_trx_id(+) = a.customer_trx_id
GROUP BY a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1,
a.raa_bill_to_address2,
a.raa_bill_to_address3,
a.bill_to_site_use_id,
a.trx_date,
a.trx_number,
a.rac_bill_to_customer_num,
a.customer_trx_id,
ctl.description,
(SUBSTR (a.trx_number, 1, INSTR (a.trx_number, 'CN') - 1)
)) cn
WHERE cc.cust_trx_type_id = cn.cust_trx_type_id
AND cc.global_attribute19 = lc.location_code(+)
AND rc.trx_number = cn.trx_number_cmp
=============================================================
Post relevant all details as explained in this instruction:
HOW TO: Post a SQL statement tuning request - template posting
Similar Messages
-
Hi,
I'm using below query in procedure.It's taking more more time can some one help to tune this query or advice to rewrite the query.
Databse :10.1
SELECT 'Reading Comprehension' TEST_NAME,T.TEST_END_DATE TEST_SESSION_DATE,
C.POOL_VERSION_ID, I.CREATED_ON POOL_CREATED_DT,
C.ITEM_ID, C.ITEM_RESPONSE_ID, S.STUDENT_ID_PK, C.RESPONSE_KEY, C.IS_CORRECT RESPONSE_IS_CORRECT,
T.SCORE SCALE_SCORE, C.RESPONSE_DURATION, P.ITEM_KEY,
T.TEST_SESSION_DETAIL_ID, SYSDATE CREATED_ON
-- BULK COLLECT INTO TV_PSYCHO_DET
FROM
CAT_ITEM_PARAMETER P, CAT_ITEM_USER_RESPONSE C, TEST_SESSION_DETAIL T,
TEST_SESSION S, ITEM_POOL_VERSION I, TEST_DETAIL D
,INSTITUTION E
WHERE TRUNC(T.TEST_END_DATE) BETWEEN TO_DATE('01-11-09','dd-mm-yy') AND TO_DATE('30-11-09','dd-mm-yy')
AND D.TEST_NAME = 'Reading Comprehension'
AND T.TEST_SESSION_STATUS_ID = 3
AND I.POOL_AVAILABILITY='Y'
AND P.PRETEST=0 AND C.RESTART_FLAG=0
AND T.TEST_DETAIL_ID = D.TEST_DETAIL_ID
AND S.TEST_SESSION_ID = T.TEST_SESSION_ID
AND C.TEST_SESSION_DETAIL_ID = T.TEST_SESSION_DETAIL_ID
AND S.INSTITUTION_ID=E.INSTITUTION_ID
AND SUBSTR(E.INSTITUTION_ID_DISPLAY,8,3) <> '000'
AND I.ITEM_ID = C.ITEM_ID
AND P.ITEM_ID = I.ITEM_ID;expln plan
Plan hash value: 3712814491
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart|
Pstop |
| 0 | SELECT STATEMENT | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
|* 1 | FILTER | | | | | | |
|
|* 2 | HASH JOIN | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
| 3 | PARTITION HASH ALL | | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 4 | TABLE ACCESS FULL | CAT_ITEM_PARAMETER | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 5 | HASH JOIN | | 94938 | 12M| 93356 (1)| 00:18:41 | |
|
|* 6 | TABLE ACCESS FULL | ITEM_POOL_VERSION | 9036 | 132K| 30 (0)| 00:00:01 | |
|
|* 7 | TABLE ACCESS BY GLOBAL INDEX ROWID | CAT_ITEM_USER_RESPONSE | 9 | 279 | 18 (0)| 00:00:01 | ROWID |
ROWID |
| 8 | NESTED LOOPS | | 45349 | 5270K| 93325 (1)| 00:18:40 | |
|
|* 9 | HASH JOIN | | 4923 | 423K| 11377 (1)| 00:02:17 | |
|
|* 10 | INDEX FAST FULL SCAN | INSTI_ID_NAME_COUN_DISP_IDX | 8165 | 111K| 18 (0)| 00:00:01 | |
|
|* 11 | HASH JOIN | | 4923 | 355K| 11359 (1)| 00:02:17 | |
|
|* 12 | TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_SESSION_DETAIL | 4107 | 148K| 6804 (1)| 00:01:22 | ROWID |
ROWID |
| 13 | NESTED LOOPS | | 4923 | 278K| 6806 (1)| 00:01:22 | |
|
|* 14 | INDEX RANGE SCAN | TEST_DETAIL_AK_1 | 1 | 21 | 2 (0)| 00:00:01 | |
|
|* 15 | INDEX RANGE SCAN | TEST_SESSION_DETAIL_FK2_I | 39737 | | 102 (0)| 00:00:02 | |
|
| 16 | PARTITION HASH ALL | | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
| 17 | TABLE ACCESS FULL | TEST_SESSION | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
|* 18 | INDEX RANGE SCAN | CAT_ITEM_USER_RESP_IDX1 | 18 | | 3 (0)| 00:00:01 | |
|
Predicate Information (identified by operation id):
1 - filter(TO_DATE('01-11-09','dd-mm-yy')<=TO_DATE('30-11-09','dd-mm-yy'))
2 - access("P"."ITEM_ID"="I"."ITEM_ID")
4 - filter("P"."PRETEST"=0)
5 - access("I"."ITEM_ID"="C"."ITEM_ID")
6 - filter("I"."POOL_AVAILABILITY"='Y')
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)
9 - access("S"."INSTITUTION_ID"="E"."INSTITUTION_ID")
10 - filter(SUBSTR("E"."INSTITUTION_ID_DISPLAY",8,3)<>'000')
11 - access("S"."TEST_SESSION_ID"="T"."TEST_SESSION_ID")
12 - filter(TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))>=TO_DATE('01-11-09','dd-mm-yy') AND "T"."TEST_SESSION_STATUS_ID"=3
AND TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))<=TO_DATE('30-11-09','dd-mm-yy'))
14 - access("D"."TEST_NAME"='Reading Comprehension')
15 - access("T"."TEST_DETAIL_ID"="D"."TEST_DETAIL_ID")
18 - access("C"."TEST_SESSION_DETAIL_ID"="T"."TEST_SESSION_DETAIL_ID")
43 rows selected.Edited by: user575115 on Dec 18, 2009 12:31 AMWhen you see something like ...
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0) It means that Oracle had to do a conversion for you since you aren't using the proper data type in your query.
That would mean IF there is an index on that column, it won't be useable... -
Please help to modifiy this query for better performance
Please help to rewrite this query for better performance. This is taking long time to execute.
Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains 200000 rows.
I have created index on ACCOUNT_ID
Query is shown below
update rbabu.t_t_bil_bil_cycle_change a
set account_number =
( select distinct b.account_number
from rbabu.t_acctnumberTab b
where a.account_id = b.account_id
Table structure is shown below
SQL> DESC t_acctnumberTab;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24)
SQL> DESC t_t_bil_bil_cycle_change;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24) YIshan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
merge rbabu.t_t_bil_bil_cycle_change a
using
( select distinct account_number, account_id
from rbabu.t_acctnumberTab
) t
on ( a.account_id = b.account_id
and decode(a.account_number, b.account_number, 0, 1) = 1
when matched then
update set a.account_number = b.account_number -
Could you please help me make this query less complicated
could you please help me make this query less complicated
select t1.R_OBJECT_ID
from dm_relation_sp a, ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID
union all
select t3.R_OBJECT_ID
from ddt_resolution_sp t3
where t3.R_OBJECT_ID in (select t2.child_id
from dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
union all
select t4.R_OBJECT_ID
from ddt_resolution_sp t4
where t4.R_OBJECT_ID in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
union all
select t5.R_OBJECT_ID
from ddt_resolution_sp t5
where t5.R_OBJECT_ID in
(select t4.child_id
from dm_relation_sp t4
where t4.parent_id in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
and t4.relation_name = 'RESOLUTION_RELATION')
Edited by: user13025450 on 29.04.2010 16:23Hi,
Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
Describe what you're doing. Think about it: how do we know that
SELECT NULL
FROM dual;doesn't do what you want?
Post CREATE TABLE and INSERT statements for a little sample data.
Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
Describe, as well as you can, how the present query is doing it.
Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
When posting formatted text (code or results) type these 6 characters
\(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing? -
I would like to create a view on this table with four columns
1. PN#_EXP_DATE
2. PN#
3. PN#_EFF_DATE
4. PN#
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:54:57 PM
I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
where table B will have one extra column exp_dt)
NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
for example: from the above sample data, let us take first two records..
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM --- Record 1
21698 13921 1 5/29/2009 3:54:57 PM --- Record 2
from this..
Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
2. PN# comes from table D. It contains numbers for the resp. weeks.
3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
I wanted the data like..
---- this is for the second record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:57 PM 214 5/29/2009 3:15:41 PM 214
---- this is for the first record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:41 PM 214 ( for this we should query the table C to get the
start_date, for this combinatation of P_S_C and A_C in table B
where B.P_S_C = C.A_C
and that value should be the EFF_DT for this record)
Please help me with this....
Thanks in advance..Hi All,
select d.P# as "PN#_EXP_DATE", exp_date
from daily_prd d, cbs1_assoc_hist b
where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
and d.period_type = 'TIMEREPORT';
This above query gives the output as follows:
pn#_exp_date exp_date
214 5/29/2009 3:15:40 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
This below is the data from history table (Table B).
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 13921 1 5/29/2009 3:15:41 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:54:57 PM
I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
My question is again....
CASE - 1
from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
in this case we can take the example...
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
In this case, the
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:57 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case, our eff_date is '5/29/2009 3:15:40 PM'.
but how to get this.
CASE - 2
from the above sample data, consider this
P_S_C A_C PLACE EXP_DATE
21698 1716656 4 5/29/2009 3:15:41 PM
In this case, there is only one record for the P_S_C and A_C combination.
The expected result :
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:41 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
for this join B.P_S_C and C.R_C.
Hope I am clear now..
Thanks in advance..... -
Hi Everyone...Please help me with this query...!
Please Help me with this doubt as I am unable to understand the logic...behind this code. It's a begineer level code but I need to understand the logic so that I am able to grasp knowledge. Thank you all for being supportive. Please help me.
//Assume class Demo is inherited from class SuperDemo...in other words class Demo extends SuperDemo
//Volume is a method declared in SuperDemo which returns an integer value
//weight is an integer vairable declared in the subclass which is Demo
class Example
public static void main(String qw[])
Demo ob1=new Demo(3,5,7,9);
//Calling Constructor of Demo which takes in 4 int parameters
SuperDemo ob2=new SuperDemo();
int vol;
vol=ob1.volume();
System.out.println("Volume of ob1 is " + vol);
System.out.println("Weight of ob1 is " + ob1.weight);
System.out.println();
ob2=ob1;
}Can someone please make me understand --- how is this possible and why !
If the above statement is valid then why not this one "System.out.println(ob2.weight);"
Thanks Thanks Thanks!u see the line wherein I am referencing the objectof
a subclass to the superclass...right? then why we
can't do System.out.println(ob2.weight)?You need to distinguish two things:
- the type of the object, which determines with the
object can do
- the type of the reference to the object, which
determines what you see that you can do
Both don't necessarily have to match. When you use a
SuperDemo reference (obj2) to access a Demo instance
(obj1), for all you know, the instance behind obj2 is
of type SuperDemo. That it's in reality of type Demo
is unknown to you. And usually, you don't care -
that's what polymorphism is about.
So you have a reference obj2 of type SuperDemo.
SuperDemo objects don't have weight, so you don't see
it - even though it is there.So from ur explanation wat I understand is - Even though u reference a subclass object to a superclass, u will only be able to access the members which are declared in the superclass thru the same...right
? -
Need help in tune this query.
Hi All,
The below query is taking nearly one hour to give the output.
2 select sku.VK_UNIT
3 , sku.MODEL
4 , sku.DESCRIPTION
5 , slt.GEO
6 , slt.LEAD_TIME
7 , slt.REV_LEAD_TIME
8 , aud.LEAD_TIME as PREV_LEAD_TIME_GEO
9 , aud.REV_LEAD_TIME as PREV_REV_LEAD_TIME_GEO
10 , slt.COUNTDOWN
11 , aud.CREATION_DATE as EDD_CREATION_DATE_GEO
12 , aud.CREATED_BY as EDD_CREATED_BY_GEO
13 from LTC_GLOBAL.LTC_SKU sku
14 , LTC_GLOBAL.LTC_SKU_LEAD_TIME slt
15 , (select VK_UNIT
16 , MODEL
17 , substr(ACTION_TYPE, 9) as GEO
18 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then ACTION_VALUE else null end) as LEAD_TIME
19 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATION_DATE else null end) as CREATION_DATE
20 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATED_BY else null end) as CREATED_BY
21 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then ACTION_VALUE else null end) as REV_LEAD_TIME
22 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATION_DATE else null end) as REV_CREATION_DATE
23 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATED_BY else null end) as REV_CREATED_BY
24 from (select VK_UNIT
25 , MODEL
26 , ACTION_TYPE
27 , ACTION_VALUE
28 , CREATION_DATE
29 , CREATED_BY
30 , PREV_ACTION_VALUE
31 , PREV_CREATION_DATE
32 , PREV_CREATED_BY
33 from (select
34 NOTE as VK_UNIT
35 , NOTE2 as MODEL
36 , ACTION_TYPE
37 , ACTION_VALUE
38 , CREATION_DATE
39 , CREATED_BY
40 , row_number() over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as DEPTH
41 , lead(CREATION_DATE) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATION_DATE
42 , lead(CREATED_BY ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATED_BY
43 , lead(ACTION_VALUE ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_ACTION_VALUE
44 from LTC_GLOBAL.LTC_AUDIT
45 where NOTE is not null
46 and NOTE2 is not null
47 and ACTION_TYPE is not null
48 )
49 where DEPTH = 2
50 and substr(ACTION_TYPE, 1, 8) in ('SKU EDD ', 'SKU RDD ')
51 )
52 group by VK_UNIT, MODEL, substr(ACTION_TYPE, 9)
53 ) aud
54 where slt.VK_UNIT = sku.VK_UNIT
55 and slt.MODEL = sku.MODEL
56 and slt.CLASS = sku.CLASS
57 and nvl(slt.LEAD_TIME, slt.REV_LEAD_TIME) is not null
58 and aud.VK_UNIT (+)= slt.VK_UNIT
59 and aud.MODEL (+)= slt.MODEL
60 and aud.GEO (+)= slt.GEO;
PLAN_TABLE_OUTPUT
Plan hash value: 2687821083
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 539K| 902M| | 1005K (1)| 03:21:05 |
|* 1 | HASH JOIN OUTER | | 539K| 902M| 62M| 1005K (1)| 03:21:05 |
|* 2 | HASH JOIN | | 539K| 56M| 27M| 66402 (1)| 00:13:17 |
|* 3 | TABLE ACCESS FULL | LTC_SKU_LEAD_TIME | 559K| 20M| | 23201 (2)| 00:04:39 |
| 4 | TABLE ACCESS FULL | LTC_SKU_UNIT | 5726K| 382M| | 19570 (1)| 00:03:55 |
| 5 | VIEW | | 4157K| 6522M| | 610K (2)| 02:02:02 |
PLAN_TABLE_OUTPUT
| 6 | HASH GROUP BY | | 4157K| 229M| 303M| 610K (2)| 02:02:02 |
|* 7 | VIEW | | 4157K| 229M| | 551K (2)| 01:50:21 |
|* 8 | WINDOW SORT PUSHED RANK| | 4157K| 229M| 303M| 551K (2)| 01:50:21 |
|* 9 | TABLE ACCESS FULL | LTC_AUDIT | 4157K| 229M| | 493K (2)| 01:38:41 |
Predicate Information (identified by operation id):
1 - access("AUD"."VK_UNIT"(+)="SLT"."VK_UNIT" AND "AUD"."MODEL"(+)="SLT"."MODEL" AND
"AUD"."GEO"(+)="SLT"."GEO")
PLAN_TABLE_OUTPUT
2 - access("SLT"."VK_UNIT"="UNIT"."VK_UNIT" AND "SLT"."MODEL"="UNIT"."MODEL" AND
"SLT"."CLASS"="UNIT"."CLASS")
3 - filter(NVL("SLT"."LEAD_TIME","SLT"."REV_LEAD_TIME") IS NOT NULL)
7 - filter("DEPTH"=2)
8 - filter(ROW_NUMBER() OVER ( PARTITION BY "NOTE","NOTE2","ACTION_TYPE" ORDER BY
INTERNAL_FUNCTION("CREATION_DATE") DESC )<=2)
9 - filter((SUBSTR("ACTION_TYPE",1,8)='SKU EDD ' OR SUBSTR("ACTION_TYPE",1,8)='SKU RDD ') AND
"NOTE2" IS NOT NULL AND "ACTION_TYPE" IS NOT NULL)
30 rows selected.
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_SKU--5012335
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_SKU_LEAD_TIME--8060956
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_AUDIT--58309887
CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_LEAD_TIME_PK ON LTC_GLOBAL.LTC_SKU_LEAD_TIME(VK_UNIT, MODEL, CLASS, GEO)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME ON LTC_GLOBAL.LTC_AUDIT(ACTION_TYPE)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM ON LTC_GLOBAL.LTC_AUDIT(NOTE, NOTE2, ACTION_TYPE)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM1 ON LTC_GLOBAL.LTC_AUDIT("CREATION_DATE" DESC)
Please help me.
Thanks in advance.Thanks for your response.
Sorry for violating formatting. Since I am not aware of the format options in new environment.
I have created functional based index on SUBSTR(ACTION_TYPE, 1, 8).
The cost got reduced some what.But still the query is taking 40 minutes.
The following predicate it is returning 58296618 rows.
NOTE is not null
and NOTE2 is not null
and ACTION_TYPE is not null
LTC_SKU_UNIT is a view.
The following query is used for creating this view.
SELECT unit.VK_UNIT,
unit.MODEL,
unit.CLASS,
unit.LOB,
unit.LAST_UPDATE_DATE,
unit.DESCRIPTION
FROM LTC_GLOBAL.LTC_SKU_UNIT unit;
The following indexes are created on the LTC_GLOBAL.LTC_SKU_UNIT table.
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_CLASS ON LTC_GLOBAL.LTC_SKU_UNIT(CLASS)
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_MODEL ON LTC_GLOBAL.LTC_SKU_UNIT(MODEL)
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_UPDATE_DATE ON LTC_GLOBAL.LTC_SKU_UNIT(LAST_UPDATE_DATE)
CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_UNIT_PK ON LTC_GLOBAL.LTC_SKU_UNIT(VK_UNIT, MODEL, CLASS)
Is there any way to rewrite the query to improve the performance. Any suggestions to improve the performance.
Please help me.
Thanks in advance. -
Please help me constructing this query
please help me .
table a
===========
transactionid personname year dept
r001 person1 y1 d1
r002 person1 y2 d2
r005 person3 y1 d2
r004 person2 y2 d1
table b
===========
transactionid personname year
r005 person3 y2
r006 person4 y1
r001 person1 y1
outout should be like
======================
transactionid personname year dept
r001 person1 y1 d1 record present (combination of transactionid/personname/year)in table a from table b
r005 person3 y2 d2 (no data present in table a (transactionid/personname/year) from table b
so it will retrive previous dept records for this person for this year so here d2)
r006 person4 y1 unknown no data present for this person in table a so department will be unknown
table creation script
=====================
CREATE TABLE A
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE),
DEPT VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r001', 'person1', 'y1', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r002', 'person1', 'y2', 'd2');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r004', 'person2', 'y2', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r005', 'person3', 'y1', 'd2');
COMMIT;
CREATE TABLE B
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r001', 'person1', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r006', 'person4', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r005', 'person3', 'y2');
COMMIT;Anirudha Dhopate wrote:
Following query should work - Data magic:
SQL> SELECT *
2 FROM a
3 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r002 person1 2011 d2
r004 person2 2011 d1
r005 person3 2010 d2
r001 person1 2010 d2
SQL> SELECT *
2 FROM b
3 /
TRANSACTIONID PERSONNAME YEAR
r001 person1 2010
r006 person4 2010
r005 person3 2011
SQL> SELECT b.transactionid
2 ,b.personname
3 ,b.year
4 ,a.dept
5 FROM a
6 RIGHT OUTER JOIN b
7 ON ((a.transactionid = b.transactionid) AND
8 (a.personname = b.personname) AND
9 (a.year = b.year OR a.year = b.year - 1))
10 ORDER BY b.transactionid
11 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> select b.transactionid,
2 b.personname,
3 b.year,
4 max(a.dept) keep(dense_rank last order by a.year) dept
5 from b
6 left join
7 a
8 on (
9 b.transactionid = a.transactionid
10 and
11 b.personname = a.personname
12 and
13 b.year >= a.year
14 )
15 group by b.transactionid,
16 b.personname,
17 b.year
18 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> SY. -
Please help me with this query -- i am trying with Dense rank
version 10g
i received a quote for an account. if the same quote is received under different account then i should mark the previous account received as deleted.
please help me .
/* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date,
DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
ACCOUNT) rn
-- ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
-- ACCOUNT)
-- WHEN 1
-- THEN 'Y'
-- ELSE 'N'
-- END deleted_flag
FROM temp
ORDER BY quote_id, captured_date;output required
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date, 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date, deleted_flag
FROM temp
ORDER BY quote_id, captured_date;try to wrap your query to become an in-line view. use a case statement or decode to your derived column RN from the analytic query of DENSE RANK. either way they both will work.
SQL> WITH temp AS
2 (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
3 TO_DATE ('12/23/2009 3:37:54',
4 'mm/dd/yyyy hh:mi:ss PM'
5 ) captured_date
6 FROM DUAL
7 UNION ALL
8 SELECT '1-11TWQL', 'COPS', 'RFS',
9 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
10 FROM DUAL
11 UNION ALL
12 SELECT '1-11TWQL', 'COPS', 'Rejected',
13 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
14 FROM DUAL
15 UNION ALL
16 SELECT '1-11TWQL', 'COPS', 'Validated',
17 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
18 FROM DUAL
19 UNION ALL
20 SELECT '1-11TWQL', 'D1', 'Ordered',
21 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
22 FROM DUAL
23 UNION ALL
24 SELECT '1-11TWQL', 'D1', 'RFS',
25 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
26 FROM DUAL
27 UNION ALL
28 SELECT '1-11TWQL', 'D1', 'Rejected',
29 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
30 FROM DUAL
31 UNION ALL
32 SELECT '1-11TWQL', 'D1', 'Validated',
33 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
34 FROM DUAL
35 UNION ALL
36 SELECT '1-249A8X', 'COPS', 'RFS',
37 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
38 FROM DUAL
39 UNION ALL
40 SELECT '1-249A8X', 'COPS', 'RFS',
41 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
42 FROM DUAL
43 UNION ALL
44 SELECT '1-249A8X', 'COPS', 'RFS',
45 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
46 FROM DUAL
47 UNION ALL
48 SELECT '1-249A8X', 'COPS', 'Rejected',
49 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
50 FROM DUAL
51 UNION ALL
52 SELECT '1-249A8X', 'COPS', 'Rejected',
53 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
54 FROM DUAL
55 UNION ALL
56 SELECT '1-249A8X', 'COPS', 'Rejected',
57 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
58 FROM DUAL
59 UNION ALL
60 SELECT '1-249A8X', 'COPS', 'Validated',
61 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
62 FROM DUAL
63 UNION ALL
64 SELECT '1-249A8X', 'COPS', 'Validated',
65 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
66 FROM DUAL
67 UNION ALL
68 SELECT '1-249A8X', 'COPS', 'Validated',
69 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
70 FROM DUAL
71 UNION ALL
72 SELECT '1-249A8X', 'D1', 'Ordered',
73 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
74 FROM DUAL
75 UNION ALL
76 SELECT '1-249A8X', 'D1', 'Ordered',
77 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
78 FROM DUAL
79 UNION ALL
80 SELECT '1-249A8X', 'D1', 'RFS',
81 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
82 FROM DUAL
83 UNION ALL
84 SELECT '1-249A8X', 'D1', 'RFS',
85 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
86 FROM DUAL
87 UNION ALL
88 SELECT '1-249A8X', 'D1', 'Validated',
89 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
90 FROM DUAL
91 UNION ALL
92 SELECT '1-249A8X', 'D1', 'Validated',
93 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
94 FROM DUAL
95 UNION ALL
96 SELECT '1-249A8Z', 'COPS', 'Validated',
97 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
98 FROM DUAL
99 UNION ALL
100 SELECT '1-249A8Z', 'COPS', 'Ordered',
101 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
102 FROM DUAL)
103 select vt.quote_id,
104 vt.account,
105 vt.status,
106 vt.captured_date,
107 case when vt.rn = 1 then 'N'
108 else 'Y'
109 end deleted_flag
110 from (SELECT quote_id, ACCOUNT, status, captured_date,
111 DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id, ACCOUNT) rn
112 FROM temp
113 ORDER BY quote_id, captured_date) vt;
QUOTE_ID ACCOUNT STATUS CAPTURED_DATE DELETED_FLAG
1-11TWQL D1 Rejected 23-Dec-2009 3 Y
1-11TWQL D1 RFS 23-Dec-2009 3 Y
1-11TWQL D1 Validated 23-Dec-2009 3 Y
1-11TWQL D1 Ordered 23-Dec-2009 3 Y
1-11TWQL COPS RFS 23-Dec-2009 3 N
1-11TWQL COPS Validated 23-Dec-2009 3 N
1-11TWQL COPS Rejected 23-Dec-2009 3 N
1-11TWQL COPS Ordered 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS RFS 05-Mar-2010 1 N
1-249A8X COPS Rejected 05-Mar-2010 1 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8Z COPS Validated 26-Mar-2010 1 N
1-249A8Z COPS Ordered 26-Mar-2010 1 N
25 rows selected
SQL> -
Hi experts,
I have data like this in a table with 5000 records.
ID cid Name
1 10 Ram
1 20 Raj
2 10 Kiran
2 20 Kishor
2 30 Krishna
2 40 Karuna
2 50 Kamesh
2 50 Kumar
2 50 Kamal
2 60 Keerti
3 10 Syam
3 20 Suresh
3 30 Suman
3 40 Santosh
3 40 Sarat
3 50 Sirisha
3 60 Sumanth
4 10 Tarun
4 20 Tanish
4 30 Taman
4 40 Tomas
4 40 Teenu
5 10 Prakash
5 20 Pavan
5 30 Prasad
etc
I want the output like
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh, Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
Please help me to get the output like this
Thanks in advancewith t as (
select 1 id,10 cid,'Ram' name from dual union all
select 1,20,'Raj' from dual union all
select 2,10,'Kiran' from dual union all
select 2,20,'Kishor' from dual union all
select 2,30,'Krishna' from dual union all
select 2,40,'Karuna' from dual union all
select 2,50,'Kamesh' from dual union all
select 2,50,'Kumar' from dual union all
select 2,50,'Kamal' from dual union all
select 2,60,'Keerti' from dual union all
select 3,10,'Syam' from dual union all
select 3,20,'Suresh' from dual union all
select 3,30,'Suman' from dual union all
select 3,40,'Santosh' from dual union all
select 3,40,'Sarat' from dual union all
select 3,50,'Sirisha' from dual union all
select 3,60,'Sumanth' from dual union all
select 4,10,'Tarun' from dual union all
select 4,20,'Tanish' from dual union all
select 4,30,'Taman' from dual union all
select 4,40,'Tomas' from dual union all
select 4,40,'Teenu' from dual union all
select 5,10,'Prakash' from dual union all
select 5,20,'Pavan' from dual union all
select 5,30,'Prasad' from dual
-- end of on-the-fly data sample
select id,
rtrim(xmlagg(xmlelement(e,cid,',').extract('//text()') order by cid),',') cid,
rtrim(xmlagg(xmlelement(e,name,',').extract('//text()') order by cid),',') name
from t
group by id
order by id
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Kumar,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh,Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
SQL> SY. -
I am running the following query. This is being run for every row that is being loaded. I figured that this is taking the most time
select distinct h.PRNT_PROD_GRP_ID, h.CHILD_PROD_GRP_ID, pg.PROD_GRP_REPORTING_NM, pg.PROD_GRP_ID, pg.PROD_GRP_TYP_ID
from PROD_GRP_HCHY_OUTBD h, PROD_GRP pg
where pg.PROD_GRP_ID = h.PRNT_PROD_GRP_ID and
pg.PROD_GRP_ID in (select c.PROD_GRP_ID from prod_grp p, prod_grp c, PROD_GRP_HCHY_OUTBD hy, (select h.PRNT_PROD_GRP_ID, h.CHILD_PROD_GRP_ID, level LVLID, PROD_GRP_HCHY_OUTBD_ID from PROD_GRP_HCHY_OUTBD h where h.PROD_MKT_ID in (select pga.PROD_GRP_ID from APLCTN_SYS aps, APLCTN a, PROD_GRP_APLCTN pga where aps.APLCTN_SYS_Cd = 'ETMS' AND aps.APLCTN_SYS_ID = a.APLCTN_SYS_ID and a.APLCTN_ID = pga.APLCTN_ID) start with h.PRNT_PROD_GRP_ID in (select pga.PROD_GRP_ID from APLCTN_SYS aps, APLCTN a, PROD_GRP_APLCTN pga where aps.APLCTN_SYS_Cd = 'ETMS' AND aps.APLCTN_SYS_ID = a.APLCTN_SYS_ID and a.APLCTN_ID = pga.APLCTN_ID) connect by h.PRNT_PROD_GRP_ID = prior h.CHILD_PROD_GRP_ID) TREE where p.prod_grp_id = TREE.PRNT_PROD_GRP_ID and c.prod_grp_id = TREE.CHILD_PROD_GRP_ID and hy.PROD_GRP_HCHY_OUTBD_ID = TREE.PROD_GRP_HCHY_OUTBD_ID) connect by prior h.PRNT_PROD_GRP_ID = h.CHILD_PROD_GRP_ID start with h.CHILD_PROD_GRP_ID = 7650 order by pg.PROD_GRP_TYP_ID;hey nick,
this is the query that is run by Tibco (middleware).
we are trying to extract this data from the data store and load into a target database.
this query generates a tree of parent - child rows that belong to a particular criteria.
everytime the parent is fetched for a particular child, we need to make sure that the parent falls in that criteria and hence the many (in) queries.
hope this helps -
Please help me tuning this query...
Hi all,
Can any body suggest some changes (synthatic) so that it can improve its performance... taking too much time...
This is a query used in oracle report...
SELECT distinct cc.seg1,cc.seg2,cc.seg3,cc.seg4,cc.seg5,cc.seg6,cc.seg7,cc.seg8,cc.code_combination_id code_comb_id,
r.flex_validation_rule_name cv_rule,gl.currency_code currency1,
(NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0)) trans_amount,
gjh.doc_sequence_value doc_num,
gjs.user_je_source_name je_source, gjc.user_je_category_name je_category,
fu.user_name last_updated_by,(NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0))
+ (NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)) balance,
gjh.last_update_date last_updated_date,gjl.effective_date
FROM gl_code_combinations cc,
fnd_flex_vdation_rules_vl r,
fnd_flex_validation_rule_lines l,
gl_je_headers gjh,
gl_je_lines gjl,
gl_balances gb,
fnd_user fu,
gl_je_categories gjc,
gl_je_sources gjs,
gl_ledgers gl
WHERE cc.enabled_flag = 'Y'
AND NVL (cc.end_date_active, SYSDATE + 1) > SYSDATE
AND cc.chart_of_accounts_id = :p_chart_of_accounts_id
AND r.id_flex_num = cc.chart_of_accounts_id
AND r.id_flex_code = 'GL#'
AND r.application_id = 101
AND gjs.je_source_name=gjh.je_source
AND gjc.je_category_name=gjh.je_category
AND l.application_id = r.application_id
AND gb.code_combination_id=cc.code_combination_id
AND gjh.period_name=gb.period_name
AND r.enabled_flag = 'Y'
AND NVL (r.end_date_active, SYSDATE + 1) > SYSDATE
AND l.id_flex_code = r.id_flex_code
AND l.id_flex_num = r.id_flex_num
AND l.flex_validation_rule_name = r.flex_validation_rule_name
AND l.include_exclude_indicator = 'E'
AND gjl.code_combination_id = gb.code_combination_id
AND gjh.je_header_id = gjl.je_header_id
AND gjh.status = 'P'
AND gl.ledger_id=gjh.ledger_id
and gl.ledger_id=:p_ledger_id
AND gjh.last_updated_by = fu.user_id
and (gjh.last_update_date,gjl.last_update_date)=(
SELECT MAX (a.last_update_date) ,MAX(b.last_update_date)
FROM gl_je_headers a, gl_je_lines b
WHERE b.code_combination_id = cc.code_combination_id
AND a.je_header_id = b.je_header_id
AND a.status = 'P'
AND ROWNUM = 1)
and (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0))=(select (NVL (accounted_dr, 0) - NVL (accounted_cr, 0)) from gl_je_lines
where je_header_id=gjh.je_header_id and code_combination_id=cc.code_combination_id and period_name=gjh.period_name and
last_update_date=gjh.last_update_date and rownum=1)
and (NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0))
+ (NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0))=(select max((NVL (begin_balance_dr, 0)
- NVL (begin_balance_cr, 0))
+ (NVL (period_net_dr_beq, 0)
- NVL (period_net_cr_beq, 0))) from gl_balances where code_combination_id=cc.code_combination_id
and period_name=gb.period_name)
and gjl.description=(select description from gl_je_lines where code_combination_id=cc.code_combination_id and
je_header_id=gjh.je_header_id and period_name=gb.period_name and rownum=1)
AND cc.seg1 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 1, 3),
cc.seg1
AND NVL (SUBSTR (l.concatenated_segments_high, 1, 3),
cc.seg1
AND cc.seg2 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 5, 4),
cc.seg2
AND NVL (SUBSTR (l.concatenated_segments_high, 5, 4),
cc.seg2
AND cc.seg3 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 10, 4),
cc.segt3
AND NVL (SUBSTR (l.concatenated_segments_high, 10, 4),
cc.seg3
AND cc.seg4 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 15, 3),
cc.seg4
AND NVL (SUBSTR (l.concatenated_segments_high, 15, 3),
cc.seg4
AND cc.seg5 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 19, 6),
cc.seg5
AND NVL (SUBSTR (l.concatenated_segments_high, 19, 6),
cc.seg5
AND cc.seg6 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 26, 4),
cc.segment6
AND NVL (SUBSTR (l.concatenated_segments_high, 26, 4),
cc.seg6
AND cc.seg7 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 31, 6),
cc.seg7
AND NVL (SUBSTR (l.concatenated_segments_high, 31, 6),
cc.seg7
AND cc.seg8 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 38, 6),
cc.seg8
AND NVL (SUBSTR (l.concatenated_segments_high, 38, 6),
cc.seg8)Thanks for help
aspDear all,
the folliwing is explain plan for above query...
<ExplainPlan>
- <PlanElement object_ID="0" id="0" operation="SELECT STATEMENT" optimizer="ALL_ROWS" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="1" operation="HASH" option="UNIQUE" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="2" operation="FILTER" filter_predicates="("GJH"."LAST_UPDATE_DATE","GJL"."LAST_UPDATE_DATE")= (SELECT MAX("A"."LAST_UPDATE_DATE"),MAX("B"."LAST_UPDATE_DATE") FROM "GL"."GL_JE_LINES" "B","GL"."GL_JE_HEADERS" "A" WHERE ROWNUM=1 AND "A"."JE_HEADER_ID"="B"."JE_HEADER_ID" AND "A"."STATUS"='P' AND "B"."CODE_COMBINATION_ID"=:B1) AND NVL("GJL"."ACCOUNTED_DR",0)-NVL("GJL"."ACCOUNTED_CR",0)= (SELECT NVL("ACCOUNTED_DR",0)-NVL("ACCOUNTED_CR",0) FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B2 AND "CODE_COMBINATION_ID"=:B3 AND "JE_HEADER_ID"=:B4 AND "LAST_UPDATE_DATE"=:B5) AND NVL("GB"."BEGIN_BALANCE_DR",0)-NVL("GB"."BEGIN_BALANCE_CR",0)+(NVL("GB"."PERIOD_NET_DR_BEQ",0)-NVL("GB"."PERIOD_NET_CR_BEQ",0))= (SELECT MAX(NVL("BEGIN_BALANCE_DR",0)-NVL("BEGIN_BALANCE_CR",0)+(NVL("PERIOD_NET_DR_BEQ",0)-NVL("PERIOD_NET_CR_BEQ",0))) FROM "GL"."GL_BALANCES" "GL_BALANCES" WHERE "PERIOD_NAME"=:B6 AND "CODE_COMBINATION_ID"=:B7)">
- <PlanElements>
- <PlanElement object_ID="0" id="3" operation="NESTED LOOPS" cost="1,262" cardinality="1" bytes="477" cpu_cost="254,376,045" io_cost="1,231" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="4" operation="NESTED LOOPS" cost="1,261" cardinality="1" bytes="464" cpu_cost="254,366,853" io_cost="1,230" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="5" operation="NESTED LOOPS" cost="1,260" cardinality="1" bytes="433" cpu_cost="254,357,622" io_cost="1,229" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="6" operation="NESTED LOOPS" cost="1,259" cardinality="1" bytes="402" cpu_cost="254,348,331" io_cost="1,228" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="7" operation="NESTED LOOPS" cost="1,258" cardinality="1" bytes="350" cpu_cost="254,337,522" io_cost="1,227" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="8" operation="NESTED LOOPS" cost="1,239" cardinality="1" bytes="273" cpu_cost="254,166,811" io_cost="1,208" time="15">
- <PlanElements>
- <PlanElement object_ID="0" id="9" operation="HASH JOIN" cost="1,184" cardinality="1" bytes="248" cpu_cost="253,727,112" io_cost="1,153" access_predicates=""B"."ID_FLEX_NUM"="CC"."CHART_OF_ACCOUNTS_ID"" filter_predicates=""CC"."SEGMENT1">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT1"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT2">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT2"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT3">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT3"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT4">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT4"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT5">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT5"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT6">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT6"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT7">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT7"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT8">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",38,6),"CC"."SEGMENT8") AND "CC"."SEGMENT8"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",38,6),"CC"."SEGMENT8")" time="15">
- <PlanElements>
- <PlanElement object_ID="1" id="10" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULE_LINES" object_type="TABLE" object_instance="3" cost="3" cardinality="1" bytes="119" cpu_cost="49,909" io_cost="3" filter_predicates=""L"."INCLUDE_EXCLUDE_INDICATOR"='E'" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="11" operation="NESTED LOOPS" cost="6" cardinality="1" bytes="189" cpu_cost="75,588" io_cost="6" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="12" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="70" cpu_cost="25,679" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="13" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="39" cpu_cost="23,779" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="2" id="14" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS" object_type="TABLE" object_instance="10" cost="1" cardinality="1" bytes="8" cpu_cost="8,541" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="3" id="15" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS_U2" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,050" io_cost="0" access_predicates=""GL"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID)" time="1" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="4" id="16" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES" object_type="TABLE" object_instance="19" cost="2" cardinality="1" bytes="31" cpu_cost="15,238" io_cost="2" filter_predicates=""B"."ENABLED_FLAG"='Y' AND NVL("B"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="1">
- <PlanElements>
<PlanElement object_ID="5" id="17" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES_U1" object_type="INDEX (UNIQUE)" search_columns="3" cost="1" cardinality="1" cpu_cost="7,321" io_cost="1" access_predicates=""B"."APPLICATION_ID"=101 AND "B"."ID_FLEX_CODE"='GL#' AND "B"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID)" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
<PlanElement object_ID="6" id="18" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VDATION_RULES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="5" cost="0" cardinality="1" bytes="31" cpu_cost="1,900" io_cost="0" access_predicates=""T"."APPLICATION_ID"=101 AND "T"."ID_FLEX_CODE"='GL#' AND "T"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "B"."FLEX_VALIDATION_RULE_NAME"="T"."FLEX_VALIDATION_RULE_NAME" AND "T"."LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
<PlanElement object_ID="7" id="19" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VAL_RULE_LINES_N1" object_type="INDEX" search_columns="4" cost="1" cardinality="41" cpu_cost="16,371" io_cost="1" access_predicates=""L"."APPLICATION_ID"=101 AND "L"."ID_FLEX_CODE"='GL#' AND "L"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "L"."FLEX_VALIDATION_RULE_NAME"="B"."FLEX_VALIDATION_RULE_NAME"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
<PlanElement object_ID="8" id="20" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="GL" object_name="GL_CODE_COMBINATIONS" object_type="TABLE" object_instance="1" cost="1,177" cardinality="1,088" bytes="64,192" cpu_cost="249,419,570" io_cost="1,147" filter_predicates=""CC"."ENABLED_FLAG"='Y' AND "CC"."CHART_OF_ACCOUNTS_ID"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND NVL("CC"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="15" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="9" id="21" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="6" cost="55" cardinality="52" bytes="1,300" cpu_cost="439,699" io_cost="55" time="1">
- <PlanElements>
<PlanElement object_ID="10" id="22" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="52" cpu_cost="25,693" io_cost="2" access_predicates=""GB"."CODE_COMBINATION_ID"="CC"."CODE_COMBINATION_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="11" id="23" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="5" cost="19" cardinality="40" bytes="3,080" cpu_cost="170,710" io_cost="19" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="24" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="49" cpu_cost="24,693" io_cost="2" access_predicates=""GJL"."CODE_COMBINATION_ID"="GB"."CODE_COMBINATION_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="13" id="25" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="4" cost="1" cardinality="1" bytes="52" cpu_cost="10,809" io_cost="1" filter_predicates=""GJH"."STATUS"='P' AND "GJH"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID) AND "GJH"."PERIOD_NAME"="GB"."PERIOD_NAME"" time="1">
- <PlanElements>
- <PlanElement object_ID="14" id="26" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,950" io_cost="0" access_predicates=""GJH"."JE_HEADER_ID"="GJL"."JE_HEADER_ID"" filter_predicates=""GJL"."DESCRIPTION"= (SELECT "DESCRIPTION" FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B1 AND "CODE_COMBINATION_ID"=:B2 AND "JE_HEADER_ID"=:B3)" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="27" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="28" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="15" cost="5" cardinality="1" bytes="62" cpu_cost="39,168" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="29" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="15" id="30" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL" object_type="TABLE" object_instance="16" cost="1" cardinality="2" bytes="62" cpu_cost="9,291" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="16" id="31" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_SOURCE_NAME"="GJH"."JE_SOURCE" AND "LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="17" id="32" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL" object_type="TABLE" object_instance="17" cost="1" cardinality="2" bytes="62" cpu_cost="9,231" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="18" id="33" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_CATEGORY_NAME"="GJH"."JE_CATEGORY" AND "LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="19" id="34" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER" object_type="TABLE" object_instance="7" cost="1" cardinality="1" bytes="13" cpu_cost="9,191" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="20" id="35" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""GJH"."LAST_UPDATED_BY"="FU"."USER_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="36" operation="SORT" option="AGGREGATE" cardinality="1" bytes="33">
- <PlanElements>
- <PlanElement object_ID="0" id="37" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="0" id="38" operation="NESTED LOOPS" cost="69" cardinality="49" bytes="1,617" cpu_cost="624,699" io_cost="69" time="1">
- <PlanElements>
- <PlanElement object_ID="11" id="39" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="12" cost="20" cardinality="49" bytes="882" cpu_cost="164,029" io_cost="20" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="40" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="3" cardinality="49" cpu_cost="30,964" io_cost="3" access_predicates=""B"."CODE_COMBINATION_ID"=:B1" time="1" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="13" id="41" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="11" cost="1" cardinality="1" bytes="15" cpu_cost="9,401" io_cost="1" filter_predicates=""A"."STATUS"='P'" time="1">
- <PlanElements>
<PlanElement object_ID="14" id="42" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""A"."JE_HEADER_ID"="B"."JE_HEADER_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="43" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="44" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="13" cost="5" cardinality="1" bytes="33" cpu_cost="39,068" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1 AND "LAST_UPDATE_DATE"=:B2" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="45" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="46" operation="SORT" option="AGGREGATE" cardinality="1" bytes="25">
- <PlanElements>
- <PlanElement object_ID="9" id="47" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="14" cost="6" cardinality="1" bytes="25" cpu_cost="45,399" io_cost="6" time="1">
- <PlanElements>
<PlanElement object_ID="10" id="48" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="2" cpu_cost="21,964" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</ExplainPlan>Sorry this xml generated...
Regards
asp -
Please help me getting this query in MDX
Select CASE WHEN DSL.Latest_Label IS NULL THEN DS.[Label] ELSE DSL.Latest_Label END AS Label From Dim_Label AS DS LEFT OUTER JOIN
(Select Idx,GRP_Idx,Max(Latest_Label) Latest_Label,MAX(Date_ID) Date_ID from [Dim_Label_Change] DSL te_Day = DSL.Date_Effective Where (Date_Id <= 333 ) Group by idx,GRP_Idx)
DSL ON DS.Idx = DSL.Idx
Thanks in Advance for the helpMy Cube has Dimensions, Fact tables and Measures , and Dimension table consists of Main and History table(Type 2 Slowly Changing Dimension).
I would like to display the History(Latest_Label) Name based on the date selected on SSRS Report.
Hi SKPSR,
According to your description, you need to get the latest history name based on a date that selected by use in SSRS report, right?
In SSAS, we can use the LastNonEmpty function or Tail function to get the last member from a set. We cannot give you the detail MDX query based on the limited information, you can refer to the links below to see the details.
http://msdn.microsoft.com/en-us/library/ms146056.aspx
http://thinknook.com/ssas-lastnonempty-aggregation-function-2012-08-18/
If the issue persists, please provide us more information about your cube structure, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support -
Please help me tune this program,
Hi.
I have a item master data table and a transaction table.
For a given criteria I have to find items from master data table which do no exits in transaction table.
I have listed my flow below, can you please advice if there is any other optimal way of doing it.
1. For the given criteria read items from master data table into internal table 1. Sort the internal table 1.
2. For the given criteria read items from transaction table into internal table 2. Sort and remove duplicates from the internal table 2.
3. Loop at internal table 1, and check if item exists in internal table 2. Append items not in internal table 2 into another internal table 3.
At the end internal table 3 will have the items I am interested in. I can sort and use binary search addition, but is there any other efficient way of doing this task.
Thank you,
CDDon't use standard tables !!!!!!! They are o.k. in old coding in new coding you should
use only sorted and hashed tables and performance works automatically !!!
Forget about sorting and deleting duplicates !
> remove duplicates from the internal table 2.
use a hashed table with a unique key and collect you entries in the hash table,
Use sorted tables if the key is non-unique, or if the need also parts of the key!
Use hashed tables if the key must be unique.
Even for the append it is possible to APPEND into a sorted table, the records must come in a sort
order, i.e. if they come from a sorted table then it is o.k.
What I write is not imagination but the only really commendable way of handling internal tables.
Siegfried -
Please help me optimize this query
Hi,
Can you’ll please recommend me if there is any way to optimize the SQL statement below.
I have 3 tables:
item_master: contains master list of items
item_rentout: items currently out on rent
item_missing: items having special status like missing, withdrawn and so on.
I want to find items that are currently available.
Which is items in table item_master –(minus) items in table item_rentout –(minus) items in table in item_missing.
This is how my sql statement is:
select item_master.item_id from item_master where item_master.item_id not in
((select item_id from item_rentout) union (select item_id from item_missing where status in (‘missing’,withdrawn’)))Regards,
RajaIn addition to what Pointless posted (which is very valuable information!) you could always try and write a logical equivalent SQL statement. It may generate a more favorable plan.
I have written the following that I think may work but they are untested:
SELECT ITEM_MASTER.ITEM_ID FROM ITEM_MASTER
MINUS
SELECT ITEM_ID FROM ITEM_RENTOUT
MINUS
SELECT ITEM_ID FROM ITEM_MISSING WHERE STATUS IN ('missing','withdrawn')
SELECT item_master.item_id
FROM ITEM_MASTER IM
WHERE NOT EXISTS
SELECT NULL
FROM ITEM_RENTOUT IR
WHERE IR.ITEM_ID = IM.ITEM_ID
AND NOT EXISTS
SELECT NULL
FROM ITEM_MISSING IIM
WHERE IIM.ITEM_ID = IM.ITEM_ID
)
Maybe you are looking for
-
The client is a pure-Java client, how to invoke session bean in oc4j server
I WOULD LIKE TO INVOKE MY SESSION BEAN FROM MY STRUT WEB PROJECT AS A PURE JAVA CLIENT . I SETUP THE JNDI INITIAL CONTEXT PROPERTY BUT I HAVE NO IDEA TO WHERE I SHALL PUT MY application-client.xml and orion-application-client.xml. MY APPLICATION THRO
-
Noise when using NVIDIA HDMI output
Trying to use audio over HDMI output on an NVIDIA GTX580, using nvidia 331.38, results in the audio transmitted with a large amount of noise on top of it. I'm not sure quite what is helpful to say here, though. Just using ALSA, no PulseAudio or anyth
-
hi, i am using 2 stacked canvas on a same window. they are one above the other. but a black colored border is displayed around both of them as it is showing the viewport. background color is gray. i want to remove that border. or if possible then cha
-
How to get module wise custom objects
Hi , How to get all the list of custom objects ( Eg : zreports, ztransactions, zscripts, zsmartforms,zwebdynpro components ..... ) and how to segregate them which module wise ( FI / MM / SD .... ) I am using Tadir for getting the custom objects. Plea
-
Dispute Management Partial Payment
Dear All We have created a dispute case and later record the partial payment but system does not give any message that Express Document Subsequent update for the case XX received from author. I test the same in Ides and getting the above message. Any