MERGE JOIN Cartesian help

Hi all

I have a problem in writing the query below. The following query always shows a MERGE JOIN CARTESIAN in the plan to explain due to which the execution of the query takes a long time (almost 2 hours for 1,000 records).

I use "Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi. Please advice if I need to provide more information on that.
Select to_char(a.amnt_date,'DD-MON-YYYY') amnt_date, 
       SUM(a.AMNT_CON) amount
from amount a, 
     (SELECT area_no  
         FROM (SELECT * 
                  FROM area_usage 
                  WHERE area_hier_no = '201064') 
      CONNECT BY area_par_no = PRIOR area_no 
      START WITH area_no in (SELECT area_no 
                                FROM area 
                                WHERE area_code in ('EQ'))) b,
     (SELECT acc_no
         FROM (SELECT * 
                 FROM acc_usage 
                WHERE acc_hier_no = '1') 
      CONNECT BY acc_par_no = PRIOR acc_no 
      START WITH acc_no = 202917) c --  Account Hierarchy
where a.area_no = b.area_no 
   AND a.acc_no = c.acc_no
GROUP BY a.amnt_date
-----

PLAN_TABLE_OUTPUT

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hash value of plan: 2492729134

-----------------------------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |
-----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 692. 22144 | 3327 (32) | 00:00:40 |
| 1. HASH GROUP BY. 692. 22144 | 3327 (32) | 00:00:40 |
| 2. TABLE ACCESS BY LOCAL INDEX ROWID | AMOUNT | 138. 2898. 3326 (32) | 00:00:40 |
| 5: NESTED LOOPS | 692. 22144 | 3326 (32) | 00:00:40 |
| 4. THE CARTESIAN MERGE JOIN. 5. 55. 13 (0) | 00:00:01 |
| 5. VIEW | 1. 5. 5 (0) | 00:00:01 |
|* 6 | CONNECT BY WITH FILTERING |
| 7. TABLE ACCESS BY INDEX ROWID | ACC_USAGE | 1. 24. 2 (0) | 00:00:01 |
|* 8 | INDEX UNIQUE SCAN | ACU_PK | 1 | | 1 (0) | 00:00:01 |
| 9. NESTED LOOPS |
| 10. CONNECT PUMP |
| * 11 | TABLE ACCESS BY INDEX ROWID | ACC_USAGE | 1. 14. 5 (0) | 00:00:01 |
| * 12 | INDEX RANGE SCAN | ACU_AH_HAVE_AS_PARENT_FK_I | 4 | | 1 (0) | 00:00:01 |
| 13. KIND OF BUFFER. 5. 30. 13 (0) | 00:00:01 |
| 14. VIEW | 5. 30. 8 (0) | 00:00:01 |
| * 15 | CONNECT BY WITH FILTERING |
| * 16. TABLE ACCESS BY INDEX ROWID | AREA_USAGE |
| 17. NESTED LOOPS | 1. 32. 2 (0) | 00:00:01 |
| 18. TABLE ACCESS BY INDEX ROWID | AREA | 1. 21. 2 (0) | 00:00:01 |
| * 19. INDEX UNIQUE SCAN | AR_AR2_UK | 1 | | 1 (0) | 00:00:01 |
| * 20. INDEX UNIQUE SCAN | AU_PK | 8608. 94688 | 0 (0) | 00:00:01 |
| 21. NESTED LOOPS |
| 22. CONNECT PUMP |
| * 23. TABLE ACCESS BY INDEX ROWID | AREA_USAGE | 5. 85. 8 (0) | 00:00:01 |
| * 24. INDEX RANGE SCAN | ARU_APN_FKI | 8 | | 1 (0) | 00:00:01 |
| 25. RANGE OF PARTITION ALL THE | 1. 60.
| 26. CONVERSION OF BITMAP IN ROWID |
| 27. BITMAP AND |
| 28. CONVERSION OF BITMAP OF ROWID |
| * 29. INDEX RANGE SCAN | A_ARH_FK_I | 194K | 134 (7) | 00:00:02 | 1. 60.
| 30. CONVERSION OF BITMAP OF ROWID |
| * 31. INDEX RANGE SCAN | A_AH_FK_I | 194K | 488 (41) | 00:00:06 | 1. 60.
-----------------------------------------------------------------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):
---------------------------------------------------

6 - access("ACC_USAGE".") ACC_PAR_NO "="ACC_USAGE"ADVANCE." ACC_NO")
8 - access("ACC_USAGE".") ACC_NO "= 202917 AND ACC_HIER_NO" = 1) «»
11 - filter ("ACC_HIER_NO" = 1)
12 - access("ACC_USAGE".") ACC_PAR_NO "="ACC_USAGE"ADVANCE." ACC_NO")
15 - access("AREA_USAGE".") AREA_PAR_NO "="AREA_USAGE"ADVANCE." AREA_NO')
16 - filter ("AREA_HIER_NO" = 201064)
19 - access ("AREA_CODE" = 'EQ')
20 - access ("AREA_HIER_NO"= "AREA_USAGE" AND 201064." AREA_NO "=" AREA_NO")
23 - filter ("AREA_HIER_NO" = 201064)
24 - access("AREA_USAGE".") AREA_PAR_NO "="AREA_USAGE"ADVANCE." AREA_NO')
29 - access("A".") AREA_NO '=' B '. ("' AREA_NO")
31 - access("A".") ACC_NO '=' C '. ("' ACC_NO")

54 selected lines.

Published by: Williams James Henderson on October 14, 2010 05:31

It is a very small difference, and I don't expect to cause huge changes in an execution plan. Either way to collect statistics, you would use the DBMS_STATS package.

Furthermore, your "formatted" execution plan is not exactly readable in your message.

Looking at your request a little more closely, I recommend you remove the SELECT * from subqueries. Something like that may be sufficient:

Select to_char(a.amnt_date,'DD-MON-YYYY') amnt_date,
       SUM(a.AMNT_CON) amount
from amount a,
     (SELECT area_no
         FROM (SELECT area_no
                    , area_par_no
                  FROM area_usage
                  WHERE area_hier_no = '201064')
      CONNECT BY area_par_no = PRIOR area_no
      START WITH area_no in (SELECT area_no
                                FROM area
                                WHERE area_code in ('EQ'))) b,
     (SELECT acc_no
         FROM (SELECT acc_no
                    , acc_par_no
                 FROM acc_usage
                WHERE acc_hier_no = '1')
      CONNECT BY acc_par_no = PRIOR acc_no
      START WITH acc_no = 202917) c --  Account Hierarchy
where a.area_no = b.area_no
   AND a.acc_no = c.acc_no
GROUP BY a.amnt_date

A SELECT statement using * and not at a later time using all the columns hides valuable information from Oracle. If you provide only the columns used Oracle may be able to find a better plan of execution.

Given that I don't know the structures of table if you can actually use all the columns. I still recommend the amendment because I think that it makes the code easier to understand.

Tags: Database

Similar Questions

  • Is the merge join Cartesian intensibe more CPU than nested loops?

    Hello
    just wonderning which access method is more intensive CPU, supposed to leave we got 2 the same rank sources and make joing via merge join Cartesian and then case is nested loop.
    I know that nl can be CPU due to the tight loop access, but what abour MJC?
    I can see bufferd sort but not sure is that cpu friendly?
    Concerning
    GregG

    The simplest answer I think is "it depends on the situation." Two of them could be disaster in different situations. Nested loops are suitable for a type of join and Cartesian for another.

  • is "join Cartesian" identical "merge join Cartesian"?

    Hi guys,.

    my plan to explain said the Cartesian merge join
    [Oracle documentation | http://download-west.oracle.com/docs/cd/B10500_01/server.920/a96533/optimops.htm#45485] speaks of Cartesian join

    Are these two the same?

    Thank you

    Hello

    Both are the same but the NAP differs from 9i to 10g, since according to the algorithm basedon Version in! 0 g's
    Kind of buffer.

    Look at the example of wirh links.

    http://www.juliandyke.com/optimisation/operations/MergeJoinCartesian.html
    http://www.akadia.com/services/ora_interpreting_explain_plan.html

    -Pavan Kumar N

  • the group causing a Cartesian merge join?

    Hi all
    Database Version: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    Database Version: PL/SQL Release 10.2.0.5.0 - Production
    I wrote a query that runs in less than a second and produced a few hundred lines (as you can see below). I wanted only to find the number of separate incidents ID returned so I put a group by at the end and it ran forever.

    I realized a plan to explain (as shown below) to the query with the group inside and he tries to make a Cartesian join!

    A WTF happening? I've never known a group by statement before.

    basic structure of the tables is the following:
    SQL> desc answer_master
     Name                                                                     Null?    Type
     ------------------------------------------------------------------------ -------- -----------------
     ANSWER_ID                                                                NOT NULL NUMBER(12)
     INCIDENT_ID                                                              NOT NULL NUMBER(12)
     PLAN_ID                                                                  NOT NULL NUMBER(12)
     QUESTION_ID                                                              NOT NULL NUMBER(12)
    
    SQL> desc question_master
     Name                                                                     Null?    Type
     ------------------------------------------------------------------------ -------- -----------------
     QUESTION_PLAN_ID                                                         NOT NULL NUMBER(12)
     QUESTION_ID                                                              NOT NULL NUMBER(12)
     QUESTION_TYPE                                                            NOT NULL NUMBER(2)
     QUESTION_TEXT                                                            NOT NULL VARCHAR2(255)
     QUESTION_PARENT_ID                                                                NUMBER(12)
    the SQL statement
    SQL> explain plan for
      2  select incident_id
      3    from answer_master am
      4   where exists (select 'x'
      5                   from answer_master am1
      6                  where question_id in (select question_id
      7                               from question_master qms
      8                              where question_plan_id = 1477
      9                                and question_parent_id = 69067
     10                                and substr(question_text,-3) = 'PDF')
     11                    and am1.incident_id = am.incident_id)
     12    and exists (select 'x'
     13                   from answer_master am1
     14                  where question_id in (select question_id
     15                               from question_master qms
     16                              where question_plan_id = 1477
     17                                and question_parent_id = 69067
     18                                and substr(question_text,-3) != 'PDF')
     19                    and am1.incident_id = am.incident_id);
    
    Explained.
    
    Elapsed: 00:00:00.01
    SQL> set linesize 132;
    SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
    
    PLAN_TABLE_OUTPUT                                                                                                                   
    ------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 1710257923                                                                                                         
                                                                                                                                        
    ----------------------------------------------------------------------------------------------------------                          
    | Id  | Operation                        | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |                          
    ----------------------------------------------------------------------------------------------------------                          
    |   0 | SELECT STATEMENT                 |                       |     1 |    32 |   171   (6)| 00:00:01 |                          
    |*  1 |  HASH JOIN RIGHT SEMI            |                       |     1 |    32 |   171   (6)| 00:00:01 |                          
    |   2 |   VIEW                           | VW_SQ_2               |    71 |   923 |    70   (5)| 00:00:01 |                          
    |   3 |    NESTED LOOPS                  |                       |    71 |  3266 |    70   (5)| 00:00:01 |                          
    |*  4 |     TABLE ACCESS BY INDEX ROWID  | QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                          
    |*  5 |      INDEX RANGE SCAN            | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                          
    |*  6 |     INDEX RANGE SCAN             | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                          
    |   7 |   NESTED LOOPS                   |                       |   304 |  5776 |   100   (5)| 00:00:01 |                          
    |   8 |    VIEW                          | VW_SQ_1               |    14 |   182 |    70   (5)| 00:00:01 |                          
    |   9 |     HASH UNIQUE                  |                       |    14 |   644 |            |          |                          
    |  10 |      NESTED LOOPS                |                       |    14 |   644 |    70   (5)| 00:00:01 |                          
    |* 11 |       TABLE ACCESS BY INDEX ROWID| QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                          
    |* 12 |        INDEX RANGE SCAN          | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                          
    |* 13 |       INDEX RANGE SCAN           | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                          
    |* 14 |    INDEX RANGE SCAN              | ANSWER_MASTER_QID_IX3 |    22 |   132 |     2   (0)| 00:00:01 |                          
    ----------------------------------------------------------------------------------------------------------                          
                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                 
    ---------------------------------------------------                                                                                 
                                                                                                                                        
       1 - access("ITEM_2"="AM"."INCIDENT_ID")                                                                                          
       4 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)!='PDF')                                                        
       5 - access("QUESTION_PARENT_ID"=69067)                                                                                           
       6 - access("QUESTION_ID"="QUESTION_ID")                                                                                          
      11 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)='PDF')                                                         
      12 - access("QUESTION_PARENT_ID"=69067)                                                                                           
      13 - access("QUESTION_ID"="QUESTION_ID")                                                                                          
      14 - access("ITEM_1"="AM"."INCIDENT_ID")                                                                                          
    
    33 rows selected.
    
    Elapsed: 00:00:00.06
    SQL> explain plan for
      2  select incident_id
      3    from answer_master am
      4   where exists (select 'x'
      5                   from answer_master am1
      6                  where question_id in (select question_id
      7                               from question_master qms
      8                              where question_plan_id = 1477
      9                                and question_parent_id = 69067
     10                                and substr(question_text,-3) = 'PDF')
     11                    and am1.incident_id = am.incident_id)
     12    and exists (select 'x'
     13                   from answer_master am1
     14                  where question_id in (select question_id
     15                               from question_master qms
     16                              where question_plan_id = 1477
     17                                and question_parent_id = 69067
     18                                and substr(question_text,-3) != 'PDF')
     19                    and am1.incident_id = am.incident_id)
     20  group by incident_id;
    
    Explained.
    
    Elapsed: 00:00:00.00
    SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
    
    PLAN_TABLE_OUTPUT                                                                                                                   
    ------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 1433543102                                                                                                         
                                                                                                                                        
    -----------------------------------------------------------------------------------------------------------                         
    | Id  | Operation                         | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |                         
    -----------------------------------------------------------------------------------------------------------                         
    |   0 | SELECT STATEMENT                  |                       |     1 |    98 |    77   (6)| 00:00:01 |                         
    |   1 |  HASH GROUP BY                    |                       |     1 |    98 |    77   (6)| 00:00:01 |                         
    |   2 |   NESTED LOOPS                    |                       |     1 |    98 |    76   (4)| 00:00:01 |                         
    |   3 |    NESTED LOOPS                   |                       |     1 |    87 |    74   (5)| 00:00:01 |                         
    |   4 |     NESTED LOOPS                  |                       |     1 |    81 |    72   (5)| 00:00:01 |                         
    |   5 |      MERGE JOIN CARTESIAN         |                       |     1 |    70 |     4   (0)| 00:00:01 |                         
    |*  6 |       TABLE ACCESS BY INDEX ROWID | QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                         
    |*  7 |        INDEX RANGE SCAN           | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                         
    |   8 |       BUFFER SORT                 |                       |     1 |    35 |     2   (0)| 00:00:01 |                         
    |*  9 |        TABLE ACCESS BY INDEX ROWID| QUESTION_MASTER       |     1 |    35 |     2   (0)| 00:00:01 |                         
    |* 10 |         INDEX RANGE SCAN          | QUESTION_MASTER_IX1   |     3 |       |     1   (0)| 00:00:01 |                         
    |* 11 |      INDEX RANGE SCAN             | ANSWER_MASTER_QID_IX2 | 18731 |   201K|    68   (5)| 00:00:01 |                         
    |* 12 |     INDEX RANGE SCAN              | ANSWER_MASTER_QID_IX3 |    22 |   132 |     2   (0)| 00:00:01 |                         
    |* 13 |    INDEX RANGE SCAN               | ANSWER_MASTER_QID_IX2 |     1 |    11 |     2   (0)| 00:00:01 |                         
    -----------------------------------------------------------------------------------------------------------                         
                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                 
    ---------------------------------------------------                                                                                 
                                                                                                                                        
       6 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)='PDF')                                                         
       7 - access("QUESTION_PARENT_ID"=69067)                                                                                           
       9 - filter("QUESTION_PLAN_ID"=1477 AND SUBSTR("QUESTION_TEXT",-3)!='PDF')                                                        
      10 - access("QUESTION_PARENT_ID"=69067)                                                                                           
      11 - access("QUESTION_ID"="QUESTION_ID")                                                                                          
      12 - access("AM1"."INCIDENT_ID"="AM"."INCIDENT_ID")                                                                               
      13 - access("QUESTION_ID"="QUESTION_ID" AND "AM1"."INCIDENT_ID"="AM"."INCIDENT_ID")                                               
    
    31 rows selected.
    
    Elapsed: 00:00:00.00
    SQL> spool off
    Edit: change superiors--more/less to signs of! = to display the Forum

    Published by: WhiteHat on February 11, 2011 09:37

    In addition, if you are interested in rewriting so I think this might be an alternative (untested):

          select am1.incident_id
          from   answer_master am1
          ,      question_master qms
          where  am1.question_id        = qms.question_id
          and    qms.question_plan_id   = 1477
          and    qms.question_parent_id = 69067
          group by am1.incident_id
          having max(case when substr(qms.question_text,-3) = 'PDF' then 1 else 0 end) !=
                 min(case when substr(qms.question_text,-3) = 'PDF' then 1 else 0 end);
    
  • join query help

    Hello everyone, I kindly need help with a query that I'm writing. I think it's supposed to be some kind of join, but I'm a little uncertain. Here is an example:

    Select a.person_id, a.company, b.name, e.element, f.value
    of a, b, e, f
    where a.person_id = b.person_id
    and e.el_id = f.el_id
    -e.t.c

    Lets say this returns

    person_id, company, name, element value
    ------------------------------------------------------
    1 vol., krog, breakfast, 34
    2, mols, flog, munch, 24

    The problem is now the table e. I want to get all the e table values that meet certain criteria. As in:

    Select e.element
    where e.name = "RATED."

    Lets say this returns

    element
    -----------
    food
    lunch
    Munch

    And combine it with the query at the top of the page. But I also want to show all the other values, a.person_id, a.company, b.name for each line.
    So my goal is to finally have:

    person_id, company, name, element value
    ------------------------------------------------------
    1 vol., krog, breakfast, 34
    1 vol., krog, food, 0
    1 vol., krog, munch, 0
    2, mols, flog, munch, 24
    2, mols, flog, food, 0
    2, mols, flog, 0

    It's to have a default value of zero, where no join does exist for the value and do not duplicate anything even if I could always use separate.
    Can anyone help with this?
    with t1 as (
                select a.person_id, a.company, b.name, e.element, f.value
                  from a, b, e, f
                  where a.person_id = b.person_id
                  and e.el_id = f.el_id
                  -- e.t.c
               ),
         t2 as (
                select e.element
                 where e.name = 'EVALUE'
               )
    select  person_id,
            company,
            name,
            t2.element,
            sum(
                case t1.element
                  when t2.element then value
                  else 0
                end
               ) value
      from  t1,
            t2
      group by person_id,
               company,
               name,
      order by person_id,
               company,
               name,
               t2.element
    /
    

    For example:

    with t1 as (
                select 1 person_id, 'Vols' company, 'krog' name, 'lunch' element, 34 value from dual union all
                select 2, 'Mols', 'flog', 'munch', 24 from dual
               ),
         t2 as (
                select 'food' element from dual union all
                select 'lunch' from dual union all
                select 'munch' from dual
               )
    select  person_id,
            company,
            name,
            t2.element,
            sum(
                case t1.element
                  when t2.element then value
                  else 0
                end
               ) value
      from  t1,
            t2
      group by person_id,
               company,
               name,
               t2.element
      order by person_id,
               company,
               name,
               t2.element
    /
    
     PERSON_ID COMP NAME ELEME      VALUE
    ---------- ---- ---- ----- ----------
             1 Vols krog food           0
             1 Vols krog lunch         34
             1 Vols krog munch          0
             2 Mols flog food           0
             2 Mols flog lunch          0
             2 Mols flog munch         24
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • Join logic help

    I'm having trouble with the logic of the join of a particular query, which is modelled with the following (very simplified):
    create table a(
        a_id number,
        constraint pk_a primary key(a_id));
    
    create table b(
        b_id number,
        a_id number,
        constraint pk_b primary key(b_id),
        constraint fk_b_a foreign key(a_id) references a(a_id));
    
    create table c(
        c_id number,
        b_id number,
        constraint pk_c primary key(c_id),
        constraint fk_c_b foreign key(b_id) references b(b_id));
    
    insert into a values(1);
    insert into a values(2);
    
    insert into b values(1,1);
    insert into b values(2,1);
    insert into b values(3,2);
    insert into b values(4,2);
    
    insert into c values(1,1);
    insert into c values(2,2);
    insert into c values(3,3);
    There may be records 1 several 'b' associated with each record 'a' and 'b' and 'c' have a 1-1 relationship. What query selects only the records 'a' who have all THE related records 'b' listed in the 'c '? In light of these data, the query must return only "a = 1", since the two "b = 1" and "b = 2" are included in the 'c'. " However, he wasn't "a = 2", since the two "b = 3" and "b = 4" are not contained in 'c'. " The results should be:
    OUTPUT:
        a_id
        ----
        1

    Hello

    Here's one way:

    SELECT       a.a_id
    FROM           a
    JOIN           b  ON  a.a_id     = b.a_id
    LEFT OUTER JOIN      c  ON     b.b_id     = c.b_id
    GROUP BY  a.a_id
    HAVING       COUNT (b.b_id)  = COUNT (c.b_id)
    ;
    

    Most of the things you can do with IN subqueries are also possible with joins or subqueries EXISTS. (Most of the things that can be made with EXISTS subqueries can also be open joins or subqueries.) However, there many things that can be done only with joins.)
    If you don't like one, try the other.

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.
    Don't forget to post the results you want from this data, regardless of how simple are these results and your version of Oracle.

  • Table join Insert help?

    Hi guys,.

    Basily, I need to update simply null 'start_date' (s) in TableB, with (s) 'start_date' from TableA.

    Joining tables by claim_no.

    I tried alog the lines of this:

    INSERT INTO TableB.start_date
    SELECT TableA.start_date FROM TableB INNER JOIN TableA
    ON TableA.Claim_no = TableB.Claim_no
    WHERE TableB.start_date is null


    But his return "column ambiguously defined".

    :-/

    Any suggestions? IM prob away from the brand here!

    Thank you JPM

    You need update instead of INSERTION

    UPDATE TableB
      SET start_date = ( SELECT TableA.start_date
                           FROM TableA INNER JOIN TableB
                             ON TableA.Claim_no = TableB.Claim_no
                       )
    WHERE start_date is null
    

    Concerning
    Arun

  • Outer join to help between

    Hello

    Does anyone know why this outer join does not...
    [
       AND TRUNC (SYSDATE) BETWEEN eh.emp_hhold_start_date AND eh.emp_hhold_stop_date (+)   
    but they don't...
    AND TRUNC (SYSDATE) >= eh.emp_hhold_start_date (+) 
    AND TRUNC (SYSDATE) <= eh.emp_hhold_stop_date  (+)
    Thank you
    Christine
    AND TRUNC (SYSDATE) BETWEEN eh.emp_hhold_start_date(+) AND eh.emp_hhold_stop_date (+)
    ---------------------------------------------------^^^
    

    You are missing the outer join operator

  • I can't open my firefox. whenever I open it, the window is not open, open at any time error saying that "firefox does ' t work join" Please help me beacause I don't other browser... Please... Please

    Respected Sir, m

               i only like mozilla firefox browser. but few day ago my system is automatically shutdown. when i restart my system then my firefox is does't open and if it is open then error message is generated. so i can't use my mozilla firefox.
            my all programm run perfectly expect mozilla firefox. please solve my problem as soon as possible.
    

    Hello

    You can try to install Firefox on one currently installed: https://www.mozilla.org/en-US/firefox/new/

  • Outer Join Q - Help pls

    Hi guys,.
    I hope everyone had a nice Easter. I have a question about my request. Here are my paintings,
    STUDENT TABLE:
    ID               NAME
    123             JIM SMITH
    456             KEN TWIST
    
    EMAIL_TABLE:
    ID              EMAIL_CODE           EMAIL_ADDRESS
    123            AA                         [email protected]
    123            AA                         [email protected]
    123            BB                         [email protected]
    456            BB                        [email protected] 
    
    OUTPUT:
    ID      NAME           EMAIL_ADDY1     EMAIL_ADDY2
    123   JIM SMITH     [email protected]   [email protected]
    456   KEN TWIST   
    Here's my query:
    select s.ID,
             s.NAME
             max(a.EMAIL_ADDRESS) email_addy1,
             min(b.EMAIL_ADDRESS) email_addy2
      from student s, email_tab a, email_tab b
     where a.id = s.id
       and a.email_code = 'AA'
       and b.id = s.id
       and b.email_code = 'AA'
       and a.id = b.id
       and a.email_code = b.email_code
    group by ID, NAME
    My question is, with this query, I get only students who has a code of 'AA' e-mail, I also want to show students without the 'AA' code, but e-mail will be empty.

    Thank you very much.


    Amy

    Published by: user5737516 on April 12, 2012 07:12

    One way, which is a slight adaptation of your code...

    select s.ID,
             s.NAME
             max(case when a.email_code = 'AA' then a.EMAIL_ADDRESS else null end) email_addy1,
             min(case when b.email_code = 'AA' then b.EMAIL_ADDRESS else null end) email_addy2
      from student s, email_tab a, email_tab b
     where a.id = s.id
       and b.id = s.id
       and a.id = b.id
       and a.email_code = b.email_code
    group by ID, NAME
    
  • The self-join query help

    Hello people,
    I have the MENU table on 9i with the following fields:

    MENU_ID, PARENT_ID, NOMMENU...

    and some sample data:

    0,999999, ROOT
    7.0, NETWORK
    6.0, SERVICES
    100.0, CUSTOMERS
    74.7, MONITORING
    88889081,7, CONFIG
    88890006,7, TEST
    88890049,7 II TEST
    88889163,6, MAIL
    61.6, SMS
    ...
    ...
    ...

    Thus PARENT_ID shows in which menu the submenu is.

    I need to create the sub report:
    ROOT
    * NETWORK
    * THE CONFIG
    * TEST
    * TEST II
    * SERVICES
    * MAIL
    * SMS
    * CUSTOMERS

    Stars or any other way to identify the depth level will be very handful.

    Thank you in advance.

    Hello

    Try to connect with this example on the emp table.

    select empno,ename,level,sys_connect_by_path(ename,'/') as path
    from emp
    start with mgr is null
    connect by prior empno=mgr
    

    Output
    ------------

    EMPNO ENAME LEVEL PATH
    7839  KING      1       /KING
    7566  JONES    2      /KING/JONES
    7788  SCOTT   3      /KING/JONES/SCOTT
    7876  ADAMS   4      /KING/JONES/SCOTT/ADAMS
    7902  FORD     3      /KING/JONES/FORD
    7369  SMITH    4     /KING/JONES/FORD/SMITH
    7698  BLAKE    2     /KING/BLAKE
    7499  ALLEN    3     /KING/BLAKE/ALLEN
    7521  WARD    3    /KING/BLAKE/WARD
    7654  MARTIN  3    /KING/BLAKE/MARTIN 
    

    It may be useful
    CKLP

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    
  • The XML parsing returns a Cartesian join

    I have the following table:
    CREATE A TEMP_XML OF THE SYS. XMLTYPE
    TABLESPACE HPS_LND_DATA
    VARRAY XMLDATA AS LOB STORE
    (
    ALLOW ONLINE STORAGE
    8192 CHUNK
    RETENTION
    AVERAGE COMPRESSION
    CACHE
    INDEX)
    TABLESPACE HPS_LND_DATA)
    )
    NOPARALLEL
    /

    Each record in the table has the following XML structure:
    < c id = "MMLab" t = "2009-10-25 12:02:00 AM" >
    < d >
    < nv n = v 'BootRomVersion' = "1.1505" / >
    < n nv v="1.6.25075.203"/ "ClientVersion" = >
    < nv n = v "CurrentTime" = "2009-10-25 12:02:00 AM" / >
    < nv n = v "LastRebootTime" = "09/10/2009 15:32:53" / >
    < nv n = v 'CPUSpeed' = "297" / >
    < nv n = v "ServiceID" = "" / >
    < nv n = v 'AvailablePhysicalMemory"="17502208"/ >
    < nv n = v 'AvailableVirtualMemory"="8519680"/ >
    < nv n = v "AllocatedPhysicalMemory" = "22003712" / >
    < nv n = v "AllocatedManagedMemory" = "2898136" / >
    < nv n = v "CommittedHeapMemory" = "1511424" / >
    < nv n = v "AllocatedHeapMemory" = "1387584" / >
    < nv n = v 'HeapEfficiency' = '91' / >
    < nv n = v "AvailableVideoMemory" = "5052864" / >
    < nv n = v "DrivePresent" = "True" / >
    < nv n = v "DiskSizeInMB" = "305082" / >
    < nv n = v 'DiskFreeInMB' = "21369" / >
    < nv n = v 'DvrSizeInMB' = "283648" / >
    < nv n = v "PercentDvrFree" = "100" / >
    / < d: >
    / < c >

    I am using the following query:
    SELECT EXTRACT (object_value, ' /c/@id').getstringval () AS ID,)
    To_date (EXTRACT (object_value, ' /c/@t').getstringval (),))
    "(mm/dd/yyyy hh: mi: ss AM') AS TIMESTAMP,
    EXTRACT (VALUE (li), ' /nv/@n').getstringval () AS xml_parm,)
    VALUE (li). EXTRACT (' (/nv/@v').getstringval) AS xml_value, li.*)
    OF temp_xml, TABLE (XMLSEQUENCE (EXTRACT (object_value, "/ c/d/nv"))) li

    The application of works very well if I limit the output to a single record in the temp_xml table, but if I ask more than one record I get a Cartesian result, how can I fix?

    You shouldn't have to join here.

    You can see from the output that is a mistake and you get a Cartesian product?

    Or are you unnecessarily worry a MERGE JOIN CARTESIAN and a SORT of BUFFER in the execution plan?

  • Dictionary stats help?

    DBA dear friends,

    In my 11.1.0.7 database, I have an ID of SQL which contributes about 100 reads physical Mil a day in the database, he ran 85 times in the 24 hour period.

    Here is the SQL - it accesses the SYSTEM tables and EM monitors query type, and is not a request part of the application-

    Dictionary collection stats help reduced the physical reads? Or any other point of view that what must be considered?

    Is it still worth to try tuning the query?  Please share your entries...

    SELECT 'AQ_Messages_in_Expired' t. *
    Of
    (select q. owner | | '.' | | q . name , v. expired
    de v$aq v, dba_queues q

    v. QID = q. QID and q. owner not in ('SYS','SYSTEM','WMSYS') and q. QID not in (206397, 206398, 206325)) t

    I don't see a MERGE JOIN CARTESIAN, which is good.  I do not see a stage for fixed table and it MIGHT help generate fixed objects statistics:

    exec dbms_stats.gather_fixed_objects_stats (null)

    You can see if they have been already generated by querying the SYS. TAB_STATS$:

    Select count (*) in the sys.tab_stats$;

    If it is empty then stats fixed objects have not been met.  Stats of $ service must be collected by the work of database statistics 'standard '.  You can collect these stats and run the query again to see if the run time is improving.  You can also check when the last statistics, what are the sample sizes and how closely NUM_ROWS agrees with a count (*) current tables questioned.

    David Fitzjarrell

  • Cartesian product in Select

    Hi all!

    I need help.

    I have this function that launches a Select statement. My Oracle Grid tells me, when I adjust the selection of this function, it is a Cartesian product. I understand what is a Cartesian product, but I can't seem to find it. Can you help me by pointing out WHERE is the misteke? Thank you!!

    PS EA Oracle 10.2.0.4 on windows Server 2003 R2 SP2 64-bit

    [code]

    create or replace

    FUNCTION "ANA_GETVERBALE".

    (

    v_VerbaleId in NUMBERS by DEFAULT NULL,

    v_Sezione IN VARCHAR2 DEFAULT NULL,

    v_NumeroVerbale IN VARCHAR2 DEFAULT NULL,

    v_DataVerbale DATE by 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 FOR Cv_1

    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

    OF ANA_Materia_Verbale ANA_M

    INNER JOIN SCH_Cartellini SCH_C on SCH_C.SoggettoId is 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]

    While it's complained the Cartesian product?

    Or is it just the fact that you've seen "MERGE JOIN CARTESIAN" in your plan to explain?

    If so, read this...

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4105951726381

  • Cartesian fusion

    Hello

    I have the underside of DEC, fine for a Merge-Cartesian join,

    I checked the where the join clause looks fine for me and the paintings are also analyzed and statistics ok for me.

    It is because of the missing join index? Can you please help?

    CREATE TABLE sas_stage. SAS_ONLY_DGNS_2008 tablespace sas_stage_data parallel 8 nologging PARTITION BY LIST (PARTN_NAME)
    (
    C01 PARTITION VALUES ("C01"),
    C02 PARTITION VALUES ("C02"),
    C03 PARTITION VALUES ("C03"),
    C08 PARTITION VALUES ('C08'),
    C09 PARTITION VALUES ('C09'),
    C10 PARTITION VALUES ('C10'),
    C11 PARTITION VALUES ('C11'),
    C12-PARTITION VALUES ("C12"),
    C14 PARTITION VALUES ('C14"),
    C15 PARTITION VALUES ("C15"),
    C16 PARTITION VALUES ('C16'),
    C17 PARTITION VALUES ('17'),
    C18 PARTITION VALUES ('C18'),
    C19 PARTITION VALUES ('C19'),
    "PARTITION VALUES C20 ("C20")) as).
    Select / * + parallel(xr,4) parallel(t,4) full (t) full (xr) no_expand * /.
    t.run_dt,
    t.link_num,
    t.hse_b_seq,
    t.nch_clm_type_cd,
    t.bene_clm_num_eq,
    t.hse_clm_from,
    t.hse_clm_thru,
    t.hcfa_clm_proc,
    t.first_expns,
    t.last_expns,
    t.carr_clm_rcpt,
    t.ficarr_ident_nbr,
    t.carr_clm_cntl_num,
    t.hse_b_prvdr_tax_num,
    t.npi_prfrmg,
    d.dgns_cd,
    t.hcpcs_cd,
    t.hcpcs_initl_mdfr_cd,
    t.hcpcs_2nd_mdfr_cd,
    t.hse_cwfb_clm_pmt_dnl_cd,
    t.line_prcsg_ind_cd,
    t.cwfb_alow_chrg_amt,
    t.bene_birth,
    t.BENE_SEX_IDENT_CD,
    t.FINAL_CLM_TYPE_CD,
    t.HSE_B_PLC_SRVC_CD,
    t.ptb_clm_id,
    t.carr_line_prcng_lclty_cd,
    t.bene_clm_num_curr,
    substr(XR.mc_xref_otpt_fil_name,1,3) sas_stage.part_b_fact_temp_2008 partn_name t,
    (SELECT / * + full (xr) full (d) * / mc_xref_otpt_fil_name, mc_xref_clm_clmn_cd)
    OF sas_stage.sas_pqri_cd_msr_xref
    WHERE mc_xref_prod_ind = 'PQRI08' AND mc_xref_otpt_fil_name IN ('C01Cancer_Care', 'C02ENT', 'C03Other_Dgns', 'C08Cardiac_Care', 'C09Hepatitus', 'C10Repiratory_Care', 'C11Renal', 'C12Stroke', 'C14Osteoporosis', 'C15Depression', 'C16Diabetes', 'C17ER_Care', 'C18Eye_Care', 'C19Incontinence', 'C20Prostate_Cancer') AND mc_xref_clm_clmn_name IN ('DGSN")
    ) xr.
    part_b.diagnosis_dimension d
    where
    t.first_expns between to_date('01/01/2008','mm/dd/yyyy') and to_date('12/31/2008','mm/dd/yyyy') and between to_date('01/01/2008','mm/dd/yyyy') and to_date('12/31/2008','mm/dd/yyyy'), and (t.LINE_DGNS_ID = d.DGNS_ID t.last_expns
    or t.dgns_seq_1_id = d.DGNS_ID
    or t.dgns_seq_2_id = d.DGNS_ID
    or t.dgns_seq_3_id = d.DGNS_ID
    or t.dgns_seq_4_id = d.DGNS_ID
    or t.dgns_seq_5_id = d.DGNS_ID
    or t.dgns_seq_6_id = d.DGNS_ID
    or t.dgns_seq_7_id = d.DGNS_ID
    or t.dgns_seq_8_id = d.DGNS_ID
    )
    AND xr.mc_xref_clm_clmn_cd = d.dgns_cd
    )
    CREATE TABLE STATEMENT, GOAL = ALL_ROWS               209205798     70410151     17391307297
     PX COORDINATOR                         
      PX SEND QC (RANDOM)     SYS     :TQ10003     208452964     70410151     17391307297
       LOAD AS SELECT     SAS_STAGE     SAS_ONLY_DGNS_2008               
        PX RECEIVE               208452964     70410151     17391307297
         PX SEND RANDOM LOCAL     SYS     :TQ10002     208452964     70410151     17391307297
          HASH JOIN               208452964     70410151     17391307297
           PX RECEIVE               26     848160     10177920
            PX SEND BROADCAST     SYS     :TQ10000     26     848160     10177920
             PX BLOCK ITERATOR               26     848160     10177920
              TABLE ACCESS FULL     PART_B     DIAGNOSIS_DIMENSION     26     848160     10177920
           MERGE JOIN CARTESIAN               199771699     170571106808     40084210099880
            SORT JOIN                         
             PX RECEIVE               2     131     4716
              PX SEND BROADCAST     SYS     :TQ10001     2     131     4716
               PX BLOCK ITERATOR               2     131     4716
                TABLE ACCESS FULL     SAS_STAGE     SAS_PQRI_CD_MSR_XREF     2     131     4716
            BUFFER SORT               199771697     1298634519     258428269281
             PX BLOCK ITERATOR               2220601     1298634519     258428269281
              TABLE ACCESS FULL     SAS_STAGE     PART_B_FACT_TEMP_2008     2220601     1298634519     258428269281
    Thanks in advance

    user604558 wrote:
    The Cartesian fusion makes long query?

    Potential concatenation of the "GOLD" Clause was seen 8 table of part_b_fact_temp_2008 table scan with a volume of 1.7 billion of complete

    Is there any alternative for this?

    If you come with the information requested more educated suggestions can be provided, without this information, it is purely speculation.

    Yes, the Cartesian merge join might be a problem as you generate a Cartesian set of something and a table whose rows 1.7 billion, but a plan of appropriate formatting output will help to understand the question.

    Because the data in part_b_fact_temp_2008 are obviously not standardized, you might consider turning columns into rows so that an equi-join simple on the ID 'dgns_seq_id' that results can be performed.

    Of course, turning columns in lines will increase volume to join again, but you will need to analyze the large segment then only once.

    If you want to know how to turn columns online, you can search the forum here or on the internet.

    Small Tip:

    If you have denormalized a table like this:

    create table t
    (
      key varchar2(3) ,
      c1  varchar2(5) ,
      c2  varchar2(5) ,
      c3  varchar2(5)
    );
    

    You can use the following query to transform the columns c1, c2, and c3 in lines:

    select
             key
           , case
             when c.id = 1 then 'C1'
             when c.id = 2 then 'C2'
             when c.id = 3 then 'C3'
             end as source
           , case
             when c.id = 1 then c1
             when c.id = 2 then c2
             when c.id = 3 then c3
             end as val
    from
             t
           , (
             select
                        level as id
             from
                        dual
             connect by
                        level <= 3
             ) c
    ;
    

    He again produced a Cartesian merge join, but it should always be as effective as possible in t table reading only once and duplication of the lines on the fly. The request of duplicate row should produce as many lines as you have columns to transform, in your particular case, it would be 8 I guess.

    Then you would simply join the values generated using an expression simple equi-join.

    Note that there are many other ways how to make columns in lines, so it's just a suggestion.

    You should be aware that if your different ID 8 likely to result in duplicates (e.g. same ID in dgns_seq_1_id) and dgns_seq_2_id in the same line of the table not so transformed prior to transformation will lead to duplicate rows.

    In this case you must either generate a separate set that is going to be a very expensive sort operation has held the number of lines, or you can try to use an EXISTS clause instead of join. In case this may use a HASH JOIN SEMI operation, this could be more efficient than sorting.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

    Published by: Randolf Geist on April 7, 2009 10:22

    Confusing lines to the columns in the lines...

    Published by: Randolf Geist on April 7, 2009 15:59

    Added warning about possible duplicates

Maybe you are looking for