Cartesian Product in Select

    Hi all!
I need help.
I have this function that launches a Select. My Oracle Grid tells me, when I tune the Select of this function, that there is a Cartesian Product. I understand what a Cartesian Product is, but I fail to find it. Can you help me by pointing out WHERE is the misteke? Thank you!!
P.s. Oracle EE 10.2.0.4 on windows Server 2003 R2 SP2 64Bit
[code]
create or replace
FUNCTION          "ANA_GETVERBALE"
  v_VerbaleId      IN NUMBER DEFAULT NULL,
  v_Sezione        IN VARCHAR2 DEFAULT NULL,
  v_NumeroVerbale  IN VARCHAR2 DEFAULT NULL,
  v_DataVerbale    IN DATE DEFAULT NULL,
  v_TargaVeicolo   IN VARCHAR2 DEFAULT NULL,
  v_Serie          IN VARCHAR2 DEFAULT NULL,
  v_LoggedUser IN VARCHAR2 DEFAULT NULL
RETURN SYS_REFCURSOR
AS
   cv_1 SYS_REFCURSOR;
BEGIN
  OPEN cv_1 FOR
    SELECT
      ANA_M.VerbaleId,
      ANA_M.Sezione,
      ANA_M.NumeroVerbale,
      ANA_M.DataVerbale,
      ANA_M.TargaVeicolo,
      ANA_M.Serie,
      SCH_C.StatoCartellinoId,
      LOV_StatoCartellino.ListOfValueName StatoCartellino,
      sch_c.cartellinoid
    FROM ANA_Materia_Verbale ANA_M
    INNER JOIN SCH_Cartellini SCH_C ON SCH_C.SoggettoId=ana_m.verbaleid AND SCH_C.TipoSoggettoId = SIS_CONSTANTS_PKG.VB
    INNER JOIN SIC_PROFILO_STATO SIC_PSC ON SIC_PSC.STATOID=SCH_C.STATOCARTELLINOID
    INNER JOIN SIC_PROFILI_USERS SIC_PUC ON SIC_PUC.PROFILOID=SIC_PSC.PROFILOID AND SIC_PUC.PERSONALID=v_LoggedUser
    LEFT JOIN TYP_ListOfValues LOV_StatoCartellino  ON LOV_StatoCartellino.ListOfValueId = SCH_C.StatoCartellinoId
    WHERE ( v_VerbaleId = SIS_CONSTANTS_PKG.AnyBigint OR ANA_M.VerbaleId = v_VerbaleId )
      AND ( v_Sezione = SIS_CONSTANTS_PKG.AnyString OR REGEXP_LIKE(ANA_M.Sezione, '^' || v_Sezione || '$', 'i') )
      AND ( v_serie = SIS_CONSTANTS_PKG.AnyString OR REGEXP_LIKE(ANA_M.Serie, '^' || v_Serie || '$', 'i') )
      AND ( v_NumeroVerbale = SIS_CONSTANTS_PKG.AnyString OR ANA_M.NumeroVerbale = v_NumeroVerbale )
      AND ( v_DataVerbale = SIS_CONSTANTS_PKG.AnyDateTime OR ANA_M.DataVerbale = v_DataVerbale )
      AND ( v_TargaVeicolo = SIS_CONSTANTS_PKG.AnyString OR REGEXP_LIKE(ANA_M.TargaVeicolo,'^' || v_TargaVeicolo || '$', 'i') );
  RETURN cv_1;
END;
[/code]

....ouch... well that explains a LOT!! The real problem was the Oracle Grid SQL_TUNING that warned me that the SELECT contained a CARTESIAN PRODUCT:
Ristruttura SQL
An expensive cartesian product operation was found at line ID 4 of the execution plan.
Consider removing the disconnected table or view from this statement or add a join condition which refers to it.
A cartesian product should be avoided whenever possible because it is an expensive operation and might produce a large amount of data.
with this EXECUTION PLAN:
Operazione
ID riga
Oggetto
Object type
Ordine
Righe
Dimensione (KB)
Costo
Tempo (sec)
Costo CPU
Costo I/O
SELECT STATEMENT
0
13
1
0,091
460
6
116.852.560
452
NESTED LOOPS OUTER
1
12
1
0,091
460
6
116.852.560
452
NESTED LOOPS
2
9
1
0,079
459
6
116.843.328
451
NESTED LOOPS
3
7
2
0,141
457
6
116.826.984
449
MERGE JOIN CARTESIAN
4
4
2
0,102
451
6
116.781.136
443
INDEX FAST FULL SCAN
5
DOCARK.PK_SIC_PROFILI_USERS
INDEX (UNIQUE)
1
1
0,010
2
1
81.903
2
BUFFER SORT
6
3
2
0,082
449
6
116.699.232
441
TABLE ACCESS FULL
7
DOCARK.ANA_MATERIA_VERBALE
TABLE
2
2
0,082
449
6
116.699.232
441
TABLE ACCESS BY INDEX ROWID
8
DOCARK.SCH_CARTELLINI
TABLE
6
1
0,020
3
1
22.924
3
INDEX RANGE SCAN
9
DOCARK.IDX_SCH_CARTELLINI_SOG_TIPO
INDEX
5
1
2
1
15.493
2
INDEX RANGE SCAN
10
DOCARK.PK_SIC_PROFILO_STATO
INDEX (UNIQUE)
8
1
0,009
1
1
8.171
1
TABLE ACCESS BY INDEX ROWID
11
DOCARK.TYP_LISTOFVALUES
TABLE
11
1
0,012
1
1
9.231
1
INDEX UNIQUE SCAN
12
DOCARK.PK_TYP_LISTOFVALUES
INDEX (UNIQUE)
10
1
0
1
1.900
0
So I started trying to REMOVE the Cartesian Product. But first I had to find it! So apparently I shouldn't worry too much...
The real problem is that I have to work with funtions and DBs created by others, so I am not sure what to expect from most of the Functions. Apparently this execution is correct no matter what that the Tunig Advisor says!
Thanks!

Similar Messages

  • Best performance in a cartesian product

    i've got a select that needs a cartesian product.
    ex:
    SELECT NVL(a.year,cp.year) year, NVL(a.month,cp.month), NVL(a.value,0) value
    FROM
    (select year, month from year, month) cp, values a
    WHERE cp.year = a.year(+) AND cp.month = a.month(+)
    i have to show all records possible even if they don't have any values on the table.
    In the beginning with fewer values, it ran OK.... but now with a lot more it begins to take a little longer (about 10 times longer).
    What is the best way to improve this kind of selects???
    Thank you.

    Best Case :
    No one shold be in red color in analysis is the best runtime.
    All should be in Green.
    or
    OK Case :
    Database level - Red is not acceptable
    ABAP Level - Red can be accepted and can be a good runtime.
    System Level - Red is not acceptable.
    Worst Case:
    All are in Red Color

  • Query resulting in cartesian product-plz help

    select count(distinct e.hiredate),count(distinct b.hiredate) from scott.emp e, scott.emp b where e.hiredate<to_date('01-DEC-80','DD-MON-YY') and b.hiredate<to_date('23-JUN-81','DD-MON-YY')

    Hi,
    When I query it individually its giving me as below and its correct.
    SQL> select count(hiredate) from scott.emp where hiredate<'01-DEC-81';
    COUNT(HIREDATE)
    9
    SQL> select count(hiredate) from scott.emp where hiredate<'23-JUN-81';
    COUNT(HIREDATE)
    6
    Now I want these two merged in same query and it should give me the same result
    SQL> select count(distinct e.hiredate),count(distinct b.hiredate) from scott.emp
    e, scott.emp b where e.hiredate<'01-DEC-80' and b.hiredate<'23-JUN-81';
    COUNT(DISTINCTE.HIREDATE) COUNT(DISTINCTB.HIREDATE)
    0 0
    But its giving me either cartesian product or the result above.
    I have already used logical operator AND .

  • Urgent plz help me out about cartesian product

    plz...its urgent,can anyone help in the following query where iam getting cartesian product,so how to get result without cartesian product
    this is the query
    SELECT DISTINCT MIS.segment1 "ITEM CODE",
    MIS.DESCRIPTION "DESCRIP"
    ,MIS.Primary_uom_code "UOM",
    MTL.LOT_NUMBER "LOT NUMBER"
    ,A.PARTY_NUMBER "CUSTOMER NUMBER",
    A.PARTY_NAME "CUSTOMER NAME",
    (A.ADDRESS1||A.ADDRESS2||A.ADDRESS3||A.ADDRESS4) "SHIP TO",
    B.DELIVERY_DETAIL_ID "DO NO",B.SHIPPED_QUANTITY "SHIPPED QUANTITY"
    ,C.ULTIMATE_DROPOFF_DATE "ISSUED DATE"
    ,D.ORDER_NUMBER "SALES ORDER NUMBER"
    ,E.LINE_NUMBER "SALES ORDER LINE"
    FROM MTL_SYSTEM_ITEMS MIS
    ,MTL_TRANSACTION_LOT_NUMBERS MTL
    ,HZ_PARTIES A,
    WSH_DELIVERY_DETAILS B,
    WSH_NEW_DELIVERIES C,
    OE_ORDER_HEADERS_ALL D,
    OE_ORDER_LINES_ALL E
    WHERE MIS.INVENTORY_ITEM_ID=MTL.INVENTORY_ITEM_ID
    AND B.INVENTORY_ITEM_ID=MIS.INVENTORY_ITEM_ID
    AND A.PARTY_ID=B.CUSTOMER_ID
    AND B.DELIVERY_DETAIL_ID=C.DELIVERY_ID
    AND MIS.INVENTORY_ITEM_ID=E.INVENTORY_ITEM_ID
    AND D.HEADER_ID=E.HEADER_ID

    A lot of times when I get duplicate results, I'll do a select * and see why. Often one of those tables will have a sequenced value that could repeat several times for a combination of values.
    If thats the case, you may need to add something like:
    ...and a.id = (select min(id)
                     from b
                    where a.col = b.col)

  • Query having cartesian product

    hi
    i have the following query
    select f.item_number, case when f.item_number='1020101002' then f.calc_cement_sk else f.calc_amount end act
                from XXNP_OPN_JOBLOG_EST_002 F WHERE f.OPN_JOBLOG_001_ID ='6369'
    output
    ITEM_NUMBER     ACT
    1020101001     NULL
    1020111001     NULL
    1020112001     NULL
    1020113004     NULL
    1020101002     494
    1020102007     232
    1020103004     37
    1020104004     557
    1020106002     20896
    1020111001     5
    1020112005     16253
    1020112008     46
    1020113004     40
    1020222010     1393
    ie 14 rows
    another query
    SELECT J.ITEM_NUMBER,j.opn_value  FROM XXNP_OPN_JOBLOG_RES_005 J  WHERE  J.OPN_JOBLOG_001_ID ='6369' 
    output
    ITEM_NUMBER     OPN_VALUE
    1010101003     1
    1010101004     3
    1010101005     2
    1010104016     1
    1010103001     76
    1010103002     228
    1010106001     2
    1010106006     147
    1010107010     1
    1010109009     1
    1010107015     866
    1010107014     799
    1010107016     1631
    ie 13 rows
    when i do
    select f.item_number, case when f.item_number='1020101002' then f.calc_cement_sk else f.calc_amount end act ,j.opn_value
           from XXNP_OPN_JOBLOG_EST_002 F ,XXNP_OPN_JOBLOG_RES_005 J   where   f.OPN_JOBLOG_001_ID = J.OPN_JOBLOG_001_ID and f.OPN_JOBLOG_001_ID ='6369'
    i get 182 rows :( i know its due to cartesian product
    is there any way i can get 27 rows  only ,can i get the output in the format given below
    ITEM_NUMBER     ACT                  opn_value
    1020101001     NULL
    1020111001     NULL
    1020112001     NULL
    1020113004     NULL
    1020101002     494
    1020102007     232
    1020103004     37
    1020104004     557
    1020106002     20896
    1020111001     5
    1020112005     16253
    1020112008     46
    1020113004     40
    1020222010     1393
    1010101003                                                                     1                                                    
    1010101004                                                                     3                                                              
    1010101005                                                                      2
    1010104016                                                                      1
    1010103001                                                                     76
    1010103002                                                                      228
    1010106001                                                                      2
    1010106006                                                                     147
    1010107010                                                                      1
    1010109009                                                                        1
    1010107015                                                                      866
    1010107014                                                                      791
    1010107016                                                                    1631kindly guide
    thanking in advance
    Edited by: makdutakdu on Mar 31, 2011 8:03 AM

    hi
    script for XXNP_OPN_JOBLOG_RES_005
    CREATE TABLE XXNP_OPN_JOBLOG_RES_005
      OPN_JOBLOG_005_ID  NUMBER,
      OPN_JOBLOG_001_ID  NUMBER,
      WIP_ENTITY_ID      NUMBER,
      WIP_ENTITY_NAME    VARCHAR2(240 BYTE),
      OPN_RESOURCE_CODE  VARCHAR2(30 BYTE),
      OPN_UOM_CODE       VARCHAR2(30 BYTE),
      OPN_VALUE          NUMBER,
      OPN_MOV_DATE       DATE,
      ORG_ID             NUMBER(15),
      CREATION_DATE      DATE,
      CREATED_BY         NUMBER(15),
      LAST_UPDATE_DATE   DATE,
      LAST_UPDATED_BY    NUMBER(15),
      LAST_UPDATE_LOGIN  NUMBER(15),
      OPN_RESOURCE_DESC  VARCHAR2(500 BYTE),
      ITEM_PRICE         NUMBER,
      ITEM_NUMBER        NUMBER(10),
      DIS_PER            NUMBER(3),
      EST_VALUE          NUMBER(15,3),
      VAL_ESTAB          NUMBER(15,3)
    script for XXNP_OPN_JOBLOG_EST_002
    CREATE TABLE XXNP_OPN_JOBLOG_EST_002
      OPN_JOBLOG_002_ID   NUMBER,
      OPN_JOBLOG_007_ID   NUMBER,
      INVENTORY_ITEM_ID   NUMBER,
      ITEM_NUMBER         VARCHAR2(20 BYTE),
      ITEM_NAME           VARCHAR2(40 BYTE),
      ITEM_UOM            VARCHAR2(30 BYTE),
      ITEM_VALUE          NUMBER,
      ITEM_PERCENT        NUMBER,
      OPN_AMOUNT          NUMBER,
      ITEM_CEMENT_SK      NUMBER,
      ORG_ID              NUMBER(15),
      CREATION_DATE       DATE,
      CREATED_BY          NUMBER(15),
      LAST_UPDATE_DATE    DATE,
      LAST_UPDATED_BY     NUMBER(15),
      LAST_UPDATE_LOGIN   NUMBER(15),
      OPN_JOBLOG_001_ID   NUMBER,
      OPN_JOBLOG_006_ID   NUMBER,
      ITEM_REF            NUMBER,
      DESCRIPTION         VARCHAR2(500 BYTE),
      CALC_AMOUNT         NUMBER,
      CALC_CEMENT_SK      NUMBER,
      )

  • Cartesian Product from in-line queries

    I have the following query:
    SELECT AUDIT_MONTH, AUDITS, DEFECTS
    FROM
    select distinct(to_char(AUDIT_DATE,'MM/YY')) as AUDIT_MONTH
    from v_safety_audit_records
    select count(distinct(AUDIT_ID)) AUDITS
    from v_safety_audit_records
    group by to_char(AUDIT_DATE,'MM/YY')
    select count(KEY_ID) DEFECTS
    from v_safety_audit_records
    where SUBAREA_ID NOT LIKE '_98'
    and SUBAREA_ID NOT LIKE '_99'
    group by to_char(AUDIT_DATE,'MM/YY')
    but it keeps giving me a cartesian product. Is there a way to re-write this so that I only get the month, the number of audits, and number of defects on a line rather than number of months x number of months worth of lines? I can't seem to get the join conditions worked out... I can re-write this all using views, but as it is for a single report, I'd rather not bother with more views if I can avoid it.
    Thanks in advance.

    The problem is that the query doesn't return a single row and isn't meant to. I tried:
    SELECT
    select distinct(to_char(AUDIT_DATE,'MM/YY'))
    from v_safety_audit_records
    group by to_char(AUDIT_DATE,'MM/YY')
    ) AUDIT_MONTH,
    select count(distinct(AUDIT_ID))
    from v_safety_audit_records
    group by to_char(AUDIT_DATE,'MM/YY')
    ) AUDITS,
    select count(KEY_ID)
    from v_safety_audit_records
    where SUBAREA_ID NOT LIKE '_98'
    and SUBAREA_ID NOT LIKE '_99'
    group by to_char(AUDIT_DATE,'MM/YY')
    ) DEFECTS
    FROM DUAL;
    and got "ORA-01427: single-row subquery returns more than one row". It would be a good idea if I only needed it for one month, however.

  • Avoiding Cartesian Products

    Hi All
    I have an SQL query that is taking a long time to run or will crash due the structure.
    I'm querying 20 fields that are sourced from 4 tables.
    Usng SQL developer, I'm given the info that the query creates 3 or 4 cartesian products.
    The basic structure is as follows, EXAMPLE ONLY;
    SELECT CUSTOMERS, PLACE, VALUE, DDATE, PHONE_NUMBER
    FROM CUSTOMERS C, PLACE P, VALUE V, DDATE D, PHONE DETAILS N
    WHERE C.ADDRESS = P.ADDRESS
    AND D.DATE BETWEEN TO_DATE ('08/06/09' , 'DD/MM/YY')
    AND TO_DATE ('10/06/09' , 'DD/MM/YY')
    OR N.PHONE_DETAILS = C.PHONE_NUMBER
    I need to rewrite this to run more quickly & may have to completely change the query structure.
    If anyone has had the same issue & a fix I'd appreciate it. Thanks

    Hi Sanjay
    here's the query
    SELECT DISTINCT DECODE(SOURCE_SYSTEM, 'S', CONCAT('SR ', SR_NUMBER), SR_NUMBER) AS S.SR_NUMBER, S.SOURCE_SYSTEM, S.SR_AREA, S.SR_SUB_AREA, S.SR_STATUS, S.SR_SUB_STATUS, S.SR_CLOSED_DATE, S.SR_PRODUCT1, S.SR_PRODUCT2,S.SR_OWNER, S.SR_SERVICE_ID, S.SR_REASON1, S.SR_REASON2, S.SR_TIO_PRIORITY, S.SR_REF_NUMBER, S.SR_REF_NUMBER_TYPE, S.SR_DATE_RECD, S.SR_CIDN, S.SR_BUS_UNIT, S.SR_MBM_SEG, S.SR_BILL_ACCT_NUMBER, S.LATEST_UPDATE, C.BEFORE_CLEANSING, C.AFTER_CLEANSING, P.DEALING, P.SERVICE_ID, P.PDATE, P.DISPUTED_AMOUNT, P.ISSUE_1, P.ISSUE_2, P.ISSUE_3
    FROM SR_MERGED_DATA S, PL2_WE_050609 P, CLEANSED_TIO_REF_IDS C, PL2_UNLOC_090609 L
    WHERE S.SR_AREA = 'Issues'
    AND (L.PSR_NUMBER = S.SR_NUMBER)
    OR (P.SERVICE_ID = S.SR_SERVICE_ID
    AND SR_DATE_RECD BETWEEN TO_DATE('01/05/09','DD/MM/YY')
    AND TO_DATE('09/06/09', 'DD/MM/YY'))
    I think you may have answered my question.
    Should I try the same syntax as you have written it instead?

  • Cartesian product (sum function on 2 tables)

    Dear all,
    I have 2 tables with columns student_no (foreign key), date and amount in both tables.
    now I want to select the sum of the amount for a student for specific date.
    the following query is from stu_fee_payment table.
    select sum(sfp.amount)
    from stu_fee_payment sfp
    where student_no =1
    and sfp.pay_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    result: 200
    the following query is from stu_fee_adjustment table.
    select sum(sfa.adj_amount)
    from stu_fee_adjustment sfa
    where student_no =1
    and sfa.adj_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    result: 400
    now I have the following query
    select sum(sfp.amount), sum(sfa.adj_amount)
    from stu_fee_payment sfp, stu_fee_adjustment sfa
    where sfp.student_no = sfa.student_no
    and sfp.student_no =1
    and sfp.pay_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    and sfa.adj_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    result: 400 400
    its some kind of cartesian product because the two tables have no primary foreign key relationship.
    how to solve the problem?
    Regards:
    MN
    Edited by: Muhammad Nadeem on Aug 22, 2010 11:55 PM
    Edited by: Muhammad Nadeem on Aug 23, 2010 12:58 AM

    Hi Nadeem,
    Try this one
    SELECT sfp_sno,sfp_amount,sfa_amount
    FROM
    SELECT sfp.student_no sfp_sno, SUM(sfp.amount) sfp_amount
    FROM stu_fee_payment sfp
    WHERE sfp.pay_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    GROUP BY sfp.student_no
    ) x,
    SELECT sfa.student_no sfa_sno, SUM(sfa.adj_amount) sfa_amount
    FROM stu_fee_adjustment sfa
    WHERE sfa.adj_date < TO_DATE('01-AUG-2010','DD-MON-YYYY')
    GROUP BY sfa.student_no
    )y
    WHERE sfp_sno = sfp_no(+) Regards,
    Sreekanth Munagala.

  • Ora 00918 normalizing problem using cartesian product

    I am using a cartesian product to normalise a table. Is there a better way of doing this to avoid the 00918 error?
    Thanks in advance ...
    select
    /* select clause */
    from
    z_dvo_proj_milestone_summary t1,
    z_dvo_proj_milestone_summary t2
    where
    /* where clause */
    create or replace view z_dvo_proj_milestone_summary as
    select
    query1.projid
    ,query1.projname
    ,query1.projtype
    ,query1.projcode
    ,query1.report_month
    ,query1.report_year
    ,query1.SubProjID
    ,query1.DVONUM
    ,query1.measure_type
    ,query1.MEASURE
    ,hier.level0_vosa_prj_type
    from
    (select
    score.project as projid
    ,srm.name as projname
    ,hier.level0_vosa_prj_type as projtype
    ,score.code as projcode
    ,score.report_month as report_month
    ,score.report_year as report_year
    ,CASE
    when (subprojtab.subprojid = 1) then score.sub_project_1
    when (subprojtab.subprojid = 2) then score.sub_project_2
    End as SubProjID
    ,dvonumtab.dvonum as DVONUM
    ,typetab.measure_type as measure_Type
    ,CASE
    WHEN (subprojtab.subprojid = 1) then
    CASE
    when typetab.measure_type = 'baseline' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj1_dvo1_baseline
    when (dvonumtab.dvonum = 2) then score.proj1_dvo2_baseline
    End
    when typetab.measure_type = 'planned' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj1_dvo1_planned
    when (dvonumtab.dvonum = 2) then score.proj1_dvo2_planned
    End
    End
    WHEN (subprojtab.subprojid = 2) then
    CASE
    when typetab.measure_type = 'baseline' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj2_dvo1_baseline
    when (dvonumtab.dvonum = 2) then score.proj2_dvo2_baseline
    End
    when typetab.measure_type = 'planned' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj2_dvo1_planned
    when (dvonumtab.dvonum = 2) then score.proj2_dvo2_planned
    End
    End
    End as MEASURE
    from
    ODF_CA_PROJSCORE score
    left outer join
    srm_projects srm on (srm.id = score.project)
    left outer join
    Z_PROJECT_HIERARCHY hier on (srm.id = hier.level0)
    Join
    (select 1 as subprojid from dual
    union
    select 2 as subprojid from dual) subprojtab on (1=1)
    /* There will be 11 measures here eventually */
    Join
    (select 'baseline' as measure_type from dual
    union
    select 'planned' as measure_type from dual) typetab on (1=1)
    Join
    (select 1 as dvonum from dual
    union
    select 2 as dvonum from dual) dvonumtab on (1=1)
    WHERE
    (CASE
    when (subprojtab.subprojid = 1) then score.sub_project_1
    when (subprojtab.subprojid = 2) then score.sub_project_2
    End) IS NOT NULL) query1
    left outer join Z_PROJECT_HIERARCHY hier
    on (query1.SubProjID = hier.level0)

    I am using a cartesian product to normalise a table. Is there a better way of doing this to avoid the 00918 error?
    Thanks in advance ...
    select
    /* select clause */
    from
    z_dvo_proj_milestone_summary t1,
    z_dvo_proj_milestone_summary t2
    where
    /* where clause */
    create or replace view z_dvo_proj_milestone_summary as
    select
    query1.projid
    ,query1.projname
    ,query1.projtype
    ,query1.projcode
    ,query1.report_month
    ,query1.report_year
    ,query1.SubProjID
    ,query1.DVONUM
    ,query1.measure_type
    ,query1.MEASURE
    ,hier.level0_vosa_prj_type
    from
    (select
    score.project as projid
    ,srm.name as projname
    ,hier.level0_vosa_prj_type as projtype
    ,score.code as projcode
    ,score.report_month as report_month
    ,score.report_year as report_year
    ,CASE
    when (subprojtab.subprojid = 1) then score.sub_project_1
    when (subprojtab.subprojid = 2) then score.sub_project_2
    End as SubProjID
    ,dvonumtab.dvonum as DVONUM
    ,typetab.measure_type as measure_Type
    ,CASE
    WHEN (subprojtab.subprojid = 1) then
    CASE
    when typetab.measure_type = 'baseline' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj1_dvo1_baseline
    when (dvonumtab.dvonum = 2) then score.proj1_dvo2_baseline
    End
    when typetab.measure_type = 'planned' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj1_dvo1_planned
    when (dvonumtab.dvonum = 2) then score.proj1_dvo2_planned
    End
    End
    WHEN (subprojtab.subprojid = 2) then
    CASE
    when typetab.measure_type = 'baseline' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj2_dvo1_baseline
    when (dvonumtab.dvonum = 2) then score.proj2_dvo2_baseline
    End
    when typetab.measure_type = 'planned' then
    CASE
    when (dvonumtab.dvonum = 1) then score.proj2_dvo1_planned
    when (dvonumtab.dvonum = 2) then score.proj2_dvo2_planned
    End
    End
    End as MEASURE
    from
    ODF_CA_PROJSCORE score
    left outer join
    srm_projects srm on (srm.id = score.project)
    left outer join
    Z_PROJECT_HIERARCHY hier on (srm.id = hier.level0)
    Join
    (select 1 as subprojid from dual
    union
    select 2 as subprojid from dual) subprojtab on (1=1)
    /* There will be 11 measures here eventually */
    Join
    (select 'baseline' as measure_type from dual
    union
    select 'planned' as measure_type from dual) typetab on (1=1)
    Join
    (select 1 as dvonum from dual
    union
    select 2 as dvonum from dual) dvonumtab on (1=1)
    WHERE
    (CASE
    when (subprojtab.subprojid = 1) then score.sub_project_1
    when (subprojtab.subprojid = 2) then score.sub_project_2
    End) IS NOT NULL) query1
    left outer join Z_PROJECT_HIERARCHY hier
    on (query1.SubProjID = hier.level0)

  • Getting cartesian product

    can anyone help in the following query where iam getting cartesian product,so how to get result without cartesian product
    this is the query
    SELECT DISTINCT MIS.segment1 "ITEM CODE",
    MIS.DESCRIPTION "DESCRIP"
    ,MIS.Primary_uom_code "UOM",
    MTL.LOT_NUMBER "LOT NUMBER"
    ,A.PARTY_NUMBER "CUSTOMER NUMBER",
    A.PARTY_NAME "CUSTOMER NAME",
    (A.ADDRESS1||A.ADDRESS2||A.ADDRESS3||A.ADDRESS4) "SHIP TO",
    B.DELIVERY_DETAIL_ID "DO NO",B.SHIPPED_QUANTITY "SHIPPED QUANTITY"
    ,C.ULTIMATE_DROPOFF_DATE "ISSUED DATE"
    ,D.ORDER_NUMBER "SALES ORDER NUMBER"
    ,E.LINE_NUMBER "SALES ORDER LINE"
    FROM MTL_SYSTEM_ITEMS MIS
    ,MTL_TRANSACTION_LOT_NUMBERS MTL
         ,HZ_PARTIES A,
         WSH_DELIVERY_DETAILS B,
         WSH_NEW_DELIVERIES C,
         OE_ORDER_HEADERS_ALL D,
         OE_ORDER_LINES_ALL E
    WHERE MIS.INVENTORY_ITEM_ID=MTL.INVENTORY_ITEM_ID
    AND B.INVENTORY_ITEM_ID=MIS.INVENTORY_ITEM_ID
    AND A.PARTY_ID=B.CUSTOMER_ID
    AND B.DELIVERY_DETAIL_ID=C.DELIVERY_ID
    AND MIS.INVENTORY_ITEM_ID=E.INVENTORY_ITEM_ID
    AND D.HEADER_ID=E.HEADER_ID

    SELECT DISTINCT MIS.segment1 "ITEM CODE",
                    MIS.DESCRIPTION "DESCRIP"
                    ,MIS.Primary_uom_code "UOM",
                    MTL.LOT_NUMBER "LOT NUMBER"
                    ,A.PARTY_NUMBER "CUSTOMER NUMBER",
                    A.PARTY_NAME "CUSTOMER NAME",
                    (A.ADDRESS1||A.ADDRESS2||A.ADDRESS3||A.ADDRESS4) "SHIP TO",
                    B.DELIVERY_DETAIL_ID "DO NO",B.SHIPPED_QUANTITY "SHIPPED QUANTITY"
                    ,C.ULTIMATE_DROPOFF_DATE "ISSUED DATE"
                    ,D.ORDER_NUMBER "SALES ORDER NUMBER"
                    ,E.LINE_NUMBER "SALES ORDER LINE"
      FROM          MTL_SYSTEM_ITEMS             MIS,
                    MTL_TRANSACTION_LOT_NUMBERS  MTL,
                    HZ_PARTIES                   A,
                    WSH_DELIVERY_DETAILS         B,
                    WSH_NEW_DELIVERIES           C,
                    OE_ORDER_HEADERS_ALL         D,
                    OE_ORDER_LINES_ALL           E
    WHERE          MIS.INVENTORY_ITEM_ID = MTL.INVENTORY_ITEM_ID
       AND          MIS.INVENTORY_ITEM_ID = E.INVENTORY_ITEM_ID
       AND          B.INVENTORY_ITEM_ID   = MIS.INVENTORY_ITEM_ID
       AND          A.PARTY_ID            = B.CUSTOMER_ID
       AND          B.DELIVERY_DETAIL_ID  = C.DELIVERY_ID
    AND C........ = D. .......
       AND          D.HEADER_ID           = E.HEADER_ID
    ;I am not sure but I guess a relationship (in bold) is missing.
    HTH
    Ghulam

  • View creating Cartesian Product.. why....

    i am joining 5 tables in a view.. dont know exactly why it is creating Cartesian product.
    Below is the query:
    PROMPT CREATE OR REPLACE VIEW xxpd_ozf_aff_err_int_v
    CREATE OR REPLACE VIEW xxpd_ozf_aff_err_int_v (
    row_id,
    source_system,
    source_process_id,
    source_process_date,
    ora_process_id,
    soa_instance_id,
    customer_record_id,
    process_status,
    insert_update_flag,
    process_stage,
    process_start_time,
    process_end_time,
    error_code,
    error_message,
    error_type,
    customer_process_status,
    supplier_process_status,
    customer_level,
    source_customer_ref,
    customer_class_code,
    customer_type,
    business_model_code,
    source_parent_cust_ref,
    source_parent_cust_type,
    customer_name,
    account_status,
    customer_alias,
    person_flag,
    person_first_name,
    person_last_name,
    tax_reg_number,
    tax_reg_type,
    customer_id,
    account_number,
    party_id,
    party_type,
    party_number,
    supplier_id,
    affiliate_type,
    check_payable_name,
    payable_flag,
    approved_flag,
    primary_site,
    site_status,
    purpose,
    address1,
    address2,
    address3,
    address4,
    city,
    county,
    state,
    province,
    postal_code,
    country,
    cust_acct_site_id,
    party_site_id,
    location_id,
    reportable_1099,
    tax_type_1099,
    primary_contact,
    contact_role,
    contact_status,
    first_name,
    last_name,
    salutation,
    job_title,
    email_address,
    phone_line_type,
    phone_number,
    phone_extension,
    phone_area_code,
    phone_country_code,
    preferred_language,
    customer_profile_class,
    profile_acct_status,
    profile_active_status,
    account_status_reason,
    invoice_type
    ) AS
    SELECT acct.ROWID row_id,
    CTRL.SOURCE_SYSTEM,
    CTRL.SOURCE_PROCESS_ID,
    CTRL.SOURCE_PROCESS_DATE,
    CTRL.ORA_PROCESS_ID,
    CTRL.SOA_INSTANCE_ID,
    ACCT.CUSTOMER_RECORD_ID,
    CTRL.PROCESS_STATUS,
    CTRL.INSERT_UPDATE_FLAG,
    CTRL.PROCESS_STAGE,
    CTRL.PROCESS_START_TIME,
    CTRL.PROCESS_END_TIME,
    CTRL.ERROR_CODE,
    CTRL.ERROR_MESSAGE,
    --ACCOUNT TABLE
    ACCT.ERROR_TYPE,
    ACCT.CUSTOMER_PROCESS_STATUS,
    ACCT.SUPPLIER_PROCESS_STATUS,
    ACCT.CUSTOMER_LEVEL,
    ACCT.SOURCE_CUSTOMER_REF,
    ACCT.CUSTOMER_CLASS_CODE,
    ACCT.CUSTOMER_TYPE,
    ACCT.BUSINESS_MODEL_CODE,
    ACCT.SOURCE_PARENT_CUST_REF,
    ACCT.SOURCE_PARENT_CUST_TYPE,
    ACCT.CUSTOMER_NAME,
    ACCT.ACTIVE_STATUS ACCOUNT_STATUS,
    ACCT.CUSTOMER_ALIAS,
    ACCT.PERSON_FLAG,
    ACCT.PERSON_FIRST_NAME,
    ACCT.PERSON_LAST_NAME,
    ACCT.TAX_REG_NUMBER,
    ACCT.TAX_REG_TYPE,
    ACCT.CUSTOMER_ID,
    ACCT.ACCOUNT_NUMBER,
    ACCT.PARTY_ID,
    ACCT.PARTY_TYPE,
    ACCT.PARTY_NUMBER,
    ACCT.SUPPLIER_ID,
    ACCT.AFFILIATE_TYPE,
    ACCT.CHECK_PAYABLE_NAME,
    ACCT.PAYABLE_FLAG,
    ACCT.APPROVED_FLAG,
    --SITE TABLE
    SITE.PRIMARY_FLAG PRIMARY_SITE,
    SITE.ACTIVE_STATUS SITE_STATUS,
    SITE.PURPOSE,
    SITE.ADDRESS1,
    SITE.ADDRESS2,
    SITE.ADDRESS3,
    SITE.ADDRESS4,
    SITE.CITY,
    SITE.COUNTY,
    SITE.STATE,
    SITE.PROVINCE,
    SITE.POSTAL_CODE,
    SITE.COUNTRY,
    SITE.CUST_ACCT_SITE_ID,
    SITE.PARTY_SITE_ID,
    SITE.LOCATION_ID,
    SITE.REPORTABLE_1099,
    SITE.TAX_TYPE_1099,
    --CONTACT
    CONT.PRIMARY_FLAG PRIMARY_CONTACT,
    CONT.CONTACT_ROLE,
    CONT.ACTIVE_STATUS CONTACT_STATUS,
    CONT.FIRST_NAME,
    CONT.LAST_NAME,
    CONT.SALUTATION,
    CONT.JOB_TITLE,
    CONT.EMAIL_ADDRESS,
    CONT.PHONE_LINE_TYPE,
    CONT.PHONE_NUMBER,
    CONT.PHONE_EXTENSION,
    CONT.PHONE_AREA_CODE,
    CONT.PHONE_COUNTRY_CODE,
    CONT.PREFERRED_LANGUAGE,
    --PRO
    PRFL.CUSTOMER_PROFILE_CLASS,
    PRFL.ACCOUNT_STATUS PROFILE_ACCT_STATUS,
    PRFL.ACTIVE_STATUS PROFILE_ACTIVE_STATUS,
    PRFL.ACCOUNT_STATUS_REASON,
    PRFL.INVOICE_TYPE
    FROM XXEX_AR_CUST_INT_CTRL_T CTRL,
    XXEX_AR_CUST_ACCT_INT_T ACCT,
    XXEX_AR_CUST_SITE_INT_T SITE,
    XXEX_AR_CUST_CONTACT_INT_T CONT,
    XXEX_AR_CUST_PROFILE_INT_T PRFL
    WHERE CTRL.ORA_PROCESS_ID = ACCT.ORA_PROCESS_ID
    AND ACCT.CUSTOMER_RECORD_ID = SITE.CUSTOMER_RECORD_ID
    AND SITE.CUSTOMER_RECORD_ID = CONT.CUSTOMER_RECORD_ID
    AND CONT.CUSTOMER_RECORD_ID = PRFL.CUSTOMER_RECORD_ID
    AND acct.Supplier_process_status = 'E'
    How i should join the 6 tables..

    Rashmi Gupta wrote:
    No all table have records corresponding to each customer ID... But what if one of the table has 1 row..?
    I checked the result.. there is a Cartesian product.
    Customer_Record_ID is unique identifier in 4 tables -
    XXEX_AR_CUST_ACCT_INT_T ACCT,
    XXEX_AR_CUST_SITE_INT_T SITE,
    XXEX_AR_CUST_CONTACT_INT_T CONT,
    XXEX_AR_CUST_PROFILE_INT_T PRFL
    XXEX_AR_CUST_INT_CTRL_T CTRL and XXEX_AR_CUST_ACCT_INT_T ACCT tables have ora_process_id column common so joined between them.
    We dont use primary keys in Interface tables.. we are just using unique indentifier
    Edited by: Rashmi Gupta on Jan 30, 2012 5:58 AMAbove is a very well worded version of what I was getting around to, but in the mean time I've been distracted by your "we don't use primary keys"...when you say "unique identifier" please tell me you mean "unique constraint" ?

  • How Cartesian products affects Sybase IQ performance?

    In my IQ message log, I have the following message:
    I. 04/21 08:28:22. 0001847919 Exception Thrown from dfo_Root.cxx:822, Err# 0, tid 8 origtid 8
    I. 04/21 08:28:22. 0001847919 O/S Err#: 0, ErrID: 9216 (df_Exception); SQLCode: -1005015, SQLState: 'QTA15', Severity: 14
    I. 04/21 08:28:22. 0001847919 [20169]: The optimizer was unable to find a query plan that avoided cartesian product joins larger than the Max_Cartesian_Result setting
    -- (dfo_Root.cxx 822) 
    I don´t know if
    this situation may affect the overall performance
    Thank you

    Hi Jairo,
    As Cartesian product (no join conditions) selects large number of rows, it requires more exec time, temp space (if order by, group by, etc,..) , temp cache, main cache, threads.
    To get close estimations about query resources consumtion, you can generate plans without execution using option NoExec.
    Query plan option recommended are : quary_name, query_plan, query_detail, query_plan_as_html, query_plan_as_html_directory, dml_options10.
    See Generating Query Plans
    Note that other resource monitoring options can be enabled/used , but they require effectivel query exection. The info are collected once execution is finished with success. Eg. query_plan_after_run and query_timing.
    Regards,
    Tayeb.

  • Want to avoid cartesian Product but cannot avoid it some how.

    Hi,
    I am using oracle 10G .
    trying to draft a query which is resulting in absurd results.
    select i.corr_acc_no, sum(amtsign.amount_6) from item i,
    (select corr_Acc_no,flag_2,decode(fund_code,'C',amount_6,amount_6*-1) amount_6 from item
    where corr_AcC_no in (select corr_acc_no from bank where local_Acc_no in ('MBL-SEG-NZD'))and flag_2=0) AmtSign
    where i.corr_acc_no=amtsign.corr_acc_no
    and i.flag_2=0
    group by  i.corr_acc_no
    Basically the inner query, which i am using as the second table in the join, gives 13 results. I want to sum the amount_6 field in main select clause which I want to get from results of
    (select corr_Acc_no,flag_2,decode(fund_code,'C',amount_6,amount_6*-1) amount_6 from item
    where corr_AcC_no in (select corr_acc_no from bank where local_Acc_no in ('MBL-SEG-NZD'))and flag_2=0)
    The sum took too much time so i drafted simple query to check how many rows are returned by removing sum and i noticed it gives a Cartesian product with 169 rows instead of just 13. I have 2 join conditions but the value for corr_Acc_no is same for all 13 rows, i can't use amount_6 as join becuase i am changing it's sign  in the inner query. Please advise.

    Thanks to both of you. @LakmalRajapakse your answer is bang on right. I did the same way after I posted this. I realized there's no point joining item with itself when I can get it done in single query. It's just that I was having hard time with 'Case' in select to get whatever I want,so I tried this logic. But then gave a try to decode, it worked. Thanks anyways.

  • CARTESIAN PRODUCT problem

    hello,
    i m trying to find the difference for calculating the DIFFENCE IN STOCK FOR OPC,PPC,CLINKER BY USING FOLLOWING SQL-QUERY
    SELECT TO_CHAR(a.dateofmtrl,'YYYY') YEAR,
    SUM(a.rm1) - SUM(b.rm1) - SUM(c.rm1) OPC,
    SUM(a.rm2) - SUM(b.rm2) - sum(c.rm2) PPC,
    SUM(a.rm3) - SUM(b.rm3) - sum(c.rm3) CLINKER
    FROM rawmtrl_graph a
    INNER JOIN rawmtrl_graph b ON TO_CHAR(a.dateofmtrl,'YYYY') =TO_CHAR(B.dateofmtrl,'YYYY')
    INNER JOIN rawmtrl_graph c ON TO_CHAR(a.dateofmtrl,'YYYY') =TO_CHAR(C.dateofmtrl,'YYYY')
    WHERE a.mtrl_flag='P'
    AND b.mtrl_flag='D'
    AND c.mtrl_flag='CS'
    GROUP BY TO_CHAR(a.dateofmtrl,'YYYY')
    BUT IT IS GIVING CARTESIAN PRODUCT...
    HOW TO MODIFY THE QUERY FOR FINDING EXACT FIGURE??????
    THANKS IN ADVENCE FOR ANY HELP.....

    Hi,
    please always put your code between two lines starting with {noformat}{noformat}.
    Additionally when you put insert statement put them entirely and not copying from one table we don't have.
    Here the way to get the result you want:SELECT EXTRACT(YEAR FROM dateofmtrl) yr
    , SUM(CASE mtrl_flag WHEN 'P' THEN rm1 ELSE -rm1 END) AS opc
    , SUM(CASE mtrl_flag WHEN 'P' THEN rm2 ELSE -rm2 END) AS ppc
    , SUM(CASE mtrl_flag WHEN 'P' THEN rm3 ELSE -rm3 END) AS clinker
    FROM rawmtrlgraph
    GROUP BY EXTRACT(YEAR FROM dateofmtrl);
    YR OPC PPC CLINKER
    2011 50 54 55
    2012 -49 -3 -11
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Cartesian Product - Report script

    Hi All,
    I am trying to export data for a specific scenario and version using report script.
    I am taking level 0 members of a specific dimension and it is throwing error as follows:
    "The Product of member counts across all dimensions in the query exceeds 2^64"
    I think the cartesian product is beyond the limit value.
    Is there any alternative method to export data of level 0 members for that dimension?
    or is there any command to select only few members from that dimension, so that I can make into two scripts and execute to export data.
    Thanks.
    Regards
    Rav

    "or is there any command to select only few members from that dimension,"
    Take a look at the member selection report script commands. If you have a hierarchies in your dimensions than you can use these to "break up"/more narrowly focus your report script

Maybe you are looking for

  • HU traceability is missing when HU unpacked(Transaction LM22).

    Hi SAP Gurus, I have a requirement to know details of Handling unit  like HU unpacked, material, batch ,qty when unpack using LM22 and packing using LM19. Firstly, Warehouse Operators will use only LM22 and LM19 transactions for Unpacking/Packing of

  • Connect to MS-SQL Server from a Oracle 10g running under Solaris

    Hi, I have the following problem. I want to access a MS-SQL server from an Oracle database (10g Enterprise licence) that is running on Solaris. After googling a while, the following questions arise: - Is it correct that the Oracle Transparant Gateway

  • Add-ons manager doesn't load

    I am at wits end... I have tried every solution to get the add-ons manager to load and nothing has worked. If you might know of a solution please let me know. I am running Firefox 11, Windows 7 and I have checked for and updated a plug-in. I even cli

  • Critical issues in MM

    Hi Gurus, Can anybody tell me one of the most critical/ challenging issues in MM implementation Thanks in advance, Kumar

  • Broadband Line Slammed by Sky - but BT still not r...

    deleted - post moved by Keith as I was typing reply way to slow gg30340 If you like a post, or want to say thanks for a helpful answer, please click on the Ratings star on the left-hand side of the post. If someone answers your question correctly ple