Help query rewrite

Hi
could you help me rewriting query without using joins
select * from A ,B,C
LEFT OUTER JOIN A
ON (A.account_no = B.account_no
AND C.id_type = B.id_type
AND B.value = 1) ;
thanks ,
-Raj

WHERE A.account_no = B.account_no(+)
AND C.id_type = B.id_typeIf these aren't joins what are they?

Similar Messages

  • Help with query rewrite and materialized views

    Hello everybody,
    I'm currently learning how to use Oracle (10G Enterprise) and in particular, Materialized Views.
    I seem to have a problem making the optimizer use a materialized view. I have already set the OPTIMIZER_MODE, QUERY_REWRITE_ENABLED and QUERY_REWRITE_INTEGRITY as needed.
    I need to create a materialized view for the following query:
    Q1:
    SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
    and PS_SUPPCOST =
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY)'
    I created it using the following code:
    CREATE MATERIALIZED VIEW mv_q1
    ENABLE QUERY REWRITE
    AS SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E JOIN PART ON (PS_PARTKEY=P_PARTKEY)
    WHERE lower(P_COMMENT) LIKE '_o_a%' or lower(P_COMMENT) LIKE '_o_u%'
    and PS_SUPPCOST=
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY);
    I have created the statistics using:
    execute dbms_stats.gather_table_stats('frandres',' mv_q1');
    execute dbms_stats.gather_table_stats('frandres','PARTSUPPLIER');
    execute dbms_stats.gather_table_stats('frandres','PART');
    Both partsupplier and part are tables and not views.
    When executing Q1, the plan does not use the materialized view. Furthermore, when using explain rewrite:
    DECLARE
    qrytxt VARCHAR2(3000) := 'SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
    and PS_SUPPCOST =
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY)';
    BEGIN
    dbms_mview.EXPLAIN_REWRITE
    (qrytxt,'MV_Q1','MV_Q1');
    END;
    I get the following message:
    MESSAGE
    QSM-01150: query did not rewrite
    QSM-01263: query rewrite not possible when query references a dictionary table o
    r view
    QSM-01219: no suitable materialized view found to rewrite this query
    What I can't understand is why it says I am referencing the dictionary or a view?
    If I remove the (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'') condition to the query (using the same materialized view), I get the following message from EXPLAIN_REWRITE:
    MESSAGE
    QSM-01150: query did not rewrite
    QSM-01219: no suitable materialized view found to rewrite this query
    Which is reasonable.
    I don't know if the like condition is messing up my materialized view. Can anyone please help?
    Thanks a lot in advance.
    Edited by: user12072111 on Oct 29, 2009 9:43 PM

    Bingo!
    The 10.2.0.3 patch set is supposed to fix this ( [List of bugs fixed (MVs)|http://www.dbatools.net/doc/bug10203.html#MVIEW] )
    In particular:
    5052568      Query rewrite does not work for SQL with LIKE clause.
    Thank you very much for your message!
    The downside is that I'm only using Oracle for educational purposes and consequently have no Metalink id, so I can't install the patch. Thanks a lot though!

  • Help to rewrite the query --performance issue

    Hi ,
    Please help to rewrite the query since it's performance is not good.Especially second inline query(CASE statements are therein select caluse ..)is taking more cost.
    Database Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    SELECT *
    FROM
      (SELECT q.*,
        COUNT(*) OVER() AS record_count,
        ROWNUM          AS row_num
      FROM
        (SELECT ExName.examiner_code,
          examiner_name,
          :v_year,
          :v_month,
          count_fb,
          NVL(count_entered_fb, 0) count_entered_fb,
          NVL(count_sent_fb, 0) count_sent_fb,
          NVL(count_edited_fb, 0) count_edited_fb,
          NVL(count_complete_fb, 0) count_complete_fb,
          NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb
        FROM
          (SELECT examiner_code,
            COUNT(*) AS count_fb
          FROM
            (SELECT
                        examiner_code,
              paper_code,
              assessment_school
            FROM
              ( SELECT DISTINCT ce.examiner_code,
                ce.paper_code,
                ce.assessment_school
              FROM
                (SELECT
                  DISTINCT assessment_school,
                  paper_code,
                  examiner_code
                FROM candidate_examiner_allocation cea
                WHERE cea.element = 'Moderation of IA'
                AND cea.year      = :v_year
                AND cea.month     = :v_month
                ) ce,
                subject_group sg,
                subject_component sc
              WHERE (:v_padded_examiner_code IS NULL
              OR ce.examiner_code            = :v_padded_examiner_code)
              AND (:v_subject_group          IS NULL
              OR sg.group_number             = :v_subject_group)
              AND sg.year                    = :v_year
              AND sg.month                   = :v_month
              AND sc.year                    = :v_year
              AND sc.month                   = :v_month
              AND sc.paper_code              = ce.paper_code
              AND sc.subject                 = sg.subject
              AND sc.lvl                     = sg.lvl
              AND (:v_subject                IS NULL
              OR sc.subject                  = :v_subject)
              AND (:v_lvl                    IS NULL
              OR sc.lvl                      = :v_lvl)
              ) ea
          GROUP BY examiner_code
          ) ExName,
          (SELECT examiner_code,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'ENTERED'
              THEN 1
              ELSE NULL
            END) AS count_entered_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'SENT'
              THEN 1
              ELSE NULL
            END) AS count_sent_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'EDITED'
              THEN 1
              ELSE NULL
            END) AS count_edited_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'COMPLETE'
              THEN 1
              ELSE NULL
            END) AS count_complete_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'WITH IBCARDIFF'
              THEN 1
              ELSE NULL
            END) AS count_withibcardiff_fb
          FROM ia_instances ia1,
            workflow_instance wfi
          WHERE wfi.instance_id = ia1.workflow_instance_id
          AND ia1.year          = :v_year
          AND ia1.month         = :v_month
          GROUP BY ia1.year,
            ia1.month,
            examiner_code
          ) iaF,
          (SELECT person_code,
            title
            || ' '
            || firstname
            || ' '
            || lastname AS examiner_name
          FROM person
          WHERE :v_examiner_name IS NULL
          OR UPPER(title
            || ' '
            || firstname
            || ' '
            || lastname) LIKE :v_search_examiner_name
          ) P
        WHERE ExName.examiner_code = iaF.examiner_code (+)
        AND ExName.examiner_code   = p.person_code
        ORDER BY ExName.examiner_code
        ) q
      ) rc
    WHERE row_num >= :v_start_row
    AND row_num   <= (:v_start_row+(:v_max_row-1));explain plan
    line 1: SQLPLUS Command Skipped: set linesize 130
    line 2: SQLPLUS Command Skipped: set pagesize 0
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 1581970599                                                                                                                                                                                                                                                                                 
    | Id  | Operation                                 | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                        
    |   0 | SELECT STATEMENT                          |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |*  1 |  FILTER                                   |                                |       |       |       |            |          |                                                                                                                                                                        
    |*  2 |   VIEW                                    |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   3 |    WINDOW BUFFER                          |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   4 |     COUNT                                 |                                |       |       |       |            |          |                                                                                                                                                                        
    |   5 |      VIEW                                 |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   6 |       SORT ORDER BY                       |                                |     1 |   119 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   7 |        NESTED LOOPS                       |                                |     1 |   119 |       |  2186   (6)| 00:00:34 |                                                                                                                                                                        
    |*  8 |         HASH JOIN OUTER                   |                                |     1 |    92 |       |  2185   (6)| 00:00:34 |                                                                                                                                                                        
    |   9 |          VIEW                             |                                |     1 |    20 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  10 |           SORT GROUP BY                   |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  11 |            VIEW                           |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  12 |             SORT UNIQUE                   |                                |     1 |   127 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  13 |              NESTED LOOPS                 |                                |     1 |   127 |       |    50   (2)| 00:00:01 |                                                                                                                                                                        
    |* 14 |               HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                        
    |* 15 |                TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                        
    |* 16 |                 INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                        
    |* 17 |                INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                        
    |* 18 |               INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |     5 |   295 |       |     6   (0)| 00:00:01 |                                                                                                                                                                        
    |  19 |          VIEW                             |                                |   679 | 48888 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |  20 |           SORT GROUP BY                   |                                |   679 | 25123 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |* 21 |            HASH JOIN                      |                                | 52408 |  1893K|  1744K|  2126   (6)| 00:00:33 |                                                                                                                                                                        
    |  22 |             TABLE ACCESS BY INDEX ROWID   | IA_INSTANCES                   | 52408 |  1125K|       |   688   (1)| 00:00:11 |                                                                                                                                                                        
    |* 23 |              INDEX RANGE SCAN             | IND_IA_INSTANCES               | 49077 |       |       |   137   (2)| 00:00:03 |                                                                                                                                                                        
    |  24 |             TABLE ACCESS FULL             | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                        
    |* 25 |         TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                        
    |* 26 |          INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                          
       8 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE"(+))                                                                                                                                                                                                                                            
      14 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      15 - filter((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL))                                                                                                                                                                                                  
      16 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      17 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter(:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP))                                                                                                                                                                                                                  
      18 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                    
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE))                                                                                                                                                                                                                                                     
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      23 - access("IA1"."YEAR"=TO_NUMBER(:V_YEAR) AND "IA1"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                   
      25 - filter(:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME)                                                                                                                                                                                   
      26 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    53 rows selected

    Hi,
    please find the below rigjt explan paln.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    SQL_ID  2ct41vyyzqyh7, child number 0                                                                                                                                                                                                                                                                       
    SELECT *  FROM    (SELECT q.*,      COUNT(*) OVER() AS record_count,      ROWNUM          AS row_num    FROM      (SELECT                                                                                                                                                                                   
    ExName.examiner_code,        examiner_name,        :v_year,        :v_month,        count_fb,        NVL(count_entered_fb,                                                                                                                                                                                  
    0) count_entered_fb,        NVL(count_sent_fb, 0) count_sent_fb,        NVL(count_edited_fb, 0) count_edited_fb,                                                                                                                                                                                            
    NVL(count_complete_fb, 0) count_complete_fb,        NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb      FROM                                                                                                                                                                                         
    (SELECT examiner_code,          COUNT(*) AS count_fb        FROM          (SELECT                                                                                                                                                                                                 
           examiner_code,            paper_code,            assessment_school          FROM            ( SELECT DISTINCT                                                                                                                                                                                        
    ce.examiner_code,              ce.paper_code,              ce.assessment_school            FROM              (SELECT                                                                                                                                                                                        
                            DISTINCT assessment_school,                                                                                                                                                                                                          
    paper_code,                examiner                                                                                                                                                                                                                                                                         
    Plan hash value: 651311258                                                                                                                                                                                                                                                                                  
    | Id  | Operation                                | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                         
    |   0 | SELECT STATEMENT                         |                                |       |       |       |  2785 (100)|          |                                                                                                                                                                         
    |*  1 |  FILTER                                  |                                |       |       |       |            |          |                                                                                                                                                                         
    |*  2 |   VIEW                                   |                                |     4 |  1104 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   3 |    WINDOW BUFFER                         |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   4 |     COUNT                                |                                |       |       |       |            |          |                                                                                                                                                                         
    |   5 |      VIEW                                |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   6 |       NESTED LOOPS                       |                                |     4 |   476 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   7 |        MERGE JOIN OUTER                  |                                |     4 |   368 |       |  2781   (7)| 00:00:43 |                                                                                                                                                                         
    |   8 |         VIEW                             |                                |     4 |    80 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |   9 |          SORT GROUP BY                   |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  10 |           VIEW                           |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  11 |            SORT UNIQUE                   |                                |     4 |   508 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  12 |             NESTED LOOPS                 |                                |     4 |   508 |       |    71   (2)| 00:00:02 |                                                                                                                                                                         
    |* 13 |              HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                         
    |* 14 |               TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                         
    |* 15 |                INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                         
    |* 16 |               INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |* 17 |              INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |    30 |  1770 |       |    27   (0)| 00:00:01 |                                                                                                                                                                         
    |* 18 |         SORT JOIN                        |                                |   576 | 41472 |       |  2709   (7)| 00:00:42 |                                                                                                                                                                         
    |  19 |          VIEW                            |                                |   576 | 41472 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |  20 |           SORT GROUP BY                  |                                |   576 | 21312 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |* 21 |            HASH JOIN                     |                                | 52408 |  1893K|  1744K|  2701   (7)| 00:00:41 |                                                                                                                                                                         
    |* 22 |             TABLE ACCESS FULL            | IA_INSTANCES                   | 52408 |  1125K|       |  1263   (6)| 00:00:20 |                                                                                                                                                                         
    |  23 |             TABLE ACCESS FULL            | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                         
    |* 24 |        TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                         
    |* 25 |         INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)|          |                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter(("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1)))                                                                                                                                                                                        
      13 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      14 - filter(((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL)))                                                                                                                                                                                                
      15 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      16 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter((:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP)))                                                                                                                                                                                                                
      17 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter(("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                   
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE)))                                                                                                                                                                                                                                                    
      18 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
           filter("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      22 - filter(("IA1"."MONTH"=:V_MONTH AND "IA1"."YEAR"=TO_NUMBER(:V_YEAR)))                                                                                                                                                                                                                                 
      24 - filter((:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME))                                                                                                                                                                                 
      25 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    66 rows selected

  • XPath query rewrite and insertChildXML (10g2): Help?

    Hi all,
    I have a registered schema for a <log> document. The schema defines an element /log/logData and under that there, /log/logData/data having maxOccurs="unbounded". So the form of documents is
    <log>
    <logData>
    <data>a</data>
    <data>b</data>
    <data>c</data>
    </logData>
    </log>
    In the schema definition I have enabled "storeArrayAsVArray='true'". The <data> elements are stored in a nested table. Every type is stored object-relationally.
    To an instance documen, I add <data> elements so:
    UPDATE log SET object_value = insertChildXML(object_value, 'log/logData', 'data', '<data>foo</data>') WHERE existsNode ('/log[@uid="foo"]')
    The call succeeds but the problem is that I need to make this call thousands of times. Initiallly the call might take 100 ms, but after a few hundred inserts inserting a single element takes over a second, and the time keeps increasing.
    I believe at least part of the problem is that XPath query rewrites are not working for this call.
    Following Chapter 6 of Oracle XML DB Developer's Guide, to debug the problem I have switched on
    ALTER SESSION SET EVENTS '19021 trace name context forever, level 1';
    and then every invocation causes:
    ORA-19022: XML XPath functions are disabled
    indicating that Oracle could not rewrite the query. Then I set
    ALTER SESSION SET EVENTS '19027 TRACE NAME CONTEXT FOREVER, LEVEL 8192'
    to obtain a trace file. Here is a portion of that trace:
    *** 2005-10-30 16:54:44.984
    *** ACTION NAME:() 2005-10-30 16:54:44.968
    *** MODULE NAME:(SQL*Plus) 2005-10-30 16:54:44.968
    *** SERVICE NAME:(SYS$USERS) 2005-10-30 16:54:44.968
    *** SESSION ID:(137.38364) 2005-10-30 16:54:44.968
    NO REWRITE
         Reason ==> xseq:not optuop
    NO REWRITE
         Reason ==> xseq:not optuop
    NO REWRITE
         Reason ==> not SQLX operand
    NO REWRITE
         Reason ==> non sqlx expression input
    NO REWRITE
         Reason ==> non rewritable sqlx input
    NO REWRITE
    (the rest of the file repeats these lines)
    I have no idea how to interpet that! Can anyone out there offer some insight/assistance?
    Thanks if you can,
    Hugh

    Below is a complete example script. Cannot seem to get rewrite for even this simple case. By that I mean, executing both of the SELECT statements near the end yield the ORA-19022, and that executing the insertChildXML takes progressively longer to execute the more child elements there are.
    Any pointers appreciated!
    Hugh
    set echo on
    ALTER SESSION SET EVENTS '19021 trace name context forever, level 1';
    ALTER SESSION SET EVENTS '19027 TRACE NAME CONTEXT FOREVER, LEVEL 8192';
    exec dbms_xmlschema.deleteSchema('http://hughw.net/foo', dbms_xmlschema.DELETE_CASCADE_FORCE);
    begin
    dbms_xmlschema.registerSchema('http://hughw.net/foo', XMLType('<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="http://hughw.net/foo" xmlns="http://hughw.net/foo" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"
    xmlns:xdb="http://xmlns.oracle.com/xdb" xdb:storeVarrayAsTable="true">
    <xs:element name="root" xdb:defaultTable="ROOT" >
    <xs:complexType xdb:SQLType="ROOT_T">
    <xs:sequence>
    <!-- could use out of line storage -->
    <!-- commented out
    <xs:element name="child" type="childType" minOccurs="0" maxOccurs="unbounded"
    xdb:SQLName="CHILDREN"
    xdb:SQLInline="false" xdb:defaultTable="CHILD"
    />
    -->
    <!-- use nested table -->
    <xs:element name="child" type="childType" minOccurs="0" maxOccurs="unbounded"
    xdb:SQLName="CHILDREN"
    xdb:SQLCollType="CHILD_V"
    />
    </xs:sequence>
    <xs:attribute name="uid" type="xs:string" use="required"/>
    </xs:complexType>
    </xs:element>
    <xs:complexType name="childType" xdb:SQLType="CHILD_T">
    <xs:simpleContent>
    <xs:extension base="xs:string"/>
    </xs:simpleContent>
    </xs:complexType>
    </xs:schema>'));
    end;
    insert into root values( XMLType('<?xml version="1.0" encoding="UTF-8"?>
    <root uid="1" xmlns="http://hughw.net/foo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://hughw.net/foo http://hughw.net/foo">
    <child>a</child>
    <child>b</child>
    <child>c</child>
    </root>'));
    CREATE INDEX ROOT_INDEX ON ROOT (extractValue(object_value,'/root/@uid'));
    select insertChildXML(object_value, '/root', 'child', '<child>x</child>>') FROM root;
    explain plan for select insertChildXML(object_value, '/root', 'child', '<child>x</child>>') FROM root;
    SELECT PLAN_TABLE_OUTPUT FROM table(DBMS_XPLAN.display('plan_table', NULL, 'serial'));
    select insertChildXML(object_value, '/root', 'child', '<child>x</child>>') FROM root
    WHERE existsNode(object_value, '/root[@uid="1"]') = 1;
    explain plan for select insertChildXML(object_value, '/root', 'child', '<child>x</child>>') FROM root
    WHERE existsNode(object_value, '/root[@uid="1"]') = 1;
    SELECT PLAN_TABLE_OUTPUT FROM table(DBMS_XPLAN.display('plan_table', NULL, 'serial'));

  • Are Cube organized materialized view with Year to Date calculated measure eligible for Query Rewrite

    Hi,
    Will appreciate if someone can help me with a question regarding Cube organized MV (OLAP).
    Does cube organized materialized view with calculated measures based on time series  Year to date, inception to date  eg.
    SUM(FCT_POSITION.BASE_REALIZED_PNL) OVER (HIERARCHY DIM_CALENDAR.CALENDAR BETWEEN UNBOUNDED PRECEDING AND CURRENT MEMBER WITHIN ANCESTOR AT DIMENSION LEVEL DIM_CALENDAR."YEAR")
    are eligible for query rewrites or these are considered advanced for query rewrite purposes.
    I was hoping to find an example with YTD window function on physical fact dim tables  with optimizer rewriting it to Cube Org. MV but not much success.
    Thanks in advance

    I dont think this is possible.
    (My own reasoning)
    Part of the reason query rewrite works for base measures only (not calc measures in olap like ytd would be) is due to the fact that the data is staged in olap but its lineage is understandable via the olap cube mappings. That dependency/source identification is lost when we build calculated measures in olap and i think its almost impossible for optimizer to understand the finer points relating to an olap calculation defined via olap calculation (olap dml or olap expression) and also match it with the equivalent calculation using relational sql expression. The difficulty may be because both the olap ytd as well as relational ytd defined via sum() over (partition by ... order by ...) have many non-standard variations of the same calculation/definition. E.g: You can choose to use or choose not to use the option relating to IGNORE NULLs within the sql analytic function. OLAP defn may use NASKIP or NASKIP2.
    I tried to search for query rewrite solutions for Inventory stock based calculations (aggregation along time=last value along time) and see if olap cube with cube aggregation option set to "Last non-na hierarchical value" works as an alternative to relational calculation. My experience has been that its not possible. You can do it relationally or you can do it via olap but your application needs to be aware of each and make the appropriate backend sql/call. In such cases, you cannot make olap (aw/cubes/dimensions) appear magically behind the scenes to fulfill the query execution while appearing to work relationally.
    HTH
    Shankar

  • Materialized Views with Query Rewrite is not getting re-written

    I have tried everything that has been mentioned in all the forums here and on metalink to fix this issue, has any smart APEX user found a solution?
    The issue is the MV with Query rewrite capability is not being re-written.
    Things I have tried
    1) give all Query Rewrite privileges to all 3 APEx schemas and parsing schema;
    2) check trace files with tkprof;
    3) dynamically printed explain plan from v$_SQL on the page while executing the query;
    4) to test in a different environment i created an another DAD using the pl/sql webtool kit and tried the same thing and rewrite works like a charm...
    whats the issue here...why are apex schemas not re-writing the queries????
    appreciate any help...thanks

    Jes, per your request
    --create materialized view
    CREATE MATERIALIZED VIEW "RPLANSWEB"."MV_FCG_ALL_SUMMARY_TAB"
    ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "RPLANSWEB"
    BUILD IMMEDIATE
    USING INDEX
    REFRESH FORCE ON DEMAND
    USING DEFAULT LOCAL ROLLBACK SEGMENT
    ENABLE QUERY REWRITE
    AS SELECT fcg, year, fcg_desc,
    fac, efr, fac_desc, efr_desc,
    ums_round, fcg_allow_drillable allow_drillable,
    MAX(category_code_um1) category_code_um1,
    SUM(perm_asset) perm_asset,
    SUM(temp_asset) temp_asset,
    SUM(semi_asset) semi_asset,
    SUM(lease_asset) lease_asset,
    SUM(planned_constr) planned_constr,
    SUM(all_perm_asset) all_perm_asset,
    SUM(total_asset) total_asset,
    SUM(allow) allow, SUM(rqmt) rqmt,
    SUM(perm_planned_constr) perm_planned_constr,
    SUM(perm_planned_constr_rqmt_delta) perm_planned_constr_rqmt_delta,
    ROUND(DECODE(SUM(rqmt), 0, 0, SUM(all_perm_asset)/SUM(rqmt)*100)) perm_rqmt_pctsat,
    ROUND(DECODE(SUM(allow), 0, 0, SUM(all_perm_asset)/SUM(allow)*100)) perm_allw_pctsat,
    ROUND(DECODE(SUM(rqmt), 0, 0, SUM(total_asset)/SUM(rqmt)*100)) total_rqmt_pctsat,
    ROUND(DECODE(SUM(allow), 0, 0, SUM(total_asset)/SUM(allow)*100)) total_allw_pctsat,
    ROUND(DECODE(SUM(all_perm_asset), 0, 0, SUM(rqmt)/SUM(all_perm_asset)*100)) perm_rqmt_pctutl,
    ROUND(DECODE(SUM(all_perm_asset), 0, 0, SUM(allow)/SUM(all_perm_asset)*100)) perm_allw_pctutl,
    ROUND(DECODE(SUM(total_asset), 0, 0, SUM(rqmt)/SUM(total_asset)*100)) total_rqmt_pctutl,
    ROUND(DECODE(SUM(total_asset), 0, 0, SUM(allow)/SUM(total_asset)*100)) total_allw_pctutl,
    SUM(coarse_screen_asset) coarse_screen_asset,
    SUM(total_excess) total_excess,
    SUM(total_deficit) total_deficit,
    SUM(perm_excess) perm_excess,
    SUM(perm_deficit) perm_deficit,
    SUM(all_perm_excess) all_perm_excess,
    SUM(all_perm_deficit) all_perm_deficit,
    SUM(temp_excess) temp_excess,
    SUM(satisfy_rqmt) satisfy_rqmt
    FROM summary_tab_dd
    GROUP BY fcg, year, fcg_desc,
    fac, efr, fac_desc, efr_desc,
    ums_round, fcg_allow_drillable;
    sql plus> log in as parsing schema user (not APEX_PUBLIC_USER)
    sql plus> SELECT fcg, year, fcg_desc,
    SUM(perm_asset) perm_asset,
    SUM(perm_excess) perm_excess,
    SUM(perm_deficit) perm_deficit,
    SUM(all_perm_excess) all_perm_excess,
    SUM(all_perm_deficit) all_perm_deficit,
    SUM(temp_excess) temp_excess,
    SUM(satisfy_rqmt) satisfy_rqmt
    FROM summary_tab_dd
    where year=2007
    GROUP BY fcg, year, fcg_desc;
    --execution plan
    SELECT STATEMENT     ALL_ROWS     12     291     17460                         
    HASH(GROUP BY)          12     291     17460                         
    MAT_VIEW REWRITE ACCESS(FULL) RPLANSWEB.MV_FCG_ALL_SUMMARY_TAB     ANALYZED     11     291     17460                         "MV_FCG_ALL_SUMMARY_TAB"."YEAR"=2007
    --execution plan from sql workshop (application express)
    SELECT STATEMENT 42,341 55 3,882 1,990,027
    HASH GROUP BY 42,341 55 3,882 1,990,027
    TABLE ACCESS FULL SUMMARY_TAB_DD 109,158 47 3,329 5,130,426 "YEAR" = 2007
    --execution plan from an APEX page (displayed from v$sql and V$SQL_PLAN)
    OPERATION: SELECT STATEMENT OPTIONS: OBJECT_NAME: OBJECT_ALIAS: OBJECT_TYPE: OPTIMIZER: ALL_ROWS SEARCH_COLUMNS: 0 COST: 4600 CARDINALITY: BYTES: CPU_COST: IO_COST: ACCESS_PREDICATES: FILTER_PREDICATES: PROJECTION:
    OPERATION: HASH OPTIONS: GROUP BY OBJECT_NAME: OBJECT_ALIAS: OBJECT_TYPE: OPTIMIZER: SEARCH_COLUMNS: 0 COST: 4600 CARDINALITY: 109158 BYTES: 8732640 CPU_COST: 549150132 IO_COST: 4569 ACCESS_PREDICATES: FILTER_PREDICATES: PROJECTION: "FCG"[VARCHAR2,6], "FCG_DESC"[VARCHAR2,15], SUM("PERM_DEFICIT")[22], SUM("PERM_EXCESS")[22], SUM("SATISFY_RQMT")[22], SUM("TEMP_EXCESS")[22], SUM("ALL_PERM_EXCESS")[22], SUM("ALL_PERM_DEFICIT")[22], SUM("PERM_ASSET")[22]
    OPERATION: TABLE ACCESS OPTIONS: FULL OBJECT_NAME: SUMMARY_TAB_DD OBJECT_ALIAS: SUMMARY_TAB_DD@SEL$1 OBJECT_TYPE: TABLE OPTIMIZER: SEARCH_COLUMNS: 0 COST: 3329
    as you can see while executing the script in sql developer the optimizer is finding the relevant materialized view, not in the case of APEX's SQL Workshop or Page.
    appreciate your time

  • Query rewrite does not happen

    Hello all,
    let me start by wishing you all the best for the forthcoming year !
    And now, the problem
    I am trying to create a materialized view so that a few slow reports that run on OBIEE (10g) make use of query rewrite functionality. Unfortunately any attempt that had made was unsuccessful. I though of posting the query that is created by OBIEE and the different materialized views that i have created, so that anyone that had a similar problem before might help me through it.  So here it goes ( there is a separate discussion for the other query here ) :
    First comes the query that was created by OBIEE when no materialized view existed.
      SELECT DISTINCT D1.c5 AS c1,                  D1.c10 AS c2,                       D1.c9 AS c3,                  D1.c6 AS c4,                  D1.c8 AS c5,                  D1.c8 / NULLIF (D1.c6, 0) AS c6,
                      D1.c7 AS c7,                  D1.c7 / NULLIF (D1.c6, 0) AS c8,        D1.c4 AS c9,                  D1.c3 / NULLIF (D1.c1, 0) AS c10,                     D1.c2 / NULLIF (D1.c1, 0) AS c11
        FROM (SELECT SUM (D1.c6) OVER (PARTITION BY D1.c5) AS c1,
                     SUM (D1.c7) OVER (PARTITION BY D1.c5) AS c2,
                     SUM (D1.c8) OVER (PARTITION BY D1.c5) AS c3,
                     SUM (D1.c4) OVER (PARTITION BY D1.c5) AS c4,
                     D1.c5 AS c5,                 D1.c6 AS c6,                 D1.c7 AS c7,                 D1.c8 AS c8,                 D1.c9 AS c9,                 D1.c10 AS c10
                FROM (  SELECT COUNT (CASE D1.c12 WHEN 1 THEN D1.c11 ELSE NULL END)    AS c4,                    D1.c5 AS c5,                           SUM (D1.c13) AS c6,            
                             SUM (D1.c14) AS c7,                           SUM (D1.c15) AS c8,               COUNT (DISTINCT D1.c11) AS c9,                           D1.c10 AS c10
                          FROM (SELECT                   /*+ PARALLEL(T16913,8) */
                                      T19403.YEAR_MONTH   AS c5,
                                       T7252.PERCENTAGE AS c10,
                                       T366.BARCODE AS c11,
                                       ROW_NUMBER ()   OVER (  PARTITION BY T19403.YEAR_MONTH,   T366.BARCODE  ORDER BY  T19403.YEAR_MONTH DESC,   T366.BARCODE DESC)  AS c12,
                                       T16913.PHA_QUANTITY AS c13,
                                       T16913.EXEC_COST AS c14,
                                       T16913.EXEC_VALUE AS c15
                                  FROM EXECALENDAR_DIM T19403,
                                           DRUG_DIM T366,
                                           PERCENTAGE_DIM T7252,
                                           PRESCDRUG_FACT T16913
                                 WHERE (T366.DWHKEY = T16913.DRU_DWHKEY
                                        AND T7252.DWHKEY = T16913.PER_DWHKEY
                                        AND T16913.EXECUTION_DATE =
                                               T19403.CALENDAR_DATE
                                        AND T19403.YEAR_MONTH = '201212')) D1
                      GROUP BY D1.c5, D1.c10) D1) D1
    ORDER BY c1, c2
    so my first try was that
    CREATE MATERIALIZED VIEW PRESCDRUG_FACT_MV  BUILD IMMEDIATE  REFRESH ON DEMAND  ENABLE QUERY REWRITE  AS
    SELECT  /*+ PARALLEL(PRESCDRUG_FACT,8) */
                     EXECALENDAR_DIM.YEAR_MONTH       as  YEAR_MONTH
                    ,PRESCDRUG_FACT.PER_DWHKEY
                     ,count(*)                            as COUNT_ALL
                     ,COUNT (EXECALENDAR_DIM.YEAR_MONTH)  AS c_YEAR_MONTH
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_CD) DRUG_CODE
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_BARCODE) BARCODE
                      -- quantities
                     ,SUM (PRESCDRUG_FACT.PHA_QUANTITY) AS PHA_QUANTITY
                     ,SUM (PRESCDRUG_FACT.DOC_QUANTITY) AS DOC_QUANTITY
                     ,SUM (PRESCDRUG_FACT.APR_QUANTITY) AS APR_QUANTITY
                     -- values
                     ,SUM (PRESCDRUG_FACT.EXEC_VALUE)       AS EXEC_VALUE
                     ,SUM (PRESCDRUG_FACT.PUB_VALUE)        AS PUB_VALUE                
                     ,SUM (PRESCDRUG_FACT.APR_VALUE) AS APR_VALUE                
                     -- costs
                     ,SUM (PRESCDRUG_FACT.EXEC_COST) AS EXEC_COST
                     ,SUM (PRESCDRUG_FACT.PUB_COST) AS PUB_COST
                     ,SUM (PRESCDRUG_FACT.APR_COST) AS APR_COST
       FROM  EXECALENDAR_DIM,    PRESCDRUG_FACT
      WHERE EXECALENDAR_DIM.CALENDAR_DATE   = PRESCDRUG_FACT.EXECUTION_DATE
           AND EXECALENDAR_DIM.YEAR_MONTH in ( '201212')
       GROUP BY   EXECALENDAR_DIM.YEAR_MONTH ,PRESCDRUG_FACT.PER_DWHKEY
    and i got the following messages from DBMS_MVIEW.EXPLAIN_REWRITE
    QSM-01150: query did not rewrite
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, EXECALENDAR_DIM, on column, CALENDAR_DATE
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXECUTION_DATE
    QSM-01082: Joining materialized view, PRESCDRUG_FACT_MV, with table, PRESCDRUG_FACT, not possible
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, DRU_DWHKEY
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXEC_VALUE
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXEC_COST
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, PHA_QUANTITY
    QSM-01155: multi-mv query rewrite not possible when there is a Window Function
    QSM-01219: no suitable materialized view found to rewrite this query
    My second attempt is the following ( in comparison to the first i have added the DRUG_BARCODE column in the grouping clause
    CREATE MATERIALIZED VIEW PRESCDRUG_FACT_MV BUILD IMMEDIATE  REFRESH ON DEMAND ENABLE QUERY REWRITE  AS
    SELECT  /*+ PARALLEL(PRESCDRUG_FACT,8) */
                     EXECALENDAR_DIM.YEAR_MONTH       as  YEAR_MONTH
                     ,PRESCDRUG_FACT.PER_DWHKEY
                  ,PRESCDRUG_FACT.DRUG_BARCODE
                     ,count(*)                                            as COUNT_ALL
                     ,COUNT (EXECALENDAR_DIM.YEAR_MONTH)  AS c_YEAR_MONTH
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_CD) DRUG_CODE
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_BARCODE) BARCODE
                     ,COUNT (DISTINCT PRESCDRUG_FACT.PRESC_NUMBER) PRESC_NUMBER
                     ,COUNT (DISTINCT PRESCDRUG_FACT.PRESC_ID)  PRESC_ID
                      -- quantities
                     ,SUM (PRESCDRUG_FACT.PHA_QUANTITY) AS PHA_QUANTITY
                     ,SUM (PRESCDRUG_FACT.DOC_QUANTITY)        AS DOC_QUANTITY
                     ,SUM (PRESCDRUG_FACT.APR_QUANTITY) AS APR_QUANTITY
                     -- values
                     ,SUM (PRESCDRUG_FACT.EXEC_VALUE)       AS EXEC_VALUE
                     ,SUM (PRESCDRUG_FACT.PUB_VALUE)        AS PUB_VALUE                
                     ,SUM (PRESCDRUG_FACT.APR_VALUE) AS APR_VALUE                
                     -- costs
                     ,SUM (PRESCDRUG_FACT.EXEC_COST) AS EXEC_COST
                     ,SUM (PRESCDRUG_FACT.PUB_COST) AS PUB_COST
                     ,SUM (PRESCDRUG_FACT.APR_COST) AS APR_COST
        FROM  EXECALENDAR_DIM,    PRESCDRUG_FACT
      WHERE EXECALENDAR_DIM.CALENDAR_DATE   = PRESCDRUG_FACT.EXECUTION_DATE
           AND EXECALENDAR_DIM.YEAR_MONTH in ( '201212')
       GROUP BY   EXECALENDAR_DIM.YEAR_MONTH ,PRESCDRUG_FACT.PER_DWHKEY,DRUG_BARCODE
    and the results of DBMS_MVIEW.EXPLAIN_REWRITE
    QSM-01150: query did not rewrite
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, EXECALENDAR_DIM, on column, CALENDAR_DATE
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXECUTION_DATE
    QSM-01082: Joining materialized view, PRESCDRUG_FACT_MV, with table, PRESCDRUG_FACT, not possible
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, DRU_DWHKEY
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXEC_VALUE
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, EXEC_COST
    QSM-01102: materialized view, PRESCDRUG_FACT_MV, requires join back to table, PRESCDRUG_FACT, on column, PHA_QUANTITY
    QSM-01155: multi-mv query rewrite not possible when there is a Window Function
    QSM-01219: no suitable materialized view found to rewrite this query
    third try (rolling up the group results)
    CREATE MATERIALIZED VIEW PRESCDRUG_FACT_MV BUILD IMMEDIATE  REFRESH ON DEMAND ENABLE QUERY REWRITE  AS
    SELECT  /*+ PARALLEL(PRESCDRUG_FACT,8) */
                     EXECALENDAR_DIM.YEAR_MONTH       as  YEAR_MONTH
                     ,PRESCDRUG_FACT.PER_DWHKEY
                  ,PRESCDRUG_FACT.DRUG_BARCODE
                     ,count(*)                                            as COUNT_ALL
                     ,COUNT (EXECALENDAR_DIM.YEAR_MONTH)  AS c_YEAR_MONTH
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_CD) DRUG_CODE
                     ,COUNT (DISTINCT PRESCDRUG_FACT.DRUG_BARCODE) BARCODE
                     ,COUNT (DISTINCT PRESCDRUG_FACT.PRESC_NUMBER) PRESC_NUMBER
                     ,COUNT (DISTINCT PRESCDRUG_FACT.PRESC_ID)  PRESC_ID
                      -- quantities
                     ,SUM (PRESCDRUG_FACT.PHA_QUANTITY) AS PHA_QUANTITY
                     ,SUM (PRESCDRUG_FACT.DOC_QUANTITY)        AS DOC_QUANTITY
                     ,SUM (PRESCDRUG_FACT.APR_QUANTITY) AS APR_QUANTITY
                     -- values
                     ,SUM (PRESCDRUG_FACT.EXEC_VALUE)       AS EXEC_VALUE
                     ,SUM (PRESCDRUG_FACT.PUB_VALUE)        AS PUB_VALUE                
                     ,SUM (PRESCDRUG_FACT.APR_VALUE) AS APR_VALUE                
                     -- costs
                     ,SUM (PRESCDRUG_FACT.EXEC_COST) AS EXEC_COST
                     ,SUM (PRESCDRUG_FACT.PUB_COST) AS PUB_COST
                     ,SUM (PRESCDRUG_FACT.APR_COST) AS APR_COST
        FROM  EXECALENDAR_DIM,    PRESCDRUG_FACT
      WHERE EXECALENDAR_DIM.CALENDAR_DATE   = PRESCDRUG_FACT.EXECUTION_DATE
           AND EXECALENDAR_DIM.YEAR_MONTH in ( '201212')
       GROUP BY   EXECALENDAR_DIM.YEAR_MONTH     , rollup (PRESCDRUG_FACT.PER_DWHKEY,    DRUG_BARCODE) 
    results from DBMS_MVIEW.EXPLAIN_REWRITE
    QSM-01150: query did not rewrite
    QSM-01295: no suitable grouping_id found in materialized view with grouping sets
    QSM-01155: multi-mv query rewrite not possible when there is a Window Function
    QSM-01219: no suitable materialized view found to rewrite this query  
    So, no luck so far. My guess is that it has to do something with the partition clause that appears in the original query.
    anyway, if anything cross your minds..
    thanks in advance
    Theodore

    Hello again,
    It appeared that, the problem is present only when I try the query in pl/sql developer.
    For some reason, even though I set QUERY_REWRITE_INTEGRITY to STALE_TOLERATED, it behaved as this parameter was set to ENFORCED.
    So the case was that:
    for session - STALE_TOLERATED
    for system - ENFORCED
    In v$parameter2 against "QUERY_REWRITE_INTEGRITY" was shown "stale_tolerated", but the query was not rewritten.
    When I do the same (altering the session and perform the select query) in SQLPlus, everything works as expected - the query is rewritten.
    And I conclude the problem is in PL/SQL Developer (my version is 8.0.1.1498) or something related to this.
    Edited by: Verdi on 2010-2-12 14:00

  • Query Rewrite ISSUE (ANSI JOINS do not work, traditional join works ) 11gR2

    For some types of queries constructed with ANSI JOINS, materialized views are not being used.
    This is currently increasing time on various reports since we cannot control the way the queries are generated(Tableau Application generates and runs queries against the STAR Schema).
    Have tried to debug this behavior using DBMS_MVIEW.EXPLAIN_REWRITE and mv_capabilities function without any success.
    The database is configured for query rewrite: REWRITE INTEGRITY, QUERY REWRITE ENABLED and other settings are in place.
    Have successfully reproduced the issue using SH Sample schema:
    Q1 and Q2 are logically identical the only difference between them being the type of join used:
    Q1: ANSI JOIN
    Q2: Traditional join
    Below is an example that can be validated on SH sample schema.
    Any help on this will be highly appreciated.
    -- Q1: the query is generated by an app and needs to be rewritten with materialized view
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;
    -- Q2: the query with traditional join is rewritten with materialized view
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;Tested both queries with the following materialized views:
    CREATE MATERIALIZED VIEW MVIEW_TEST_1
    ENABLE QUERY REWRITE
    AS
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;
    CREATE MATERIALIZED VIEW MVIEW_TEST_2
    ENABLE QUERY REWRITE
    AS
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust,  countries cntr
    WHERE cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;Explain Plans showing that Q1 does not use materialized view and Q2 uses materialized view
    SET AUTOTRACE TRACEONLY
    --Q1 does not use MVIEW_TEST_1
    SQL> SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;  2    3    4    5 
    511 rows selected.
    Execution Plan
    Plan hash value: 1218164197
    | Id  | Operation           | Name       | Rows  | Bytes |TempSpc| Cost (%CPU)| Time       |
    |   0 | SELECT STATEMENT      |        |   425 | 12325 |       |   916   (1)| 00:00:11 |
    |   1 |  HASH GROUP BY           |        |   425 | 12325 |       |   916   (1)| 00:00:11 |
    |   2 |   VIEW                | VM_NWVW_1 | 55500 |  1571K|       |   916   (1)| 00:00:11 |
    |   3 |    HASH GROUP BY      |        | 55500 |  1842K|  2408K|   916   (1)| 00:00:11 |
    |*  4 |     HASH JOIN           |        | 55500 |  1842K|       |   409   (1)| 00:00:05 |
    |   5 |      TABLE ACCESS FULL| COUNTRIES |    23 |   414 |       |     3   (0)| 00:00:01 |
    |   6 |      TABLE ACCESS FULL| CUSTOMERS | 55500 |   867K|       |   405   (1)| 00:00:05 |
    --Q2 uses MVIEW_TEST_2
    SQL> SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust,  countries cntr
    WHERE cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;  2    3    4 
    511 rows selected.
    Execution Plan
    Plan hash value: 2126022771
    | Id  | Operation               | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |              |     511 | 21973 |       3   (0)| 00:00:01 |
    |   1 |  MAT_VIEW REWRITE ACCESS FULL| MVIEW_TEST_2 |     511 | 21973 |       3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------Database version 11gR1 (Tested also on 11gR2)
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    Thanks for the formatting tips.
    Just found an Oracle Bug which explains the above behavior.
    Unfortunately the bug will be fixed only in 12.1 Release so as a workaround will try to use traditional joins.
    For those who have metalink access see [Bug 10145667 : ERRORS TRYING TO REWRITE QUERY WITH EXACT TEXT MATCH TO MVIEW]

  • Materialized views - schedule, indexes, query rewrite, etc.

    I'm trying to get the hang of materialized views and need some help . . .
    running Oracle 10gR2
    I created a materialized view as follows:
    CREATE MATERIALIZED VIEW "MY_SCHEMA"."USERS"
    AS
    SELECT * FROM "USERS"@PRODUCTION -- to copy the USERS table from my production database to this database
    Worked fine. So far so good. Then, I altered it to schedule the refresh:
    ALTER MATERIALIZED VIEW "MY_SCHEMA"."USERS" REFRESH FORCE START WITH SYSDATE NEXT TRUNC(SYSDATE + 1) + 4/24
    -- to schedule a refresh immediately (SYSDATE) and every morning thereafter at 4:00 am (I think)
    then, I wanted to enable query rewrite, so I issued the following command:
    ALTER MATERIALIZED VIEW "MY_SCHEMA"."USERS" ENABLE QUERY REWRITE;
    and I got the
    ALTER MATERIALIZED VIEW succeeded.
    message for both of those commands (I'm doing this in SQL Developer).
    Then, I edit the materialized view in SQL Developer, click on the 'SQL' tab, and get the following:
    CREATE MATERIALIZED VIEW "MY_SCHEMA"."USERS"
    ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "TBLSPC_PHIGH"
    BUILD IMMEDIATE
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "TBLSPC_PHIGH"
    REFRESH FORCE ON DEMAND START WITH sysdate+0 NEXT TRUNC(SYSDATE + 1) + 4/24
    WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
    DISABLE QUERY REWRITE
    AS SELECT "USERS"."User" "User","USERS"."Logon" "Logon","USERS"."Name" "Name","USERS"."Password"
    "Password","USERS"."Level" "Level","USERS"."Producer" "Producer","USERS"."Deleted" "Deleted","USERS"."ClaimDoctor"
    "ClaimDoctor","USERS"."UserType" "UserType","USERS"."Locked" "Locked","USERS"."Scheduler"
    "Scheduler","USERS"."RestrictDays" "RestrictDays","USERS"."First" "First","USERS"."DisableAutoChart"
    "DisableAutoChart","USERS"."MaxChartOut" "MaxChartOut","USERS"."MaxHoursOut" "MaxHoursOut","USERS"."EffDate"
    "EffDate","USERS"."ExpDate" "ExpDate","USERS"."SwipeLogon" "SwipeLogon","USERS"."SwipePassword"
    "SwipePassword","USERS"."PwdLastChanged" "PwdLastChanged","USERS"."Audit" "Audit","USERS"."IsInstructor"
    "IsInstructor" FROM "USERS"@PRODUCTION.REGRESS.RDBMS.DEV.US.ORACLE.COM "USERS";
    The problems I've encountered so far:
    1) I created this two days ago and changed the value of one column in one row in the 'source' USERS table
    (USERS@PRODUCTION) as a test case. So far, that change has not propagated over to my materialized view even though
    it has had two chances to do so (yesterday morning at 4:00 am and this morning at 4:00 am).
    2) I enabled QUERY REWRITE. Why does it still show DISABLE?
    3) The primary key of the table came over (as far as I can tell) because it shows in SQL Developer. However, the
    indexed columns are no longer indexed. Do I need to recreate those indexes manually and will they persist?
    4) As you have guessed, I have just taken the plunge into materialized views, and have not been able to find
    anything on the Web along the lines of 'Materialized Views for Dummies'. So, any and all advice/suggestions/help
    will be welcome.
    Thanks,
    Carl

    The Refresh would be executed by a job submitted in the background.
    Query USER_JOBS (or DBA_JOBS) to see if a job has been submitted and if it has been running (you'd be able to see LAST_DATE, LAST_SEC and NEXT_DATE and NEXT_SEC). \
    If the Refresh job has been failing the FAILURES count would be incremented. If there are 16 consecutive failures, the job is marked BROKEN. (if a job fails, Oracle retries it automatically and keeps retrying till it is BROKEN). If the job has been failing you would get messages in the database instance alert log file and trace files.
    If the Refresh job has not been running check the parameter value for JOB_QUEUE_PROCESSES -- a value of 0 would not run in jobs in the USER_JOBS/DBA_JOBS view. Ask the DBA to increase set this parameter to at least 1.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • Query Rewrite Configuration

    Hi,
    I have a confusion on the •     Query Rewrite Configuration in OBIEE some one at workplace has raised a question on the configuration of Query rewrite in OBIEE
    i think this is a feature of Oracle Database , but just wanted to know is there anything in OBIEE for Query Rewrite, other than the aggregate level setting.
    Help appreciated

    Query rewrite is handled by the Oracle RDBMS. You would just expose the MV/tables in your physical layer of RPD as per any regular table.
    Paul

  • Query rewrite don't work wor aggregate query but work for join query

    Dear experts,
    Let me know what's wrong for
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    I have two MATERIALIZED VIEW:
    A) -- Only join
    CREATE MATERIALIZED VIEW "SCOTT"."TST_MV"
    ENABLE QUERY REWRITE AS
    SELECT "T57410"."MEMBER_KEY" "MEMBER_KEY",
    "T57410"."ANCESTOR_KEY" "ANCESTOR_KEY",
    "T57410"."DISTANCE" "DISTANCE",
    "T57410"."IS_LEAF" "IS_LEAF",
    "T57460"."DEPARTMENTID" "DEPARTMENTID",
    "T57460"."NAME" "NAME","T57460"."PARENT"
    "PARENT","T57460"."SHORTNAME" "SHORTNAME",
    "T57460"."SKIMOID" "SKIMOID"
    FROM "BI_OIV_HIER" "T57410",
    "BI_DEPARTMENTS" "T57460"
    WHERE "T57410"."ANCESTOR_KEY"="T57460"."DEPARTMENTID";
    B) -- Join with aggregation
    CREATE MATERIALIZED VIEW "SCOTT"."TST_MV2"
    ("C41", "C42", "C43",
    "C44", "C45", "C46",
    "C47", "C48", "C49",
    "C50", "C51", "C52",
    "C53", "C54", "C55",
    "C56", "C57", "C58",
    "C59", "C60", "C61",
    "INCIDENTTYPE")
    ENABLE QUERY REWRITE
    AS SELECT COUNT(T56454.TOTAL) AS c41,
    T56840.CATEGORYID AS c42,
    T56840.PARENT AS c43,
    T56908.DOCSTATEID AS c44,
    T56908.PARENT AS c45,
    T56947.EXPIREDID AS c46,
    T56947.PARENT AS c47,
    T56986.ISSUESTATEID AS c48,
    T56986.PARENT AS c49,
    T57025.LOCATIONID AS c50,
    T57025.PARENT AS c51,
    T57064.NEWID AS c52,
    T57064.PARENT AS c53,
    T57103.PARENT AS c54,
    T57103.RESOLUTIONID AS c55,
    T57142.PARENT AS c56,
    T57142.RESPONSIBLEID AS c57,
    T57181.PARENT AS c58,
    T57181.SOURCEID AS c59,
    T57460.DEPARTMENTID AS c60,
    T57460.PARENT AS c61,
    T56454.INCIDENTTYPE
    FROM BI_OIV_HIER T57410
    BI_DEPARTMENTS T57460
    BI_SOURCE_HIER T57176
    SOURCE T57181
    BI_RESPONSIBLE_HIER T57137
    RESPONSIBLE T57142
    BI_RESOLUTIONS_HIER T57098
    RESOLUTIONS T57103
    BI_NEW_HIER T57059
    NEW T57064
    BI_LOCATIONS_HIER T57020
    LOCATIONS T57025
    BI_ISSUESTATES_HIER T56981
    ISSUESTATES T56986
    BI_EXPIRED_HIER T56942
    EXPIRED T56947
    BI_DOCSTATES_HIER T56903
    DOCSTATES T56908
    BI_CATEGORY_HIER T56835
    CATEGORY T56840
    INCIDENTS T56454
    WHERE ( T56454.RESOLUTION = T57098.MEMBER_KEY
    AND T56454.CATEGORY = T56835.MEMBER_KEY
    AND T56454.DOCSTATE = T56903.MEMBER_KEY
    AND T56454.EXPIRED = T56942.MEMBER_KEY
    AND T56454.ISSUESTATE = T56981.MEMBER_KEY
    AND T56454.LOCATION = T57020.MEMBER_KEY
    AND T56454.NEW = T57059.MEMBER_KEY
    AND T56454.RESPONSIBLE = T57137.MEMBER_KEY
    AND T56454.SOURCE = T57176.MEMBER_KEY
    AND T56454.DEPARTMENTID = T57410.MEMBER_KEY
    AND T56835.ANCESTOR_KEY = T56840.CATEGORYID
    AND T56903.ANCESTOR_KEY = T56908.DOCSTATEID
    AND T56942.ANCESTOR_KEY = T56947.EXPIREDID
    AND T56981.ANCESTOR_KEY = T56986.ISSUESTATEID
    AND T57020.ANCESTOR_KEY = T57025.LOCATIONID
    AND T57059.ANCESTOR_KEY = T57064.NEWID
    AND T57098.ANCESTOR_KEY = T57103.RESOLUTIONID
    AND T57137.ANCESTOR_KEY = T57142.RESPONSIBLEID
    AND T57176.ANCESTOR_KEY = T57181.SOURCEID
    AND T57410.ANCESTOR_KEY = T57460.DEPARTMENTID
    GROUP BY T56840.CATEGORYID,
    T56840.PARENT,
    T56908.DOCSTATEID,
    T56908.PARENT,
    T56947.EXPIREDID,
    T56947.PARENT,
    T56986.ISSUESTATEID,
    T56986.PARENT,
    T57025.LOCATIONID,
    T57025.PARENT,
    T57064.NEWID,
    T57064.PARENT,
    T57103.PARENT,
    T57103.RESOLUTIONID,
    T57142.PARENT,
    T57142.RESPONSIBLEID,
    T57181.PARENT,
    T57181.SOURCEID,
    T57460.DEPARTMENTID,
    T57460.PARENT,
    T56454.INCIDENTTYPE;
    So, optimizer uses query rewrite in
    select * from TST_MV
    and don't use query rewrite in
    select * from TST_MV2
    within one session.
    select * from TST_MV should be read as underlying select for TST_MV:
    SELECT "T57410"."MEMBER_KEY" "MEMBER_KEY",
    "T57410"."ANCESTOR_KEY" "ANCESTOR_KEY",
    "T57410"."DISTANCE" "DISTANCE",
    "T57410"."IS_LEAF" "IS_LEAF",
    "T57460"."DEPARTMENTID" "DEPARTMENTID",
    "T57460"."NAME" "NAME","T57460"."PARENT"
    "PARENT","T57460"."SHORTNAME" "SHORTNAME",
    "T57460"."SKIMOID" "SKIMOID"
    FROM "BI_OIV_HIER" "T57410",
    "BI_DEPARTMENTS" "T57460"
    WHERE "T57410"."ANCESTOR_KEY"="T57460"."DEPARTMENTID";
    So, select * from TST_MV2 should be read by similar way as underlying select to TST_MV2
    DBMS_STATS.GATHER_TABLE_STAT is done for each table and MV.
    Please help to investigate the issue.
    Why TST_MV2 don't used for query rewrite ?
    Kind regards.

    Hi Carlos
    It looks like you have more than one question in your posting. Would I be right in saying that you have an issue with how long Discoverer takes when compared with SQL, and a second issue with regards to MVs not being used? I will add some comments on both. If one of these is not an issue please inform.
    Issue 1:
    Have you compared the explain plan from Discoverer with SQL? You may need to use a tool like TOAD to see it.
    Also, is Discoverer doing anything complicated with the data after it comes back? By complicated I mean do you have a large number of Page Items and / or Group Sorted items? SQL wouldn't have this overhead you see.
    Because SQL would create a table, have you tried creating a table in Discoverer and seeing how long it takes?
    Finally, what version of the database are you using?
    Issue 2:
    Your initial statement was that query rewrite works with several MV but not with others, yet in the body of the report you only show explain plans that do use the MV. Could you therefore go into some more detail regarding this situation.
    Best wishes
    Michael

  • Help for rewrite or tune this quer

    Hi,
    can u some help to rewrite or tune this quer.
    SELECT 20100201 PERIOD_KEY,CONSUMER_KEY,DOW_KEY  PREFDOW,nvl(FIN_SCOR_DOW,-1),'MONTH' GRANULAR FROM
    SELECT CONSUMER_KEY,DOW_KEY,FIN_SCOR_DOW,
    ROW_NUMBER() OVER ( PARTITION BY CONSUMER_KEY ORDER BY FIN_SCOR_DOW DESC,DOW_KEY ) RNO
    FROM
    SELECT CONSUMER_KEY,DOW_KEY,SUM(SCORE_SERVICE_WEIGHT) FIN_SCOR_DOW FROM
    SELECT DOW_KEY,CONSUMER_KEY,SERVICE_KEY,DUR,TRAN,VOLU,TOT_DUR,CUM_DUR,TOT_TRAN,CUM_TRAN,TOT_VOL,CUM_VOL,SCORE_DUR,SCORE_TRAN,SCORE_VOL,
    1*NVL(SCORE_DUR,0)+1*NVL(SCORE_TRAN,0)+1*NVL(SCORE_VOL,0) TOT_SCOR ,
    CASE
    WHEN SERVICE_KEY= 0 THEN
    1*SCORE_DUR
    WHEN SERVICE_KEY IN ('1','3') THEN
    1*SCORE_TRAN
    WHEN SERVICE_KEY  = 2 THEN
    1*SCORE_VOL
    END SCORE_SERVICE_WEIGHT FROM
    select DOW_KEY,consumer_key,service_key,sumDUR dur,SUMTRAN tran,sumVOL volu,
    tot_dur,cum_dur,tot_tran,cum_tran,tot_vol,cum_vol,
    case
    when tot_dur > 0 then
    cum_dur*100/tot_dur
    end score_dur,
    case
    when tot_tran > 0 then
    cum_tran*100/tot_tran
    end score_tran,
    case
    when tot_vol > 0 then
    cum_vol*100/tot_vol
    end  score_vol
    from
    SELECT CONSUMER_KEY,SERVICE_KEY,DOW_KEY,SUMDUR,SUMTRAN,SUMVOL,SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_DUR,
    SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY) CUM_DUR,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_TRAN,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMTRAN,DOW_KEY) CUM_TRAN,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_VOL,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMVOL,DOW_KEY) CUM_VOL
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    FROM
    SELECT CONSUMER_KEY,SERVICE_KEY, to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')) DOW_KEY,
    sum(SUM_OF_DURATION) sumdur,SUM(NO_OF_TRANSACTIONS) sumtran,sum(SUM_OF_VOLUME) sumvol
    --ROW_NUMBER () OVER (ORDER BY CONSUMER_KEY) RNO
    FROM SERVICE_FACTS_BY_DAY
    WHERE DATE_KEY BETWEEN 20100201 AND 20100228
    group by CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    ORDER BY CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    GROUP BY CONSUMER_KEY,DOW_KEY
    WHERE RNO=1;explain plan
    Plan hash value: 3130556327
    | Id  | Operation                         | Name                 | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                  |                      |   571K|    28M|       |   128K  (1)| 00:29:54 |       |       |
    |*  1 |  VIEW                             |                      |   571K|    28M|       |   128K  (1)| 00:29:54 |       |       |
    |*  2 |   WINDOW SORT PUSHED RANK         |                      |   571K|    59M|   217M|   128K  (1)| 00:29:54 |       |       |
    |   3 |    HASH GROUP BY                  |                      |   571K|    59M|   217M|   128K  (1)| 00:29:54 |       |       |
    |   4 |     VIEW                          |                      |  1713K|   179M|       | 93314   (1)| 00:21:47 |       |       |
    |   5 |      WINDOW SORT                  |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   6 |       WINDOW SORT                 |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   7 |        WINDOW SORT                |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   8 |         VIEW                      |                      |  1713K|   127M|       | 34903   (2)| 00:08:09 |       |       |
    |   9 |          SORT GROUP BY            |                      |  1713K|    40M|   340M| 34903   (2)| 00:08:09 |       |       |
    |  10 |           PARTITION RANGE ITERATOR|                      |  8090K|   192M|       | 13172   (2)| 00:03:05 |     1 |    25 |
    |* 11 |            TABLE ACCESS FULL      | SERVICE_FACTS_BY_DAY |  8090K|   192M|       | 13172   (2)| 00:03:05 |     1 |    25 |
    Predicate Information (identified by operation id):
       1 - filter("RNO"=1)
       2 - filter(ROW_NUMBER() OVER ( PARTITION BY "CONSUMER_KEY" ORDER BY SUM(CASE "SERVICE_KEY" WHEN 0 THEN 1*CASE  WHEN
                  ("TOT_DUR">0) THEN ("CUM_DUR"*100/"TOT_DUR") END  WHEN 1 THEN 1*CASE  WHEN ("TOT_TRAN">0) THEN
                  ("CUM_TRAN"*100/"TOT_TRAN") END  WHEN 3 THEN 1*CASE  WHEN ("TOT_TRAN">0) THEN ("CUM_TRAN"*100/"TOT_TRAN") END  WHEN 2
                  THEN 1*CASE  WHEN ("TOT_VOL">0) THEN ("CUM_VOL"*100/"TOT_VOL") END  END ) DESC ,"DOW_KEY")<=1)
      11 - filter("DATE_KEY"<=20100228 AND "DATE_KEY">=20100201)

    You are posting your request to the Enterprise Manager Grid Control forum.
    So I assume that you are using OEM Grig Control.
    You could then start using the SQL Tuning Advisor to provide you with an alternative query, execution plan etc.
    If you are not using OEM Grid Control, I suggest that you post your request to a Database forum.
    Regards
    Rob

  • No query rewriting in a star schema

    Gentlemen,
    I am facing a problem with query rewriting in a simple data warehouse star schema. I want to take advantage of the built-in roll up along dimensions of a star schema. Therefore, I created several DIMENSIONs and made sure that all foreign key/primary key relationships between fact and dimension tables are set up correctly. In addition, as many table attributes as possible are assigned the NOT NULL constraint, especially the ones that are used by the CHILD Of and ATTRIBUTE relationships.
    I defined materialized views on the fact table and a couple of dimension tables to report on aggregated data. All the MVIEWs are enabled for query rewriting and I have the initialization parameter set correctly (QUERY_REWRITE_INTEGRITY is set to TRUSTED).
    From my tests I learned that a query is rewritten correctly only of the corresponding MVIEW contains the fact table and one dimension table. This is true for every dimension I created. However, as soon as the MVIEW joins more than one dimension table to the fact table the rewriting mechanism fails. It appears that the roll-up (aggregation along the hierarchy) is only possible for one of the dimensions. If the original query suggests rolling-up more than one dimension (e.g., "summarize the key figures by year and product category" but the underlying dimension is based on month and product), the MVIEW is no longer rewritten at all.
    Do you know this effect from your work experience? Is this a bug or have I made a mistake or forgotten to switch on a special feature?
    Here are some technical data of our data warehouse: we are running an Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 on a Windows Server 2003, the size of the database is about 10 GB (excluding indexes), the star schema contains ten dimension tables each one with a simple or parallel hierarchies (e.g. a product dimension). The fact table and the MVIEWS are partitioned by month.
    Any help is very welcome.
    Regards,
    John

    Hi,
    you may ask with DBMS_MVIEW why your query does not get rewritten:
    Maybe you have to create a util table first with
    SQL> @?/rdbms/admin/utlxrw.sql
    Then you ask:
    SQL> begin
    DBMS_MVIEW.EXPLAIN_REWRITE('<your query without ; at the end>');
    end;
    The reason why it is not rewritten:
    SQL> select message from rewrite_table order by sequence;
    Kind regards
    Uwe

  • Help for Rewrite/tune the quey

    Hi,
    Could you please help to rewrite or tune the below query.
    database
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bitQuery
    SELECT *
    FROM
      (SELECT q.*,
        ROWNUM          AS rowindex,
        COUNT(*) OVER() AS record_count
      FROM
        (SELECT get_cand_session_number(ccr.split_session_year,ccr.split_session_month,ccr.candidate) AS candidate_session_number,
          ca.candidate,
          ca.lastname,
          ca.firstname,
          (SELECT csl.status_type
          FROM ibis.cw_status_lookup csl
          WHERE csl.status_id = ccp.status_id
          ) AS status,
          ccp.candidate_portfolio_id
        FROM ibis.candidate_component_reg ccr
        INNER JOIN
          (SELECT self_taught,
            YEAR,
            MONTH,
            main_school,
            candidate,
            subject,
            subject_option,
            lvl,
            language,
            withdrawn,
            programme
          FROM ibis.candidate_subject_registration
          ) csr
        ON csr.year           = :v_year
        AND csr.month         =:v_month
        AND csr.main_school   =ccr.main_school
        AND csr.candidate     =ccr.candidate
        AND csr.subject       =ccr.subject
        AND csr.subject_option=ccr.subject_option
        AND csr.lvl           = ccr.lvl
        AND csr.language      =ccr.language
        AND csr.withdrawn     ='N'
        INNER JOIN
          (SELECT YEAR,
            MONTH,
            candidate,
            programme,
            exam_seq_num
          FROM ibis.candidate_session_detail
          ) csd
        ON csd.year          = :v_year
        AND csd.month        = :v_month
        AND csd.candidate    = csr.candidate
        AND csd.programme    = ccr.programme
        AND csd.exam_seq_num = NVL(NULL,csd.exam_seq_num)
        INNER JOIN
          (SELECT candidate,lastname,firstname FROM ibis.candidate
          ) ca
        ON ca.candidate=csd.candidate
        INNER JOIN
          (SELECT status_id,
            candidate_portfolio_id,
            YEAR,
            MONTH,
            paper_code,
            candidate
          FROM ibis.cw_candidate_portfolio
          ) ccp
        ON ccp.year                  = :v_year
        AND ccp.month                = :v_month
        AND ccp.paper_code           = ccr.paper_code
        AND ccp.candidate            = ccr.candidate
        WHERE ccr.split_session_year = :v_year
        AND ccr.split_session_month  = :v_month
        AND ccr.component            = :v_component
        AND ccr.withdrawn            ='N'
        AND ccr.assessment_school    =NVL(:v_school_code,ccr.assessment_school)
        AND ccr.subject              = NVL(:v_subject,ccr.subject)
        AND ccr.subject_option       = NVL(:v_subject_option,ccr.subject_option)
        AND ccr.lvl                  = NVL(:v_lvl,ccr.lvl)
        AND ccr.language             = NVL(:v_language,ccr.language)
        AND ((csr.self_taught        ='N'
        AND ccr.sampled              ='Y'
        AND ccr.deleted_from_sample  ='N'
        AND EXISTS
          (SELECT 1
          FROM ibis.subject_component sc
          WHERE sc.year               = ccr.split_session_year
          AND sc.month                = ccr.split_session_month
          AND ccr.paper_code          =sc.paper_code
          AND sc.subject              = ccr.subject
          AND sc.subject_option       =ccr.subject_option
          AND sc.lvl                  = ccr.lvl
          AND sc.language             =ccr.language
          AND sc.component            =ccr.component
          AND sc.assessment_method_id = 11
          AND sc.assessment_type      = 'INTERNAL'
        AND NOT EXISTS
          (SELECT 1
          FROM ibis.cw_portfolio_template cpt
          WHERE ccr.split_session_year = cpt.year
          AND ccr.split_session_month  = cpt.month
          AND ccr.subject              = cpt.subject
          AND ccr.subject_option       = cpt.subject_option
          AND ccr.component            = cpt.component
          AND cpt.combined             = 'Y'
        OR (csr.self_taught='Y'
        AND EXISTS
          (SELECT 1
          FROM ibis.subject_component sc
          WHERE sc.year               = ccr.split_session_year
          AND sc.month                = ccr.split_session_month
          AND ccr.paper_code          =sc.paper_code
          AND sc.subject              = ccr.subject
          AND sc.subject_option       =ccr.subject_option
          AND sc.lvl                  = ccr.lvl
          AND sc.language             =ccr.language
          AND sc.component            =ccr.component
          AND sc.assessment_method_id = 11
          AND sc.assessment_type      = 'INTERNAL'
        AND NOT EXISTS
          (SELECT 1
          FROM ibis.cw_portfolio_template cpt
          WHERE ccr.split_session_year = cpt.year
          AND ccr.split_session_month  = cpt.month
          AND ccr.subject              = cpt.subject
          AND ccr.subject_option       = cpt.subject_option
          AND ccr.component            = cpt.component
          AND cpt.combined             = 'Y'
        OR (EXISTS
          (SELECT 1
          FROM ibis.cw_portfolio_template cpt
          WHERE ccr.split_session_year = cpt.year
          AND ccr.split_session_month  = cpt.month
          AND ccr.subject              = cpt.subject
          AND ccr.subject_option       = cpt.subject_option
          AND ccr.component            = cpt.component
          AND cpt.combined             = 'Y'
        AND EXISTS
          (SELECT 1
          FROM ibis.subject_component sc
          WHERE sc.year               = ccr.split_session_year
          AND sc.month                = ccr.split_session_month
          AND ccr.paper_code          =sc.paper_code
          AND sc.subject              = ccr.subject
          AND sc.subject_option       =ccr.subject_option
          AND sc.lvl                  = ccr.lvl
          AND sc.language             =ccr.language
          AND sc.component            =ccr.component
          AND sc.assessment_method_id = 11
        UNION
        SELECT get_cand_session_number(ssm.year,ssm.month,ccr.candidate) AS candidate_session_number,
          ca.candidate,
          ca.lastname,
          ca.firstname,
          (SELECT csl.status_type
          FROM ibis.cw_status_lookup csl
          WHERE csl.status_id = ccp.status_id
          ) AS status,
          ccp.candidate_portfolio_id
        FROM ibis.school_sample_mark_additional ssm,
          ibis.candidate_component_reg ccr,
          ibis.candidate ca,
          ibis.candidate_session_detail csd,
          ibis.cw_candidate_portfolio ccp
        WHERE ssm.year              = :v_year
        AND ssm.month               = :v_month
        AND ssm.candidate          IS NOT NULL
        AND ssm.year                = ccr.split_session_year
        AND ssm.month               =ccr.split_session_month
        AND ccr.assessment_school   =ssm.school_code
        AND ssm.candidate           =ccr.candidate
        AND ssm.paper_code          = ccr.paper_code
        AND ccr.component           = :v_component
        AND ccr.split_session_year  = csd.year
        AND ccr.split_session_month = csd.month
        AND ccr.candidate           =csd.candidate
        AND ccr.programme           = csd.programme
        AND csd.candidate           =ca.candidate
        AND ccr.split_session_year  = ccp.year
        AND ccr.split_session_month = ccp.month
        AND ccr.paper_code          =ccp.paper_code
        AND ccr.candidate           = ccp.candidate
        AND ssm.school_code         = NVL(:v_school_code,ssm.school_code)
        AND ccr.subject             = NVL(:v_subject,ccr.subject)
        AND ccr.subject_option      = NVL(:v_subject_option,ccr.subject_option)
        AND ccr.lvl                 = NVL(:v_lvl,ccr.lvl)
        AND ccr.language            = NVL(:v_language,ccr.language)
        AND csd.exam_seq_num        = NVL(:v_candidate,csd.exam_seq_num)
        )q
      ) sq
    WHERE ROWINDEX >=:v_startrow
    AND ROWINDEX   <= (:v_startrow + (:v_maxrows - 1) );explain plan
    | Id  | Operation                                  | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                               
    |   0 | SELECT STATEMENT                           |                                |     4 |  8708 |   363   (1)| 00:00:06 |                                                                                                                                                                               
    |*  1 |  FILTER                                    |                                |       |       |            |          |                                                                                                                                                                               
    |*  2 |   VIEW                                     |                                |     4 |  8708 |   363   (1)| 00:00:06 |                                                                                                                                                                               
    |   3 |    WINDOW BUFFER                           |                                |     4 |  8604 |   363   (1)| 00:00:06 |                                                                                                                                                                               
    |   4 |     COUNT                                  |                                |       |       |            |          |                                                                                                                                                                               
    |   5 |      VIEW                                  |                                |     4 |  8604 |   363   (1)| 00:00:06 |                                                                                                                                                                               
    |   6 |       SORT UNIQUE                          |                                |     4 |  1016 |   363  (14)| 00:00:06 |                                                                                                                                                                               
    |   7 |        UNION-ALL                           |                                |       |       |            |          |                                                                                                                                                                               
    |   8 |         CONCATENATION                      |                                |       |       |            |          |                                                                                                                                                                               
    |*  9 |          FILTER                            |                                |       |       |            |          |                                                                                                                                                                               
    |* 10 |           FILTER                           |                                |       |       |            |          |                                                                                                                                                                               
    |  11 |            TABLE ACCESS BY INDEX ROWID     | CW_CANDIDATE_PORTFOLIO         |     1 |    44 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |  12 |             NESTED LOOPS                   |                                |     1 |   270 |   299   (1)| 00:00:05 |                                                                                                                                                                               
    |  13 |              NESTED LOOPS                  |                                |     1 |   226 |   296   (1)| 00:00:05 |                                                                                                                                                                               
    |  14 |               NESTED LOOPS                 |                                |     1 |   200 |   294   (1)| 00:00:05 |                                                                                                                                                                               
    |  15 |                NESTED LOOPS                |                                |    35 |  3080 |   190   (1)| 00:00:03 |                                                                                                                                                                               
    |  16 |                 TABLE ACCESS BY INDEX ROWID| CANDIDATE_SESSION_DETAIL       |    35 |   980 |    92   (2)| 00:00:02 |                                                                                                                                                                               
    |* 17 |                  INDEX RANGE SCAN          | SESSION_SCHL_CAND              |    35 |       |    77   (2)| 00:00:02 |                                                                                                                                                                               
    |* 18 |                 TABLE ACCESS BY INDEX ROWID| CANDIDATE_SUBJECT_REGISTRATION |     1 |    60 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 19 |                  INDEX RANGE SCAN          | Y_M_CAND_SUBJ_LVL_OPTION       |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 20 |                TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG        |     1 |   112 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 21 |                 INDEX RANGE SCAN           | SPLIT_SESSION_CANDIDATE        |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |  22 |               TABLE ACCESS BY INDEX ROWID  | CANDIDATE                      |     1 |    26 |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 23 |                INDEX UNIQUE SCAN           | CANDIDATE_PK                   |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                               
    |* 24 |              INDEX RANGE SCAN              | CANDIDATE_PORTFOLIO_INDEX1     |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 25 |           TABLE ACCESS BY INDEX ROWID      | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 26 |            INDEX RANGE SCAN                | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 27 |            TABLE ACCESS BY INDEX ROWID     | SUBJECT_COMPONENT              |     1 |    96 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 28 |             INDEX RANGE SCAN               | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 29 |             TABLE ACCESS BY INDEX ROWID    | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 30 |              INDEX RANGE SCAN              | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 31 |              TABLE ACCESS BY INDEX ROWID   | SUBJECT_COMPONENT              |     1 |    96 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 32 |               INDEX RANGE SCAN             | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 33 |               TABLE ACCESS BY INDEX ROWID  | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 34 |                INDEX RANGE SCAN            | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 35 |                TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT              |     1 |    87 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 36 |                 INDEX RANGE SCAN           | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 37 |          FILTER                            |                                |       |       |            |          |                                                                                                                                                                               
    |* 38 |           FILTER                           |                                |       |       |            |          |                                                                                                                                                                               
    |  39 |            NESTED LOOPS                    |                                |     1 |   270 |    16   (0)| 00:00:01 |                                                                                                                                                                               
    |  40 |             NESTED LOOPS                   |                                |     1 |   244 |    14   (0)| 00:00:01 |                                                                                                                                                                               
    |  41 |              NESTED LOOPS                  |                                |     1 |   216 |    12   (0)| 00:00:01 |                                                                                                                                                                               
    |  42 |               NESTED LOOPS                 |                                |     1 |   156 |     9   (0)| 00:00:01 |                                                                                                                                                                               
    |* 43 |                TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG        |     1 |   112 |     6   (0)| 00:00:01 |                                                                                                                                                                               
    |* 44 |                 INDEX RANGE SCAN           | ASSESSMENT_SPLIT_SESSION       |     1 |       |     5   (0)| 00:00:01 |                                                                                                                                                                               
    |  45 |                TABLE ACCESS BY INDEX ROWID | CW_CANDIDATE_PORTFOLIO         |     1 |    44 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 46 |                 INDEX RANGE SCAN           | CANDIDATE_PORTFOLIO_INDEX1     |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 47 |               TABLE ACCESS BY INDEX ROWID  | CANDIDATE_SUBJECT_REGISTRATION |     1 |    60 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 48 |                INDEX RANGE SCAN            | CAND_REG_SCHOOL                |     1 |       |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 49 |              TABLE ACCESS BY INDEX ROWID   | CANDIDATE_SESSION_DETAIL       |     1 |    28 |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 50 |               INDEX UNIQUE SCAN            | CANDIDATE_DETAIL_PK            |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                               
    |  51 |             TABLE ACCESS BY INDEX ROWID    | CANDIDATE                      |     1 |    26 |     2   (0)| 00:00:01 |                                                                                                                                                                               
    |* 52 |              INDEX UNIQUE SCAN             | CANDIDATE_PK                   |     1 |       |     1   (0)| 00:00:01 |                                                                                                                                                                               
    |* 53 |           TABLE ACCESS BY INDEX ROWID      | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 54 |            INDEX RANGE SCAN                | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 55 |            TABLE ACCESS BY INDEX ROWID     | SUBJECT_COMPONENT              |     1 |    96 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 56 |             INDEX RANGE SCAN               | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 57 |             TABLE ACCESS BY INDEX ROWID    | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 58 |              INDEX RANGE SCAN              | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 59 |              TABLE ACCESS BY INDEX ROWID   | SUBJECT_COMPONENT              |     1 |    96 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 60 |               INDEX RANGE SCAN             | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 61 |               TABLE ACCESS BY INDEX ROWID  | CW_PORTFOLIO_TEMPLATE          |     1 |    46 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 62 |                INDEX RANGE SCAN            | YEAR_MON_PORTFOLIO_TEMPLATE    |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |* 63 |                TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT              |     1 |    87 |     4   (0)| 00:00:01 |                                                                                                                                                                               
    |* 64 |                 INDEX RANGE SCAN           | SUBJECT_COMPONENT_PK           |     1 |       |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |  65 |         CONCATENATION                      |                                |       |       |            |          |                                                                                                                                                                               
    |* 66 |          FILTER                            |                                |       |       |            |          |                                                                                                                                                                               
    |  67 |           TABLE ACCESS BY INDEX ROWID      | CW_CANDIDATE_PORTFOLIO         |     1 |    44 |     3   (0)| 00:00:01 |                                                                                                                                                                               
    |  68 |            NESTED LOOPS                    |                                |     1 |   238 |    23   (0)| 00:00:01 |                                                                                                                                                                               
    |  69 |             NESTED LOOPS                   |                                |     1 |   194 |    20   (0)| 00:00:01 |                                                                                                                                                                               
    |  70 |              NESTED LOOPS                  |                                |     1 |   168 |    18   (0)| 00:00:01 |Edited by: user575115 on

    Hi
    i have seen your query and i am nt changing the whole query but i'll recommend some of the changes it may helps in the performance tuning...
    1) write all the filter conditions in the FROM clause in correspondence to the tables for ex :
    One way : select * from tab a, tab1 b where a.c = b.c and a.d in ('xx','lll')
    Tuned way : select * from (select c from tab where d in ('xx','lll')) a, tab b where a.c = b.c (it provides lesser rows for joining)
    2) Donot write Inline query in the select statement.You can try it.
    for ex:
    One way : select a.c, (select d from tab1 where tab1.d = a.e) from tab a
    tuned way : select a.c, tab1.d from tab a, tab1 where tab1.d = a.e
    3) Check the gathering of stats in 10G
    4) Avoid using ANSI standered for JOINS for ex : Instead of select * from a inner join a on ... use select * from a, b where joining cond.(I am not confirmed)
    5) If possible here use the WITH clause becuase you have use UNION and you have use some common tables which are executing twice in the current.
    6) Use some HINTS like FIRST_ROWS
    If somewhere i am wrong please correct me.
    Edited by: user9292111 on 22-Mar-2012 01:52
    Edited by: user9292111 on 22-Mar-2012 01:53

  • Query rewrite for COUNT(DISTINCT)

    Hi,
    I am having fact table with different dimension keys.
    CREATE TABLE FACT
    TIME_SKEY NUMBER
    REGION_SKEY NUMBER,
    AC_SKEY NUMBER
    I need to take COUNT(DISTINCT(AC_SKEY) for TIME_SKEY and REGION_SKEY. There are oracle dimension defined for time and region which are using TIME_SKEY and REGION_SKEY. I have created MV with query rewrite with COUNT(DISTINCT) but it is not using dimension if I am using any other level and MV can't be fast refreshed as it was build using COUNT(DISTINCT).
    CREATE MATERIALIZED VIEW AC_MV
    NOCACHE
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    WITH PRIMARY KEY
    ENABLE QUERY REWRITE
    AS
    SELECT
    TIME_SKEY ,
    REGION_SKEY,
    COUNT (DISTINCTAC_SKEY)
    FROM FACT
    GROUP BY TIME_SKEY, REGION_SKEY;
    Query used to retrieve data is as below
    SELECT TIME_SKEY, COUNT(DISTINCT AC_SKEY) OVER (PARTITION BY TIME_SKEY) UNIQ_AC, COUNT(DISTINCT AC_SKEY) OVER () UNIQ_AC1
    FROM FACT;
    There can be other queries based on time / region dimension.
    Can you please provide help in solving above issue?
    Thanks,
    Pritesh

    What version of the Oracle database?

Maybe you are looking for

  • Reports - Reason for rejection for a Sales Org.

    Hi, I need to generate a report wherein I want to analyze the reasons for  rejection for a particular sales organization. Are there any standard reports available. If not how do I go about it. Thanks in advance. Regards Mahesh

  • Data extraction using ODS objects

    Hello everybody, I am trying to extract CRM data into SAP BW. Found a standard ODS Object 0CRMBPKPI, which i think is relavent as i need to extract Business partner data from CRM. Does anybody know the procedure how to extract data using this ODS obj

  • Spry IE Memory issue

    Hi, I'm having a major headache with IE 7 caching issues at the moment. I've tried adding all the no-cache headers to both the generated xml, and the actual spry page to no avail. I've also tried using random characters to the xml file and changing t

  • Conversion of PSE 6 Catalog to PSE 8 fails

    I recently purchased PSE 8 and installed it on my computer.  When I attempted to convert the PSE 6 catalog, I get the error message that the conversion failed and to repair the catalog with the original program.  I had the program to seach for discon

  • Oracle RAC on different SunServer

    Hi forum, I have one question regarding Oracle RAC requirements. As far as I know base requirements are: OS should be similar OS Patch Level should be similar kernel parameters should be similar And servers architecture should be the same Can I confi