Merge Cartesian in query

Hi
below query is running 1 minutes on test server however it is stucking on production for more than 8 hours .
I compared explain plan for both queries ,on test server,optimizer is using hash join however on production ,optimizer is using Merge Cartesian join .
I tried query with ordered hit ,we get rid of mergecartesian join but cost got increased
now please advice ,if we should go by this ordered hit method on production or not not
or suggets any other ways .
below is query
SELECT DISTINCT acct_promo_hdr.row_id, '401000', 'EXPORTED',
acct_promo_hdr.src_num, 'PLAN_ACCOUNT_PROMOTION',
promo_hdr_org.NAME
FROM siebel.s_src acct_promo_hdr,
siebel.s_mdf_alloc deal,
siebel.s_bu promo_hdr_org
-- siebel.s_contact contact,
-- siebel.s_user usr
WHERE acct_promo_hdr.sub_type = 'PLAN_ACCOUNT_PROMOTION'
AND acct_promo_hdr.row_id = deal.promo_id
AND acct_promo_hdr.bu_id = promo_hdr_org.row_id
-- AND acct_promo_hdr.created_by = contact.row_id
-- AND contact.row_id = usr.row_id
AND EXISTS (
SELECT 1
FROM approval acb_approval
WHERE acb_approval.status NOT IN
('11', '12', '65', '77')
AND acct_promo_hdr.src_num =
acb_approval.commit_num)
AND deal.status_cd IN
('Cancel',
'Cancelled',
'Committed',
'On Hold',
'Processing Claim',
'Paid In Part',
'Paid In Full',
'Hold'
explain plan on production
PLAN_TABLE_OUTPUT
Plan hash value: 115701554
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 133 | 207 (2)| 00:00:03 |
| 1 | HASH UNIQUE | | 1 | 133 | 207 (2)| 00:00:03 |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 1 | 133 | 206 (1)| 00:00:03 |
| 4 | NESTED LOOPS | | 1 | 112 | 205 (1)| 00:00:03 |
| 5 | MERGE JOIN CARTESIAN | | 1 | 57 | 67 (2)| 00:00:01 |
| 6 | SORT UNIQUE | | 1 | 30 | 64 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL | APPROVAL | 1 | 30 | 64 (0)| 00:00:01 |
| 8 | BUFFER SORT | | 3 | 81 | 3 (34)| 00:00:01 |
| 9 | TABLE ACCESS FULL | S_BU | 3 | 81 | 2 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID| S_SRC | 1 | 55 | 137 (0)| 00:00:02 |
|* 11 | INDEX RANGE SCAN | S_SRC_U2 | 1 | | 137 (0)| 00:00:02 |
|* 12 | INDEX RANGE SCAN | S_MDF_ALLOC_F8 | 12 | | 1 (0)| 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID | S_MDF_ALLOC | 11 | 231 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
7 - filter("ACB_APPROVAL"."STATUS"<>'11' AND "ACB_APPROVAL"."STATUS"<>'12' AND
"ACB_APPROVAL"."STATUS"<>'65' AND "ACB_APPROVAL"."STATUS"<>'77')
11 - access("ACCT_PROMO_HDR"."BU_ID"="PROMO_HDR_ORG"."ROW_ID" AND
"ACCT_PROMO_HDR"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION')
filter("ACCT_PROMO_HDR"."SUB_TYPE"='PLAN_ACCOUNT_PROMOTION' AND
"ACB_APPROVAL"."COMMIT_NUM"=TO_NUMBER("ACCT_PROMO_HDR"."SRC_NUM"))
12 - access("ACCT_PROMO_HDR"."ROW_ID"="DEAL"."PROMO_ID")
13 - filter("DEAL"."STATUS_CD"='Cancel' OR "DEAL"."STATUS_CD"='Cancelled' OR
"DEAL"."STATUS_CD"='Committed' OR "DEAL"."STATUS_CD"='Hold' OR "DEAL"."STATUS_CD"='On
Hold' OR "DEAL"."STATUS_CD"='Paid In Full' OR "DEAL"."STATUS_CD"='Paid In Part' OR
"DEAL"."STATUS_CD"='Processing Claim')
35 rows selected.

pujakhetan wrote:
Tables are analysed on production .Well, the stats are indicating to the optimizer that the filter at #7 (<tt>ACB_APPROVAL_STATUS {noformat}<{noformat}> '11'</tt> etc) will return 1 row (usually indicating it thinks there are no rows to process), so if that is not the case then something has gone wrong. I'm guessing the 'good' plan you see in test has higher cardinality figures?
I tried query with ordered hit, we get rid of merge cartesian join but cost got increased nowIgnore the 'cost', it is just a figure calculated by the optimizer to indicate the relative resources required by different query plans - according to the available stats - and if those stats are out or something else is confusing it then the figure will be meaningless. Look at it this way - if the cost calculation was right, your query would already have the best plan.
Also the problem was not the join order but the join method, so I don't see an 'ordered' hint necessarily helping.
btw placing <tt></tt> tags around your code and execution plan will make it a lot easier to read.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Merge Cartesian Join

    Hi,
    I'm having this plan, But I'm not able to understand as to which table/view it's producing the MERGE CARTESIAN JOIN, and BUFFER SORT, is it from CM_PAY_TRANS_VW but then which column it's referring to?
    Please advice
    | Id  | Operation                           | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                    |                      |     1 |   249 |    24  (13)| 00:00:01 |
    |*  1 |  HASH JOIN                          |                      |     1 |   249 |    24  (13)| 00:00:01 |
    |   2 |   VIEW                              | CM_PAY_TRANS_VW      |     1 |   160 |    12   (9)| 00:00:01 |
    |   3 |    HASH GROUP BY                    |                      |     1 |   179 |    12   (9)| 00:00:01 |
    |   4 |     NESTED LOOPS OUTER              |                      |     1 |   179 |    11   (0)| 00:00:01 |
    |   5 |      NESTED LOOPS                   |                      |     1 |   149 |    10   (0)| 00:00:01 |
    |   6 |       MERGE JOIN CARTESIAN          |                      |    19 |  2242 |     9   (0)| 00:00:01 |
    |   7 |        TABLE ACCESS BY INDEX ROWID  | CI_PAY_SEG           |     1 |    28 |     1   (0)| 00:00:01 |
    |   8 |         NESTED LOOPS                |                      |     1 |    78 |     2   (0)| 00:00:01 |
    |   9 |          TABLE ACCESS BY INDEX ROWID| CI_PAY               |     1 |    50 |     1   (0)| 00:00:01 |
    |* 10 |           INDEX RANGE SCAN          | XT156S2              |     1 |       |     1   (0)| 00:00:01 |
    |* 11 |          INDEX RANGE SCAN           | XT165S1              |     3 |       |     1   (0)| 00:00:01 |
    |  12 |        BUFFER SORT                  |                      |    30 |  1200 |     8   (0)| 00:00:01 |
    |* 13 |         TABLE ACCESS FULL           | CI_SA_TYPE_L         |    30 |  1200 |     7   (0)| 00:00:01 |
    |* 14 |       TABLE ACCESS BY INDEX ROWID   | CI_SA                |     1 |    31 |     1   (0)| 00:00:01 |
    |* 15 |        INDEX UNIQUE SCAN            | XM199P0              |     1 |       |     1   (0)| 00:00:01 |
    |  16 |      TABLE ACCESS BY INDEX ROWID    | CI_PAY_CAN_RSN_L     |     1 |    30 |     1   (0)| 00:00:01 |
    |* 17 |       INDEX UNIQUE SCAN             | XC557P0              |     1 |       |     1   (0)| 00:00:01 |
    |  18 |   VIEW                              | CM_PAY_TNDR_TYPES_VW |   174 | 15486 |    11  (10)| 00:00:01 |
    |  19 |    HASH GROUP BY                    |                      |   174 | 15660 |    11  (10)| 00:00:01 |
    |  20 |     NESTED LOOPS OUTER              |                      |   174 | 15660 |    10   (0)| 00:00:01 |
    |  21 |      NESTED LOOPS OUTER             |                      |   160 | 10080 |     9   (0)| 00:00:01 |
    |  22 |       TABLE ACCESS FULL             | CI_PAY_EVENT         |   160 |  4640 |     7   (0)| 00:00:01 |
    |  23 |       TABLE ACCESS BY INDEX ROWID   | CI_PAY_TNDR          |     1 |    34 |     1   (0)| 00:00:01 |
    |* 24 |        INDEX RANGE SCAN             | XT265S3              |     1 |       |     1   (0)| 00:00:01 |
    |  25 |      TABLE ACCESS BY INDEX ROWID    | CI_TENDER_TYPE_L     |     1 |    27 |     1   (0)| 00:00:01 |
    |* 26 |       INDEX UNIQUE SCAN             | XC583P0              |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("A"."PAY_EVENT_ID"="B"."PAY_EVENT_ID")
      10 - access("P"."PAY_EVENT_ID"='010253513440')
      11 - access("P"."PAY_ID"="PSEG"."PAY_ID")
      13 - filter("SA_TYP"."LANGUAGE_CD"='ENG')
      14 - filter("SA"."SA_TYPE_CD"="SA_TYP"."SA_TYPE_CD")
      15 - access("PSEG"."SA_ID"="SA"."SA_ID")
      17 - access("P"."CAN_RSN_CD"="RSN"."CAN_RSN_CD"(+) AND "RSN"."LANGUAGE_CD"(+)='ENG')
      24 - access("EVT"."PAY_EVENT_ID"="TDR"."PAY_EVENT_ID"(+))
      26 - access("TDR"."TENDER_TYPE_CD"="TT"."TENDER_TYPE_CD"(+) AND "TT"."LANGUAGE_CD"(+)='ENG')

    is it CM_PAY_TRANS_VWYou know your data model, we don't. You also haven't posted the query, so it's a bit difficult to tell but it looks to me as though it's CI_SA_TYPE_L which is responsible. FULL TABLE ACCESS with a filter rather than an access predicate.
    As to why this happening, you might find this article by Jonathan Lewis sheds some light.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Cartesian Join query optimization

    Hello Experts!
    I have a question about cartesian join query which might look a bit weird.
    Assume the SQL query like that:
    SELECT DISTINCT A.NAME
    FROM A, B, C;
    Here we have cartesian join for 3 tables A, B and C.
    It looks to me, in order to get the result for such a particular SQL tables/sets B and C need to be accessed only to ensure they return at least 1 row (otherwise result set is empty), query table A, but there is no actual need to join the data.
    If you run such a query Oracle is doing full table scans and actually joins the data.
    Yes, DBMS is doing exactly what you are asking for, but I wonder if there is any way (SQL hint or db parameter or anything else) to enforce more optimal access path here?
    Obvious solution to remove B and C tables from the SELECT statement is not acceptable. :-)
    Thank you!

    Your statement in the other thread indicates you don't understand how the BI prompts actually work because you say you want it to do something that doesn't make sense for it to do.
    Of course Product and Account levels will be constrained to the interval you specified. It wouldn't make sense for them not to be. Because that would mean returning data for based on product and account levels that has a different open data range than what you specified.
    All UI prompt dialogs I have seen use AND relationships between the parameters. If there are three parameters (A, B, C) then the ultimate relationship is 'A AND B AND C'; not 'A OR (B AND C)', 'A AND (B OR C)', 'A OR (B OR C).
    Unless the tool allows you to select OR relationships you need to use a separate dialog box (parameter dialog) for each condition set.:-)
    I understand how BI prompts work and basically agree on your comment, but there are two problems here:
    1. I need to convince the customer his original requirements are not valid. Customer want it to work different way and there are some reasons why.
    2. There are pretty large dimensions and fact tables used here, so when I choose filter criteria for the Product (which is small table) to populate/recalculate prompt values, large SR dimension and fact tables are joined too, and if there are Account dimension filters added, huge Account dimension will be added as well. This looks to be a bit sub-optimal for just populating the Product prompt values.
    Of course, technically this is solvable, but requires to put some extra effort and does not solve the 1st issue.
    That other link doesn't explain the sample code you posted in this thread. Post the actual query that is being generated and the query that you want to actually use.This is what is generated:
    >
    select distinct T311691.X_CUST_SUBTYPE as c1
    from
    WC_LOV_SR_AREA_H T311695,
    WC_LOV_PROD_H T311687,
    WC_LOV_CUST_TYPE_H T311691,
    W_SRVREQ_D T302384 /* Dim_W_SRVREQ_D */
    where ( T311687.LEV1 = 'Product X' and T311691.X_CUST_TYPE = 'Business' and T302384.OPEN_DT between TO_DATE('2012-03-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2012-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
    order by c1
    >
    This is what is actually needed to query this data:
    >
    select distinct T311691.X_CUST_SUBTYPE as c1
    from
    WC_LOV_CUST_TYPE_H T311691
    where ( T311691.X_CUST_TYPE = 'Business' )
    order by c1

  • Merge cartesian join in query plan

    Hi All
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
    I am trying to sue dynamic sampling, but it doesn't seem to work.
    please help on this.

    user8650395 wrote:
    Hi All
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
    I am trying to sue dynamic sampling, but it doesn't seem to work.
    please help on this.Interesting.
    There was a a thread a day or two ago about when dynamic sampling does not work. You can search OTN for it if you like. Also check the docs to make sure that dynamic sampling works with GTTS
    One problem with GTTS is getting accurate statistics. Have you considered using DBMS_STATISTICS to set the statistics on the table to adjust the cardinality?
    Your cardinality of 1 sounds incorrect. In theory a cartesian join against one row should be painelss; unfortunately your cardinality figure seems to be off! Sometimes in cases like yours the cost-based optimizer will choose a Cartesian join even when the table joins are properly specified.

  • Table.Join/Merge in Power Query takes extremly long time to process for big tables

    Hi,
    I tried to simply merge/inner join two big tables(one has 300,000+ rows after filtering and the other has 30,000+ rows after filtering) in PQ. However, for this simple join operation, PQ took at least 10 minutes (I killed the Query Editor after 10
    minutes' processing) to load the preview.
    Here's how I did the join job: I first loaded tables into the workbook, then did the filtering for each table and at last, used the merge function to do the join based on a same field.
    Did I do anything wrong here? Or is there any way to improve the load efficiency?
    P.S. no custom SQL was used during the process. I was hoping the so called "Query Folding" can help speed the process, but it seems it didn't work here.
    Thanks.
    Regards,
    Qilong

    Hi!
    You should import the source tables
    in Access. This will speed up the work of
    PQ in several times.

  • Inline views / view merge slowing the query

    I have a tool generated query. This query uses inline views. The individual view return data under a second but final query is taking 10min +. any suggestion.
    I tried /*+ NO_MERGE(D1,D2,D3,D4)*/ but to no help.
    TIA.
    SELECT /*+ NO_MERGE(D1,D2,D3,D4)*/DISTINCT d4.c5 AS c1, d2.c14 AS c2,
    d3.c8 AS c3, d2.c8 AS c4,
    d2.c9 AS c5, d2.c10 AS c6,
    d2.c11 AS c7, d2.c12 AS c8,
    d2.c13 AS c9
    FROM (vv_d1) d1,
    (vv_d2) d2,
    (vv_d3) d3,
    (vv_d4) d4
    WHERE ( NVL (d1.c1, 'q') =
    NVL (d2.c14, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d2.c14, 'z')
    AND NVL (d1.c3, 'q') =
    NVL (d2.c12, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d2.c12, 'z')
    AND NVL (d1.c6, 'q') =
    NVL (d2.c9, 'q')
    AND NVL (d1.c6, 'z') =
    NVL (d2.c9, 'z')
    AND NVL (d1.c4, 'q') =
    NVL (d2.c10, 'q')
    AND NVL (d1.c4, 'z') =
    NVL (d2.c10, 'z')
    AND NVL (d1.c5, 8) =
    NVL (d2.c13, 8)
    AND NVL (d1.c5, 9) =
    NVL (d2.c13, 9)
    AND NVL (d1.c1, 'q') =
    NVL (d4.c6, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d4.c6, 'z')
    AND NVL (d1.c1, 'q') =
    NVL (d3.c11, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d3.c11, 'z')
    AND NVL (d1.c2, 88.0) =
    NVL (d3.c9, 88.0)
    AND NVL (d1.c2, 99.0) =
    NVL (d3.c9, 99.0)
    AND NVL (d1.c3, 'q') =
    NVL (d3.c10, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d3.c10, 'z')
    AND NVL (d1.c7, 'q') =
    NVL (d2.c11, 'q')
    AND NVL (d1.c7, 'z') =
    NVL (d2.c11, 'z')
    )

    And the Oracle version number, to three decimal places is?
    Post EXPLAIN PLAN output created using dbms_xplan
    http://www.psoug.org/reference/explain_plan.html

  • How to merge 3 different query results using full outer join?

     Hi all This is my my query for 2 results
    with t1 as (
    select trans.crAcc_id,trans.cr_amt,row_number() over (order by trans.head_id) rn from Acttrans trans,
     Acttranhead head where trans.head_id in(select link_id from acttrans where head_id=12) and trans.crAcc_id!=0
     and head.head_id=trans.head_id
    t2 as (
    select trans.drAcc_id,trans.dr_amt,head.[Vouc_No],head.[Vouc_Date] ,head.[Check_No],head.[Check_Date],head.[stat],row_number() over (order by trans.head_id) rn from Acttrans trans,
     Acttranhead head where trans.head_id=12 and trans.drAcc_id!=0
     and head.head_id=trans.head_id
     select t1.crAcc_id, t1.cr_amt,t2.[Vouc_No],t2.[Vouc_Date] ,t2.[Check_No],t2.[Check_Date],t2.[stat],t2.drAcc_id,t2.dr_amt from t1
      full outer join t2 on t1.rn = t2.rn
    Query 3: SELECT [CrAcc_Id]  FROM [KSSDATA].[dbo].[ActTrans] where head_id=12 and crAcc_id!=0
    and i want to add Query3 result to the ABOVE RESULT but i am unable add third result using full outer join
    Thanks
    Balu D

    >>>but i am unable add third result using full outer join
    Do you get the error or wrong result?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Merging images - newbie query

    I have an A3 picture that I have scanned in 2 parts using my A4 scanner and would like to know to find the easiest way of stitching them together with PS. I am aware of Autostitch, but want to produce a high resolution TIFF image. Can anyone direct me to a suitable tutorial - I do need click by click instructions though as I'm still feeling my way along with PS!

    What is the problem with File->Automate->Photomerge? you can then change the resolution using Image->Image Size (if you need to) and save it as a TIFF as you would any document.
    Using Photomerge: http://help.adobe.com/en_US/Photoshop/11.0/WSfd1234e1c4b69f30ea53e41001031ab64-75e8a.html

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

  • Query taking long because of merge cartesion join

    Hi,
    please suggest me to tune this query.
    SELECT DISTINCT acct_promo_hdr.row_id, '401000', 'EXPORTED',
    acct_promo_hdr.src_num, 'PLAN_ACCOUNT_PROMOTION',
    promo_hdr_org.NAME
    FROM siebel.s_src acct_promo_hdr,
    siebel.s_mdf_alloc deal,
    siebel.s_bu promo_hdr_org
    -- siebel.s_contact contact,
    -- siebel.s_user usr
    WHERE -- acct_promo_hdr.sub_type = 'PLAN_ACCOUNT_PROMOTION'
    deal.promo_id =acct_promo_hdr.row_id
    AND acct_promo_hdr.bu_id = promo_hdr_org.row_id
    -- AND acct_promo_hdr.created_by = contact.row_id
    -- AND contact.row_id = usr.row_id
    AND EXISTS (
    SELECT 1
    FROM approval acb_approval
    WHERE acb_approval.status NOT IN
    ('11', '12', '65', '77')
    AND acct_promo_hdr.src_num =
    acb_approval.commit_num)
    AND deal.status_cd IN
    ('Cancel', 'Cancelled', 'Committed', 'On Hold',
    'Processing Claim', 'Paid In Part',
    'Paid In Full', 'Hold')
    explain plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 115701554
    | Id | Operation | Name | Rows | Bytes | Cost
    (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 1 | 105 | 206 (2)| 00:00:03 |
    | 1 | HASH UNIQUE | | 1 | 105 | 206 (2)| 00:00:03 |
    | 2 | NESTED LOOPS | | | || |
    | 3 | NESTED LOOPS | | 1 | 105 | 205(1)| 00:00:03 |
    PLAN_TABLE_OUTPUT
    | 4 | NESTED LOOPS | | 1 | 84 | 204 (1)| 00:00:03 |
    | 5 | MERGE JOIN CARTESIAN | | 1 | 57 | 67(2)| 00:00:01 |
    | 6 | SORT UNIQUE | | 1 | 30 | 64 (0)| 00:00:01 |
    |* 7 | TABLE ACCESS FULL | APPROVAL | 1 | 30 | 64 PLAN_TABLE_OUTPUT--(0)| 00:00:01 |
    | 8 | BUFFER SORT | | 3 | 81 | 3(34)| 00:00:01 |
    | 9 | TABLE ACCESS FULL | S_BU | 3 | 81 | 2(0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID| S_SRC | 1 | 27 | 136(0)| 00:00:02 |
    PLAN_TABLE_OUTPUT
    |* 11 | INDEX RANGE SCAN | S_SRC_U2 | 1 | | 136(0)| 00:00:02 |
    Thanks,
    |* 12 | INDEX RANGE SCAN | S_MDF_ALLOC_F8 | 12 | | 1(0)| 00:00:01 |
    |* 13 | TABLE ACCESS BY INDEX ROWID | S_MDF_ALLOC | 10 | 210 | 1(0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    7 - filter("ACB_APPROVAL"."STATUS" <>'11' AND "ACB_APPROVAL"."STATUS"<> '12' AN
    D
    "ACB_APPROVAL"."STATUS"<> '65' AND "ACB_APPROVAL"."STATUS"<> '77')
    11 - access("ACCT_PROMO_HDR"."BU_ID" ;="PROMO_HDR_ORG"."ROW_ID")
    filter("ACB_APPROVAL"."COMMIT_NUM&q uot;=TO_NUMBER("ACCT_PROMO_HDR"."SRC_N UM"))
    PLAN_TABLE_OUTPUT

    Please format your code and stick between tags to preserve the formatting.
    From the look of it, merge cartesian is not unreasonable given the low cardinality.
    However I suspect that the number of rows the optimiser is estimating may be wrong.
    Have you analysed your tables recently?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Query to mimic the items tab of the Sales Analysis report.

    Hi there,
    I'm currently looking to create a query that mimics the behaviour of the Sales Analysis report in B1. The items tab of the Sales Analysis report provides all the data I require - the only issue is that I would like to merge this data with some other data regarding current on hand stock quantities etc. and therefore I would like to be able to pull out the query behind the Sales Analysis report.
    I'm assuming this cannot be done and therefore I'm attempting to build a query to replicate the results. The query needs to show Item No, Item Description, Quantity Sold, Sales Amt (in system currency), Gross Profit and Gross Profit % for items within a given period.
    If this can be done relatively easily, can the query then be modified to show all items (including items that haven't sold in the date range) merely with '0' for Quantity Sold, Sales Amt etc. if the item hasn't been sold in the period, and the appropriate figures if each of these columns if the item has sold. I assume some kind of CASE statement can be used to generate this.
    So the query needs to show Item No, Item Description, Current quantity in stock, Quantity Sold, Sales Amt (in system currency), Gross Profit and Gross Profit % for all items within a given date range.
    I hope you can assist me with this problem.
    Thanks
    Grant.

    Hi,
    Thanks Gordon that was exactly what I needed.
    I've been trying to add some additional columns to the query but I'm experiencing some errors and I can't quite tell why.
    Basically, here's the code from another working query I have which I wish to merge into the query you've suggested above:
    SELECT T0.[ItemCode],
    T0.[ItemName],
    T3.[ItmsGrpNam],
    T4.[Name] AS [Sub-Category],
    T5.[Name] AS [Sub-Sub-Category],
    T0.[CardCode] AS [Pref Supplier],
    T6.[FirmName] AS [Brand],
    T0.[U_Range],
    T0.[OnHand],
    CASE WHEN T0.[StockValue] = 0 THEN 0 ELSE T0.[StockValue] END AS [StockValue],
    T1.[Price] AS [PBK GBP Price],
    CASE WHEN T0.[OnHand] = 0 THEN T0.[LastPurPrc] ELSE T0.[StockValue]/T0.[OnHand] END AS [Ave Cost],
    CASE WHEN T0.[OnHand] = 0 THEN T1.[Price]-T0.[LastPurPrc] ELSE CASE WHEN T0.[OnHand] > 0 THEN T1.[Price]-T0.[StockValue]/T0.[OnHand] END END AS [Margin],
    CASE WHEN T0.[OnHand] = 0 AND T0.[LastPurPrc] = 0 THEN 0 ELSE CASE WHEN T0.[OnHand] > 0 AND (T0.[StockValue]/T0.[OnHand]) = 0 THEN 0 ELSE CASE WHEN T0.[OnHand] = 0 THEN (T1.[Price]-T0.[LastPurPrc])/T1.[Price]*100 ELSE CASE WHEN T0.[OnHand] > 0 THEN (T1.[Price]-T0.[StockValue]/T0.[OnHand])/T1.[Price]*100 END END END END AS [Margin %],
    T0.[LastPurPrc]
    FROM [dbo].[OITM]  T0 INNER JOIN [dbo].[ITM1]  T1 ON T0.ItemCode = T1.ItemCode INNER JOIN [dbo].[OITB]  T3 ON T0.ItmsGrpCod = T3.ItmsGrpCod LEFT OUTER JOIN [dbo].[@U_SUBCATEGORY]  T4 ON T0.U_Subcategory = T4.Code LEFT OUTER JOIN [dbo].[@U_SUBSUBCATEGORY]  T5 ON T0.U_SubSubCategory = T5.Code INNER JOIN OMRC T6 ON T0.FirmCode = T6.FirmCode
    WHERE T0.[OnHand] >= 0 and T0.U_Range not in ('E','X')  
    ORDER BY T0.[ItemCode]
    Essentially I just wish to add the fields which are specified in the query above, but not in the query you've already suggested:
    SELECT T0.ItemCode,
    Max(T0.ItemName),
    Max(IsNull(T0.OnHand,0)) 'In Stock',
    SUM(IsNull(T1.Quantity,0)) 'Quantity',
    Sum(IsNull(T1.LineTotal,0)) 'Sales Amt',
    SUM(IsNull(T1.GrssProfit,0)) 'Gross Profit',
    Case WHEN Sum(Isnull(T1.LineTotal,0)) = 0 THEN 0 ELSE
    SUM(IsNUll(T1.GrssProfit,0))/Sum(Isnull(T1.LineTotal,0)) * 100 END 'Gross Profit %'
    FROM dbo.OITM T0
    LEFT JOIN dbo.INV1 T1 ON T1.ItemCode=T0.ItemCode
    LEFT JOIN dbo.OINV T2 ON T2.DocEntry=T1.DocEntry AND T2.DocDate Between [%0] AND [%1]
    GROUP BY T0.ItemCode
    I was hoping it would be fairly straight forward but so far I've had limited success.
    What am I missing here?
    Thanks in advance!

  • OFFICE 2013 - Word could not re-establish a DDE connection to Microsoft Query

    Hi, I have installed office 2013 on a pc and used excel to run a query on a database and created a .qry query so I can use this data in word mail merge.
    The query runs ok and returns the data.
    However, when I go to take the data in through mail merge it comes up with a message "Confirm data source" ( I enabled this after  reading kb article below) so I select "MS query files via DDE(*.qry, *.dqy)" as this is a .dqy I select
    it. It says at the bottom of the screen word is starting query then comes up with the error  "Word could not re-establish a DDE connection to Microsoft Query to complete the current task".
    I have re-did the query from scratch and no difference I tried the recommend kb article 918594 and it still doesn't work.
    I recreated the odbc link and still no joy.
    Has anyone come across this and have they a solution I would be grateful.
    Thanks
    Tom

    Hi,
    Try to check whether the methods listed in the following link is helpful. The link applies to previous versions, but we can refer to it.
    http://support.microsoft.com/kb/813989
    Jaynet Zhang
    TechNet Community Support

  • Not able to un-merge a dimension in webi report

    Hello,
    I'm facing an issue in webi reports. That is I'm not able to un-merge a dimension. I'm using BO 4.0 sp 6
    I have 6 data providers in my webi report all of those 6 have sales order number in common. The report refreshes fine but a new requirement came in where I had to add another query (data provider) which also has the sales order number.
    Now in the report I need to merge the new query's sales order number with the existing merged sales order number. When I un-merge the existing sales order number; webi just does not respond.
    Any ideas? thanks in advance.
    Regards,
    samique

    The way I resolved this is:
    1- Removed Sales Order Object from all the existing queries. (the variables that were using the sales orders broke)
    2- Added a new data provider query in webi; then added sales order objects in all the data providers.
    3- Merged the Sales Order objects in the webi report.
    4- fixed all the variables with calculations requiring sales order object.
    5- Dragged the Sales Order object to the report body.
    I hope to see an option in future where we don't have to do all this just to add a new data provider query to an existing report that uses merged dimensions. Because its just a waste of time re-doing things.
    There should be an option to merge new dimensions to the existing merged dimensions in the webi report.
    Regards,
    samique

  • Optmizing use of function in a query

    select a1.*, test_pkg.test_function(section_id) record_id
    from (
    select project_id, student_id, max(se.section_id) section_id
    from college c, students s, sections se, zone z
    where c.college_id in (121, 123, 124)
    and s.student_id = c.student_id
    and s.section_id = z.response_id
    and z.section_id = s.section_id
    group by c.project_id, s.student_id) a1;
    the question is I am hitting the test_pkg.test_function for each student_id
    I want it only in case the section_id is different i.e for unique section_id..
    right now i use the inner query to populate the table and then use a cursor to update the
    record_id. this is fast since in the cursor i hit the funtion only for unique section_id's
    Is there a way to make my query faster and in 1 go instead of updating it later...
    I mean can i populate the table using a single query...
    NOTE: May be the joins are wrong, i just manipulated them.....
    using oracle 10g
    thank you

    Something else you can try is to use an inline view. Here when you say you only have 1500 sections, i'm assuming that's the number of records in your section table. I've also added the NO_MERGE hint in to this so that the optimizer doesn't decide to merge this inline query into the rest of the joins (then it would apply the function many more times).
    select project_id, student_id, max(se.section_id) section_id, se.record_id
    from college c, students s, (select /*+ NO_MERGE */ section_id, test_pkg.test_function(section_id) as record_id from sections) se, zone z
    where c.college_id in (121, 123, 124)
    and s.student_id = c.student_id
    and s.section_id = z.response_id
    and z.section_id = s.section_id
    [pre]
    as you said in your original post, the joins are not all correct (there is NO join to the sections table in your query....i'd assume there should be one.
    If the performance of that isn't acceptable you could look into making a materialized view, or a function based index, etc...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Would this query be faster in Oracle 10?

    I'm running 2 queries on Oracle 8i:
    Query 1:
    select count(Member_ID) from
    select Member_ID, c2, c3, ... c100 from T1
    union
    select Member_ID, c2, c3, ... c100 from T2
    union
    union
    select Member_ID, c2, c3, ... c100 from T10
    Query2:
    select count(Member_ID) from
    select Member_ID from T1
    union
    select Member_ID from T2
    union
    union
    select Member_ID from T10
    The columns c2 to c100 in Query 1 involve a lot of cast statements. Query 1 takes about 81 seconds and Query 2 takes only about 1/4 second – which is a big difference. These 2 queries are equivalent in terms of what the would return. The reason I am doing Query 1 is because I want the inner query to be a view.
    My question is does anyone know if Oracle 10 would be smart enough to 'forget' about columns c2 to c100 in Query 1 as they are not needed in Query 1? Could the execution times of the 2 queries be similar in Oracle 10?
    Please don't ask me to see the whole queries as they too big and beside the point.

    Denis,
    The answer to your question is that Oracle is smart
    enough to know it simply cannot 'forget' columns c2
    until c100. The fact that in your case both the
    queries return the same result, does not mean the two
    are semantically equivalent.
    In query 1 you use a union operator, meaning it has
    to do a SORT UNIQUE step. In other words: only when
    the rows (member_ID,c2,c3,...,c100) are completely
    identical they will be merged. In query 2 the rows
    only get merged when member_ID's are identical.
    Regards,
    Rob.Thanks for your help! I didn't think about that! In this case the Member_ID is unique (but I didn't say that from the outset). I'm going to try this thing over using Union All instead of Union. If that doesn't help me - I may write back with an update on the post...

Maybe you are looking for