Cartesian Product with @SumRange

Hi,
I'm trying to calculata a sumRange of an Account on two separate Dimension,on Planning 11.1.2.3
@sumRange("Account"->"ToTal",@Range("Dimension1.1"->"Dimension2.3","Dimension1.3"->"Dimnension2.5"));
the results is not what i was expecting, The target would be a Cartesian Product ( sum of the following elements) :
Dimension1.1"->"Dimension2.3
Dimension1.1"->"Dimension2.4
Dimension1.1"->"Dimension2.5
Dimension1.2"->"Dimension2.3
Dimension1.2"->"Dimension2.4
Dimension1.2"->"Dimension2.5
Dimension1.3"->"Dimension2.3
Dimension1.3"->"Dimension2.4
Dimension1.3"->"Dimension2.5
Is there any ways to achieve this ?
Regards

Hi,
thanks for your eeply but the @Xrange will get  also elements that are not needed.
if Dimension 1 has got 20 childrens (Dimension 1.1 ...Dimension 1.20) the calc will add all these elements :
Dimension1.1"->"Dimension2.3
Dimension1.2"->"Dimension2.3
Dimension1.20"->"Dimension2.3
Dimension2.1"->"Dimension2.4
Dimension2.20"->"Dimension2.4
Dimension1.3"->"Dimension2.3
Dimension1.3"->"Dimension2.4
Dimension1.3"->"Dimension2.5
and that is incorrect.
The elements that are needed are those in the first post.
Regards

Similar Messages

  • 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.

  • 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

  • General algorithm for cartesian product

    i am looking for an algorithm to get the cartesian product from a set of sets like {{1,2,3,4},{a,b,c},{x,y,z,7,15}...} - this means in most general form.
    google yields no results :-(. i think implementing it by myself is not a good idea.

    dermoritz wrote:
    prometheuzz is your algorithm better than n*mi n: number of sets mi: cardinality of the set i ?
    can you short explain the algorithm?You can't do any better than that because for n sets: S(0), S(1), S(2) ... S(n-1) there are prod(i in [0, n), |S(i)|) elements of the caresian product. Prometeuzz algorithm generates
    one at ever pass of the loop executing n steps per element. If you're afraid that the product number will be too large you can also fiddle with the indexes themselves:
    // scard[i] == |S(i)|
    // prod[i] == element of S(i) in product
    int[] next(int[] scard, int[] prod) {
       for (int i= prod.lerngth; i-- > 0; prod= 0)
    if (++prod[i] < scard[i]) return prod; // return indexes of next product
    return null; // no next product anymore
    }kind regards,
    Jos                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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.

  • 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!

  • 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.

  • How to force Cartesian Product for unlineked (DBF) tables

    Hello
    We have been using CR8.5 for many years and we are just about to perform major upgrade to CR2011. I have, howverm found one strange behavior.
    Many of our reports are implemented in following way:
    MainTable.DBF (contains reported rows)
    ParamTable.DBF (contains one row with some general parameters)
    There is no data "link" between these tables but t makes sense to expect that every record from main table will see record from param table.
    in CR 8.5 Cartesian product of MainTable X ParamTable was ALWAYS available ad therefore we were able to (for example) hide the details & show only group totals, or display some header information (this can be also done by sub-report).
    in CR2011, however, this seems not to be the case anymore. Namely:
    any old report that I open in CR2011 has param line available only for the very first record and I was not able to find a way how to change it
    if I recreate the report from the scratch, sometimes Cartesian product is "provided" and sometimes not - I really do not know the reason for the decision.
    [I have one very ugly workaround: link these two tables with != (not equal operation) between two unrelated fields that can never be the same]
    Is there any "solution" to this cause as it blocks us from upgrading to the latest version?
    Kind Regards,
    Martin Fontan

    Hi Martin,
    Long story so here's the short one. As of CR 9 we completely redeveloped our database drivers and query engine. We removed all of the "hack" work arounds in our code for DB clients did not follow the rules, this forces the DB makers to fix the client engine and follow ANSII 92 standards. You also can no longer edit the SQL statement.
    We have also never supported unlinked tables, CR is a Relational database reporting tool. Us a subreport if you must use an unlinked table, or as you have discovered using a != type.
    Other work around is to use a Command, it' sin the Database wizard, write your own SQL, we simply pass it to the client. There is no option directly to set location from a Table to a SQL Command but search here, Brian Dong found a way around this limitation using a CR Wizard.
    Thanks
    Don

  • About cartesian product

    hello!!
    I write to you in order to ask you some information about the cartesian product of n sets. The all n sets are equivalent; everyone contain matriz nxm.
    Please help me! Can I use array of array or Set?
    How can I do it! Some reference?
    Thanks.. grazie!

    chongo,
    To begin with, it looks like your sets have binary strings as elemens, so (unless your binary strings are ever longer than 16 bits) you can use one integer to represent each element. For instance, the element 01101 is equivalent to 0000000000001101, which is 13 in base two, so it will be a 13 in the set. (All I'm saying is, you don't need to use a string representation.)
    The sets themselves are probably most easily stored as arrays of ints. This gives us a notion of order that might be useful for calculating the cartesian product, and is quick and easy to implement.
    For the product, I would not even bother calculating the whole thing at once unless you need acces to all of its elements more than a few times. If you represent your existing sets by arrays, you have constant-time random access to the elements in a definite order, so you could just write a method that returns specific elements of the Cartesian product. This will effectively give you access to elements in the Cartesian product in O(n) time. For an example of such a method (check this code before using it):
    public static int[] getCartesianElement(int[][] sets, int[] coordinates) {
        if (sets.length != coordinates.length)
            throw new IllegalArgumentException("lengths do not match");
        int[] element = new int[sets.length];
        for (int i = 0; i < sets.length; i++)
            element[i] = sets[i][coordinates];
        return element;
    }or, if you know you're using only one set in the product,
    public static int[] getCartesianElement(int[] set, int[] coordinates) {
        int[] element = new int[coordinates.length];
        for (int i = 0; i < coordintates.length; i++)
            element[i] = set[coordinates];
        return element;
    }I used the name "coordinates" for the int[] specifying which element we want because you can think of the elements of the product as occupying points in n-space, with the coordinates resulting form the handy ordering imposed by the array representation. In the second method, the number of operands is implicit in the length of coordinates.
    If you really want to generate the whole product, the code above could be easily adapted.

  • What is a cartesian product why we need it and where we need it

    Hi,
    One of my interview they asked this question
    Can any one please tell detail about it.
    Thanks
    Kalpana

    >
    what is a cartesian product
    >
    A cartesian join is when you do not specify any join condition between tables.
    So for two tables A and B the result is that every row of table B is appended to every row of table A.
    If there are 10 rows in Table A and 20 rows in Table b there will be 200 rows in the result set and each row will contain every column from table A and every column from table b unless you specify specific columns.
    See Cartesian Products in the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm
    >
    Cartesian Products
    If two tables in a join query have no join condition, then Oracle Database returns their Cartesian product. Oracle combines each row of one table with each row of the other. A Cartesian product always generates many rows and is rarely useful. For example, the Cartesian product of two tables, each with 100 rows, has 10,000 rows. Always include a join condition unless you specifically need a Cartesian product. If a query joins three or more tables and you do not specify a join condition for a specific pair, then the optimizer may choose a join order that avoids producing an intermediate Cartesian product.
    >
    As for when? In earlier versions of Oracle I would use a cartesian join when creating report ready data tables and there needed to be data for every report period. One example is writing a Crystal Report (now business objects) to report sales for 2011 and you want the report to have a section for each month even if there was no data for that month.
    Then we would use a cartesian join on a date table that had 12 records (one for each month) with totals of zero. This would make sure that there was at lease one summary record for each month so that every month would show up on the report even if we only had data for March.

  • What is Cartesian product in Oracle?

    "Cartesian product" often appear in the Oracle book, what is it?

    Hi Ashish,
    Actually it is the other way round. Actually it depends the way you see.. But normal it is stated this way.If you want to get data from two tables depending on one condition you use join. If you don't give a condition for joining it displays the cartesian product of the two tables.
    If the condition for joining the table is equality sign then it is called equi join else if it is > or < then non-equi join.
    Similary you have outer join, self join(joining table with itself based on a condition), inner join ,etc.
    To learn more about joins take a look at the following link
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/queries7.htm
    Regards,
    Anupama

  • 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.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Hint ordered and cartesian product

    I have a query which needs to be tuned.
    The initial Query does not show cartesian product in the plan , when I change the order of the tables in the from clause ( I have placed the least # of rows first and the most rows tables in the last) and I get MERGE JOIN CARTESIAN product the where clause remaining the same and the cost escalates from 7180 to 454M .
    This happens with ordered hint.

    ranjus wrote:
    I have a query which needs to be tuned.
    The initial Query does not show cartesian product in the plan , when I change the order of the tables in the from clause ( I have placed the least # of rows first and the most rows tables in the last) and I get MERGE JOIN CARTESIAN product the where clause remaining the same and the cost escalates from 7180 to 454M .
    This happens with ordered hint.Let's take a look at this with a simple test case. Assume that:
    * Table T1 contains 10,000 rows
    * Table T2 contains 100 rows
    * Table T3 contains 100,000 rows
    * Table T4 contains 10 rows
    You have the following query:
    SELECT
      T1.C1,
      T2.C2,
      T3.C3,
      T4.C4
    FROM
      T1,
      T2,
      T3,
      T4
    WHERE
      T1.C1=T2.C2
      AND T2.C2=T3.C2
      AND T3.C3=T4.C3;In the above, you can see that in the WHERE clause:
    * Table T1 is joined to table T2
    * Table T2 is joined to tables T1 and T3
    * Table T3 is joined to tables T2 and T4
    * Table T4 is joined to table T3
    What it sounds like you are trying to do is something like this based on the number of rows in the tables:
    SELECT /*+ ORDERED */
      T1.C1,
      T2.C2,
      T3.C3,
      T4.C4
    FROM
      T4,
      T2,
      T1,
      T3
    WHERE
      T1.C1=T2.C2
      AND T2.C2=T3.C2
      AND T3.C3=T4.C3;In the above, we are forcing Oracle's optimizer to join tables T4 and T2 - but there is no direct relationship between the two tables described in the WHERE clause. In such a case, Oracle's optimizer will be forced to perform a Cartesian join between tables T4 and T2. Next, table T1 has a relationship defined in the WHERE clause with table T2, so that join would not result in a Cartesian product. Finally, table T3 has a relationship between tables T2 and T4, so that would not result in a Cartesian product.
    Going back to this example, assume that table T4 contained a single row. The execution plan will still show a Cartesian join, but that Cartesian join is no worse than a nested loops join because there is a single row in one of the row sources.
    In short, think about what you are attempting to force the optimizer to do. You cannot always join in the order of increasing row cardinality estimates - it simply does not make sense to try in some cases.
    Charles Hooper
    Co-author of "Expert Oracle Practices: Oracle Database Administration from the Oak Table"
    http://hoopercharles.wordpress.com/
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • What is the use of Cartesian Product or Cross join?

    Dear friends...
        I have done with inner join, self join and outer join. But I m getting confused with cross join. I know it used to produce Cartesian product of two table. But I wanted to know what is the use of Cartesian product in real life? In
    which situation we can use Cartesian product or cross join? I wanted some real life examples on Cartesian product. Please help me.

    Sometimes you get requirement stating that all combinations should be considered and in this scenario CROSS JOIN comes in play.
    If you have Products and Stores table, by using CROSS JOIN you can get the combination of all stores and all products and then you can JOIN this result set to other tables.
    Please refer:  The power of the Cross Join
    Cheers,
    Vaibhav Chaudhari
    [MCTS],
    [MCP]

Maybe you are looking for

  • Creation of asset in PO

    Does anybody know if it is possible to add extra fields in the first screen of asset creation when this is opened from within the PO? More specific: when creating a Purchase Order and the account assignment is set as Asset (multiple account assignmen

  • Best way for a thread to wait without busy-waiting

    Hi! I have a thread that has nothing to do but to monitor the status of a variable public static boolean askToClose. This variable is set by other threads to indicate that this thread should stop now. But I don't want the thread to busy-wait like in

  • Resolved - iTunes cannot sync apps to iPad "ipadName" because the apps installed on the iPad could not be determined.

    Current setup - Dell Destop running Windows XP SP3 - iTunes 10.5 as of 11/02/2011 - iPad 2 iOS 5.0 as of 11/02/2011 I recently got the error message iTunes cannot sync apps to iPad "ipadName" because the apps installed on the iPad could not be determ

  • Help with printing out colored text.

    Basically i just have a String, that i want to print to the screen, using System.out.println(); But i want to give it a RGB value. Can anyone tell me the simplest way to do this?

  • Deployer URI not working from my workstation.

    I am unable to deploy to a remote oc4j instance while my coworker has no trouble. When I try to deploy using our ANT script, I get the following error: Failed at "Could not get DeploymentManager". This is typically the result of an invalid deployer U