Modify query used in Materialized View

Are there any ways to modify the query used in materialized view without dropping the materialized view. I dont think alter materialized view has such an option.
Please provider me your suggestions.

you have to give "ENABLE QUERY REWRITE" option then u can change your query

Similar Messages

  • Very high parse times for query rewrite using cube materialized views

    We recently upgraded to version 11.2.0.2 (both AWM and Oracle database server). We are using cube materialized views with query rewrite enabled. Some observations of changes that took place when we rebuilt all the dimensions and cubes in this version:
    1. Queries against the base tables take about 35 seconds to parse. Then they execute in a tenth of a second. Even simple queries that just get a sum of the amount from the fact table (which is joined to all the dimensions) takes that long to parse. Once parsed, the queries fly.
    2. I noticed that the materialized views used to use grouping sets in the group by clause in version 11.2.0.1, but now they use group by rollup, rollup, rollup...
    If we disable query rewrite on the MV or for my session, parse times drop to less than a second. Ideas?

    There does appear to be a slow down in parse times between 11.1.0.7 and 11.2. We are still investigating this, but in the meantime here is a way to force the code in 11.2 to generate a GROUPING SETS clause instead of the new ROLLUP syntax.
    The trick is to create a dummy hierarchy containing only the leaf level. This is necessary for all dimensions that currently have a single hierarchy. As a simple example I created a dimension, PROD, with three levels, A, B, and C, in a single hierarchy. I then created a one dimensional cube, PC. Here is the SELECT statement for the MV in 11.2. Note the ROLLUP clause in the GROUP BY.
    SELECT
      GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")  SYS_GID,
      (CASE GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")
       WHEN 3
       THEN TO_CHAR(('A_' || T3."CLASS_ID") )
       WHEN 1
       THEN TO_CHAR(('B_' || T3."FAMILY_ID") )
       ELSE TO_CHAR(('C_' || T3."ITEM_ID") )  END)     "PROD",
      T3."CLASS_ID" "D1_PROD_A_ID",
      T3."FAMILY_ID" "D1_PROD_B_ID",
      T3."ITEM_ID" "D1_PROD_C_ID",
      SUM(T2."UNIT_PRICE")     "PRICE",
      COUNT(T2."UNIT_PRICE")  "COUNT_PRICE",
      COUNT(*)  "SYS_COUNT"
    FROM
      GLOBAL."PRICE_AND_COST_FACT" T2,
      GLOBAL."PRODUCT_DIM" T3
    WHERE
      (T3."ITEM_ID" = T2."ITEM_ID")
    GROUP BY
      (T3."CLASS_ID") ,
      ROLLUP ((T3."FAMILY_ID") , (T3."ITEM_ID") )Next I modified the dimension to add a new hierarchy, DUMMY, containing just the leaf level, C. Once I have mapped the new level and re-enabled MVs, I get the following formulation.
    SELECT
      GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")  SYS_GID,
      (CASE GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")
       WHEN 3
       THEN ('A_' || T3."CLASS_ID")
       WHEN 1
       THEN ('B_' || T3."FAMILY_ID")
       WHEN 0
       THEN ('C_' || T3."ITEM_ID")
       ELSE NULL END)  "PROD",
      T3."CLASS_ID" "D1_PROD_A_ID",
      T3."FAMILY_ID" "D1_PROD_B_ID",
      T3."ITEM_ID" "D1_PROD_C_ID",
      SUM(T2."UNIT_PRICE")     "PRICE",
      COUNT(T2."UNIT_PRICE")  "COUNT_PRICE",
      COUNT(*)  "SYS_COUNT"
    FROM
      GLOBAL."PRICE_AND_COST_FACT" T2,
      GLOBAL."PRODUCT_DIM" T3
    WHERE
      (T3."ITEM_ID" = T2."ITEM_ID")
    GROUP BY
      GROUPING SETS ((T3."CLASS_ID") , (T3."FAMILY_ID", T3."CLASS_ID") , (T3."ITEM_ID", T3."FAMILY_ID", T3."CLASS_ID") )This puts things back the way they were in 11.1.0.7 when the GROUPING SETS clause was used in all cases. Note that the two queries are logically equivalent.

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

  • Do I need to tune the base query of my materialized view ?

    Hi gurus,
    We implement materialized view (FAST REFRESH ON COMMIT) on base table used in OLTP system. In fact the MV itself is also queried by the OLTP system itself, interactively.
    Currently user complain that after they input transaction, they see that the MV is not refresh as soon as they commit the transaction.
    (it takes 5 to 10 minutes before they see the update on the MV)
    The query of the MV is attached below, it consists of union all of two queries but actually the real query has 13 queries on a UNION ALL.
    The question is :
    Do I need to tune the query that forms the MV ?
    Does it impact the refresh time of the MV ?
    Thank you for your help,
    xtanto
    SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
    F_Convert_Qty_K(GRND.PRODUCT, GRND.QTY, GRND.UOM) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'.....
    FROM GRN_LOCAL_D GRND
              JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
              WHERE GRND.PRODUCT IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
    UNION ALL
    SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
    F_Convert_Qty_K(GRND.PRODUCT_B, GRND.QTY_B, GRND.UOM_B) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'...
    FROM GRN_LOCAL_D GRND
    JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
    WHERE GRND.PRODUCT_B IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
    UNION ALL
         ......

    Hi Justin & APC,
    Are they seeing a 5-10 minute delay in being able to commit their transaction?NO, the commit itself is completed normally, but after that when they go to the page (this is webbased app) that display data from the MV, the newly committed transactionis not there yet. Only after 5-10 minutes we can see the new data.
    What does the F_Convert_Qty_K() function do?It is a function that convert the quantity from whatever Unit Of Measurement (UOM) into the smallest UOM. Below is the code.
    So the question remains:
    why intermittently theere is delay before the new data visible in the MV ?
    Thanks you,
    xtanto
    CREATE OR REPLACE FUNCTION F_Convert_Qty (pProduct VARCHAR2, pQty NUMBER, pUOM VARCHAR2)
    RETURN NUMBER
    IS
    vQtyBase NUMBER(13,5);
    BEGIN
    SELECT CASE WHEN pUOM = ( SELECT UOM_BASE FROM PRODUCTS WHERE PRODUCT = pProduct)
              THEN pQty
         ELSE
                   SELECT ROUND(pQty * Coefficient / Divisor, 5)
                   FROM (
                             SELECT Coefficient, Divisor FROM CONVERT_UOM
                             WHERE PRODUCT = pProduct AND UOM_CONVERT = pUOM
                             ) tmp
              END INTO vQtyBase FROM DUAL;
    --RETURN (vQtyBase) ;
    RETURN ( NVL(vQtyBase,0) ) ;
    END F_Convert_Qty;
    /

  • Usage of Query Rewrite in Materialized Views

    Hi,
    I have a star schema with fact table and and dimensions tables.
    One of the dimension tables is time_dimension and I have created
    a materialized view(time_sales_mv) on it and the fact table. I
    have also created a dimension(time_dim) on the
    table 'time_dimension' with hierarchies and attributes.
    Following are the syntaxes -
    --Dimension table
    CREATE TABLE TIME_DIMENSION (
    TIME_KEY NUMBER(9) NOT NULL,
    DAY_OF_MONTH NUMBER(9),
    WEEKDAY NUMBER(9),
    WEEKEND NUMBER(9),
    JULIAN_DAY NUMBER(9),
    JULIAN_WEEK NUMBER(9),
    JULIAN_YEAR NUMBER(9),
    MONTH_NUMBER NUMBER(9),
    MONTH_NAME VARCHAR2(15),
    WEEK_OF_THE_YEAR NUMBER(9),
    WEEKDAY_NAME VARCHAR2(10),
    WEEK_DAY_NUMBER NUMBER(9),
    THE_YEAR NUMBER(9),
    DAY_OF_THE_YEAR NUMBER(9),
    THE_DATE DATE,
    THE_QUARTER NUMBER(9),
    PRIMARY KEY ( TIME_KEY )) ;
    --Fact table
    CREATE TABLE SALES_FACT (
    TIME_KEY NUMBER(9) NOT NULL,
    PRODUCT_KEY NUMBER(9) NOT NULL,
    PROMOTION_KEY NUMBER(9) NOT NULL,
    CUSTOMER_KEY NUMBER(9) NOT NULL,
    DOLLAR_SALES FLOAT,
    UNIT_SALES NUMBER(9),
    DOLLAR_COST FLOAT)
    -- Dimension created
    CREATE DIMENSION Time_dim
    LEVEL THE_DATE IS TIME_DIMENSION.THE_DATE
    LEVEL WEEK_OF_THE_YEAR IS time_dimension.WEEK_OF_THE_YEAR
    LEVEL MONTH_NUMBER IS time_dimension.MONTH_NUMBER
    LEVEL THE_QUARTER IS time_dimension.THE_QUARTER
    LEVEL THE_YEAR IS time_dimension.THE_YEAR
    HIERARCHY calendar_rollup (
         THE_DATE CHILD OF
         MONTH_NUMBER CHILD OF
         THE_QUARTER CHILD OF
         THE_YEAR )
    HIERARCHY weekly_rollup (
         THE_DATE CHILD OF
    WEEK_OF_THE_YEAR )
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.DAY_OF_MONTH
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.WEEKDAY
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.JULIAN_DAY
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.DAY_OF_THE_YEAR
    ATTRIBUTE MONTH_NUMBER DETERMINES
    time_dimension_sagar.month_name
    ATTRIBUTE THE_YEAR DETERMINES
    time_dimension_sagar.JULIAN_YEAR;
    -- Materialized View
    CREATE MATERIALIZED VIEW time_sales_mv
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    ENABLE QUERY REWRITE
    AS
    SELECT t.month_number, SUM
    (dollar_sales) AS sum_dollar_sales
    FROM sales_fact s,time_dimension t
    WHERE t.time_key =
    s.time_key GROUP BY
    t.month_number
    Now if I use the same query as in the MV and see the explain
    plan it shows the MV is being used instead of the underlying
    tables which is as expected. But if I change 'month_number'
    to 'month_name' in the above query, the explain plan does not
    use the MV which is not as expected. Since 'month_name' is an
    attribute of 'month_number'(defined in the dimension
    definition), we can use it and query rewrite feature will join
    the MV to the time_dimension table. But in the actual plan, it
    uses the fact table 'sales_fact' instead of the MV. Even when I
    use the rewrite hint on the query it does not use the MV. I want
    know why this is happening??
    Query-
    SELECT t.month_number, SUM(dollar_sales) AS
    sum_dollar_sales FROM
    sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_number
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=82 Bytes=2132)
    TABLE ACCESS (FULL) OF TIME_SALES_MV (Cost=1 Card=82
    Bytes=2132)
    Query(using month_name instead of month_number)-
    SELECT t.month_name, SUM(dollar_sales)
    FROM sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_name
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=151 Card=9053
    Bytes=307802)
    SORT (GROUP BY) (Cost=151 Card=9053 Bytes=307802)
    HASH JOIN (Cost=16 Card=9053 Bytes=307802)
    TABLE ACCESS (FULL) OF TIME_DIMENSION_SAGAR (Cost=1
    Card=82 Bytes=1804)
    TABLE ACCESS (FULL) OF SALES_FACT (Cost=10 Card=11040
    Bytes=132480)
    Query (using rewrite hint in the above query) -
    SELECT /*+ rewrite(time_sales_mv)*/
    t.month_name, SUM
    (dollar_sales)
    FROM sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_name
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=151 Card=9053
    Bytes=307802)
    SORT (GROUP BY) (Cost=151 Card=9053 Bytes=307802)
    HASH JOIN (Cost=16 Card=9053 Bytes=307802)
    TABLE ACCESS (FULL) OF TIME_DIMENSION_SAGAR (Cost=1
    Card=82 Bytes=1804)
    TABLE ACCESS (FULL) OF SALES_FACT (Cost=10 Card=11040
    Bytes=132480)

    Hi,
    I have a star schema with fact table and and dimensions tables.
    One of the dimension tables is time_dimension and I have created
    a materialized view(time_sales_mv) on it and the fact table. I
    have also created a dimension(time_dim) on the
    table 'time_dimension' with hierarchies and attributes.
    Following are the syntaxes -
    --Dimension table
    CREATE TABLE TIME_DIMENSION (
    TIME_KEY NUMBER(9) NOT NULL,
    DAY_OF_MONTH NUMBER(9),
    WEEKDAY NUMBER(9),
    WEEKEND NUMBER(9),
    JULIAN_DAY NUMBER(9),
    JULIAN_WEEK NUMBER(9),
    JULIAN_YEAR NUMBER(9),
    MONTH_NUMBER NUMBER(9),
    MONTH_NAME VARCHAR2(15),
    WEEK_OF_THE_YEAR NUMBER(9),
    WEEKDAY_NAME VARCHAR2(10),
    WEEK_DAY_NUMBER NUMBER(9),
    THE_YEAR NUMBER(9),
    DAY_OF_THE_YEAR NUMBER(9),
    THE_DATE DATE,
    THE_QUARTER NUMBER(9),
    PRIMARY KEY ( TIME_KEY )) ;
    --Fact table
    CREATE TABLE SALES_FACT (
    TIME_KEY NUMBER(9) NOT NULL,
    PRODUCT_KEY NUMBER(9) NOT NULL,
    PROMOTION_KEY NUMBER(9) NOT NULL,
    CUSTOMER_KEY NUMBER(9) NOT NULL,
    DOLLAR_SALES FLOAT,
    UNIT_SALES NUMBER(9),
    DOLLAR_COST FLOAT)
    -- Dimension created
    CREATE DIMENSION Time_dim
    LEVEL THE_DATE IS TIME_DIMENSION.THE_DATE
    LEVEL WEEK_OF_THE_YEAR IS time_dimension.WEEK_OF_THE_YEAR
    LEVEL MONTH_NUMBER IS time_dimension.MONTH_NUMBER
    LEVEL THE_QUARTER IS time_dimension.THE_QUARTER
    LEVEL THE_YEAR IS time_dimension.THE_YEAR
    HIERARCHY calendar_rollup (
         THE_DATE CHILD OF
         MONTH_NUMBER CHILD OF
         THE_QUARTER CHILD OF
         THE_YEAR )
    HIERARCHY weekly_rollup (
         THE_DATE CHILD OF
    WEEK_OF_THE_YEAR )
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.DAY_OF_MONTH
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.WEEKDAY
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.JULIAN_DAY
    ATTRIBUTE THE_DATE DETERMINES
    time_dimension_sagar.DAY_OF_THE_YEAR
    ATTRIBUTE MONTH_NUMBER DETERMINES
    time_dimension_sagar.month_name
    ATTRIBUTE THE_YEAR DETERMINES
    time_dimension_sagar.JULIAN_YEAR;
    -- Materialized View
    CREATE MATERIALIZED VIEW time_sales_mv
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    ENABLE QUERY REWRITE
    AS
    SELECT t.month_number, SUM
    (dollar_sales) AS sum_dollar_sales
    FROM sales_fact s,time_dimension t
    WHERE t.time_key =
    s.time_key GROUP BY
    t.month_number
    Now if I use the same query as in the MV and see the explain
    plan it shows the MV is being used instead of the underlying
    tables which is as expected. But if I change 'month_number'
    to 'month_name' in the above query, the explain plan does not
    use the MV which is not as expected. Since 'month_name' is an
    attribute of 'month_number'(defined in the dimension
    definition), we can use it and query rewrite feature will join
    the MV to the time_dimension table. But in the actual plan, it
    uses the fact table 'sales_fact' instead of the MV. Even when I
    use the rewrite hint on the query it does not use the MV. I want
    know why this is happening??
    Query-
    SELECT t.month_number, SUM(dollar_sales) AS
    sum_dollar_sales FROM
    sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_number
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=82 Bytes=2132)
    TABLE ACCESS (FULL) OF TIME_SALES_MV (Cost=1 Card=82
    Bytes=2132)
    Query(using month_name instead of month_number)-
    SELECT t.month_name, SUM(dollar_sales)
    FROM sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_name
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=151 Card=9053
    Bytes=307802)
    SORT (GROUP BY) (Cost=151 Card=9053 Bytes=307802)
    HASH JOIN (Cost=16 Card=9053 Bytes=307802)
    TABLE ACCESS (FULL) OF TIME_DIMENSION_SAGAR (Cost=1
    Card=82 Bytes=1804)
    TABLE ACCESS (FULL) OF SALES_FACT (Cost=10 Card=11040
    Bytes=132480)
    Query (using rewrite hint in the above query) -
    SELECT /*+ rewrite(time_sales_mv)*/
    t.month_name, SUM
    (dollar_sales)
    FROM sales_fact s, time_dimension t
    WHERE t.time_key = s.time_key
    GROUP BY t.month_name
    Explain Plan -
    SELECT STATEMENT Optimizer=CHOOSE (Cost=151 Card=9053
    Bytes=307802)
    SORT (GROUP BY) (Cost=151 Card=9053 Bytes=307802)
    HASH JOIN (Cost=16 Card=9053 Bytes=307802)
    TABLE ACCESS (FULL) OF TIME_DIMENSION_SAGAR (Cost=1
    Card=82 Bytes=1804)
    TABLE ACCESS (FULL) OF SALES_FACT (Cost=10 Card=11040
    Bytes=132480)

  • Use of materialized views?

    can any one tell me the use of materilized views in oracle?
    explain briefly please...........

    ratnakar wrote:
    can any one tell me the use of materilized views in oracle?
    explain briefly please...........In Views, what happens is there is not data storage in it. Every time you execute the View, it has to pull the data using its query from the Base tables.
    Materialized Views are replica (or Snapshot ) of data from some master site to another site.
    It has the capability to store data. When you execute the MView it pulls data stored in it.
    There is something called as MView Refresh which pulls data from the base tables and stores in this MView's storage unit. And when you read the MView data is pulled from this storage unit (and doesn't hit the base tables).
    This somewhat ensures data availability always.
    Please read this thoroughly... http://docs.oracle.com/cd/B28359_01/server.111/b28326/repmview.htm

  • Query performance on materialized view vs master tables

    Hi,
    I am afraid of strange behavior in db, on my master tables UDBMOVEMENT_ORIG(26mil.rows) and UDBIDENTDATA_ORIG(18mil.rows) is created materialized view TMP_MS_UDB_MV (UDBMOVEMENT is synonym to this object) which meets some default conditions and join condition on these master tables. MV got about 12milions rows. I created MV to query not so huge objects, MV got 3GB, master tables toghether 12GB. But I don't understand that even physical reads and consistent gets are less on MV than on master tables, the final execution time is shorter on master tables. See my log below.
    Why?
    Thanks for answers.
    SQL> set echo on
    SQL> @flush
    SQL> alter system flush buffer_cache;
    System altered.
    Elapsed: 00:00:00.20
    SQL> alter system flush shared_pool;
    System altered.
    Elapsed: 00:00:00.65
    SQL> SELECT
    2 UDBMovement.zIdDevice, UDBMovement.sDevice, UDBMovement.zIdLocal, UDBMovement.sComputer, UDBMovement.tActionTime, UDBIdentData.sCardSubType, UDBIdentData.sCardType, UDBMovement.cEpan, UDBMovement.cText, UDBMovement.lArtRef, UDBMovement.sArtClassRef, UDBMovement.lSequenz, UDBMovement.sTransMark, UDBMovement.lBlock, UDBMovement.sTransType, UDBMovement.lGlobalID, UDBMovement.sFacility, UDBIdentData.sCardClass, UDBMovement.lSingleAmount, UDBMovement.sVAT, UDBMovement.lVATTot, UDBIdentData.tTarifTimeStart, UDBIdentData.tTarifTimeEnd, UDBIdentData.cLicensePlate, UDBIdentData.lMoneyValue, UDBIdentData.lPointValue, UDBIdentData.lTimeValue, UDBIdentData.tProdTime, UDBIdentData.tExpireDate
    3 FROM UDBMOVEMENT_orig UDBMovement, Udbidentdata_orig UDBIdentData
    4 WHERE
    5 UDBMovement.lGlobalId = UDBIdentData.lGlobalRef(+) AND UDBMovement.sComputer = UDBIdentData.sComputer(+)
    6 AND UDBMovement.sTransType > 0 AND UDBMovement.sDevice < 1000 AND UDBMovement.sDevice>= 0 AND UDBIdentData.sCardType IN (2) AND (bitand(UDBMovement.sSaleFlag,1) = 0 AND bitand(UDBMovement.sSaleFlag,4) = 0) AND UDBMovement.sArtClassRef < 100
    7 AND UDBMovement.tActionTime >= TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.25 AND UDBMovement.tActionTime < TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.5
    8 ORDER BY tActionTime, lBlock, lSequenz;
    4947 rows selected.
    Elapsed: 00:00:15.84
    Execution Plan
    Plan hash value: 1768406139
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 7166 | 1238K| | 20670 (1)| 00:04:09 |
    | 1 | SORT ORDER BY | | 7166 | 1238K| 1480K| 20670 (1)| 00:04:09 |
    | 2 | NESTED LOOPS | | | | | | |
    | 3 | NESTED LOOPS | | 7166 | 1238K| | 20388 (1)| 00:04:05 |
    |* 4 | TABLE ACCESS BY INDEX ROWID| UDBMOVEMENT_ORIG | 7142 | 809K| | 7056 (1)| 00:01:25 |
    |* 5 | INDEX RANGE SCAN | IDX_UDBMOVARTICLE | 10709 | | | 61 (0)| 00:00:01 |
    |* 6 | INDEX UNIQUE SCAN | UDBIDENTDATA_PRIM | 1 | | | 1 (0)| 00:00:01 |
    |* 7 | TABLE ACCESS BY INDEX ROWID | UDBIDENTDATA_ORIG | 1 | 61 | | 2 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    4 - filter("UDBMOVEMENT"."STRANSTYPE">0 AND "UDBMOVEMENT"."SDEVICE"<1000 AND
    BITAND("SSALEFLAG",1)=0 AND "UDBMOVEMENT"."SDEVICE">=0 AND BITAND("UDBMOVEMENT"."SSALEFLAG",4)=0)
    5 - access("UDBMOVEMENT"."TACTIONTIME">=TO_DATE(' 2011-05-05 06:00:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "UDBMOVEMENT"."TACTIONTIME"<TO_DATE(' 2011-05-05 12:00:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "UDBMOVEMENT"."SARTCLASSREF"<100)
    filter("UDBMOVEMENT"."SARTCLASSREF"<100)
    6 - access("UDBMOVEMENT"."LGLOBALID"="UDBIDENTDATA"."LGLOBALREF" AND
    "UDBMOVEMENT"."SCOMPUTER"="UDBIDENTDATA"."SCOMPUTER")
    7 - filter("UDBIDENTDATA"."SCARDTYPE"=2)
    Statistics
    543 recursive calls
    0 db block gets
    84383 consistent gets
    4485 physical reads
    0 redo size
    533990 bytes sent via SQL*Net to client
    3953 bytes received via SQL*Net from client
    331 SQL*Net roundtrips to/from client
    86 sorts (memory)
    0 sorts (disk)
    4947 rows processed
    SQL> @flush
    SQL> alter system flush buffer_cache;
    System altered.
    Elapsed: 00:00:00.12
    SQL> alter system flush shared_pool;
    System altered.
    Elapsed: 00:00:00.74
    SQL> SELECT UDBMovement.zIdDevice, UDBMovement.sDevice, UDBMovement.zIdLocal, UDBMovement.sComputer, UDBMovement.tActionTime, UDBMovement.sCardSubType, UDBMovement.sCardType, UDBMovement.cEpan, UDBMovement.cText, UDBMovement.lArtRef, UDBMovement.sArtClassRef, UDBMovement.lSequenz, UDBMovement.sTransMark, UDBMovement.lBlock, UDBMovement.sTransType, UDBMovement.lGlobalID, UDBMovement.sFacility, UDBMovement.sCardClass, UDBMovement.lSingleAmount, UDBMovement.sVAT, UDBMovement.lVATTot, UDBMovement.tTarifTimeStart, UDBMovement.tTarifTimeEnd, UDBMovement.cLicensePlate, UDBMovement.lMoneyValue, UDBMovement.lPointValue, UDBMovement.lTimeValue, UDBMovement.tProdTime
    2 FROM UDBMOVEMENT WHERE
    3 UDBMovement.sTransType > 0 AND UDBMovement.sDevice < 1000 AND UDBMovement.sDevice>= 0 AND UDBMovement.sCardType IN (2) AND (bitand(UDBMovement.sSaleFlag,1) = 0 AND bitand(UDBMovement.sSaleFlag,4) = 0) AND UDBMovement.sArtClassRef < 100
    4 AND UDBMovement.tActionTime >= TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.25
    5 AND UDBMovement.tActionTime < TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.5 ORDER BY tActionTime, lBlock, lSequenz;
    4947 rows selected.
    Elapsed: 00:00:26.46
    Execution Plan
    Plan hash value: 3648898312
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 2720 | 443K| 2812 (1)| 00:00:34 |
    | 1 | SORT ORDER BY | | 2720 | 443K| 2812 (1)| 00:00:34 |
    |* 2 | MAT_VIEW ACCESS BY INDEX ROWID| TMP_MS_UDB_MV | 2720 | 443K| 2811 (1)| 00:00:34 |
    |* 3 | INDEX RANGE SCAN | EEETMP_MS_ACTTIMEDEVICE | 2732 | | 89 (0)| 00:00:02 |
    Predicate Information (identified by operation id):
    2 - filter("UDBMOVEMENT"."STRANSTYPE">0 AND BITAND("UDBMOVEMENT"."SSALEFLAG",4)=0 AND
    BITAND("SSALEFLAG",1)=0 AND "UDBMOVEMENT"."SARTCLASSREF"<100)
    3 - access("UDBMOVEMENT"."TACTIONTIME">=TO_DATE(' 2011-05-05 06:00:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "UDBMOVEMENT"."SDEVICE">=0 AND "UDBMOVEMENT"."SCARDTYPE"=2 AND
    "UDBMOVEMENT"."TACTIONTIME"<TO_DATE(' 2011-05-05 12:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
    "UDBMOVEMENT"."SDEVICE"<1000)
    filter("UDBMOVEMENT"."SCARDTYPE"=2 AND "UDBMOVEMENT"."SDEVICE"<1000 AND
    "UDBMOVEMENT"."SDEVICE">=0)
    Statistics
    449 recursive calls
    0 db block gets
    6090 consistent gets
    2837 physical reads
    0 redo size
    531987 bytes sent via SQL*Net to client
    3953 bytes received via SQL*Net from client
    331 SQL*Net roundtrips to/from client
    168 sorts (memory)
    0 sorts (disk)
    4947 rows processed
    SQL> spool off
    Edited by: MattSk on Feb 4, 2013 2:20 PM

    I have added some tkprof outputs on MV and master tables:
    SELECT tmp_ms_udb_mv.zIdDevice, tmp_ms_udb_mv.sDevice, tmp_ms_udb_mv.zIdLocal, tmp_ms_udb_mv.sComputer, tmp_ms_udb_mv.tActionTime, tmp_ms_udb_mv.sCardSubType, tmp_ms_udb_mv.sCardType, tmp_ms_udb_mv.cEpan, tmp_ms_udb_mv.cText, tmp_ms_udb_mv.lArtRef, tmp_ms_udb_mv.sArtClassRef, tmp_ms_udb_mv.lSequenz, tmp_ms_udb_mv.sTransMark, tmp_ms_udb_mv.lBlock, tmp_ms_udb_mv.sTransType, tmp_ms_udb_mv.lGlobalID, tmp_ms_udb_mv.sFacility, tmp_ms_udb_mv.sCardClass, tmp_ms_udb_mv.lSingleAmount, tmp_ms_udb_mv.sVAT, tmp_ms_udb_mv.lVATTot, tmp_ms_udb_mv.tTarifTimeStart, tmp_ms_udb_mv.tTarifTimeEnd, tmp_ms_udb_mv.cLicensePlate, tmp_ms_udb_mv.lMoneyValue, tmp_ms_udb_mv.lPointValue, tmp_ms_udb_mv.lTimeValue, tmp_ms_udb_mv.tProdTime
    FROM tmp_ms_udb_mv WHERE
    tmp_ms_udb_mv.sTransType > 0 AND tmp_ms_udb_mv.sDevice < 1000 AND tmp_ms_udb_mv.sDevice>= 0 AND tmp_ms_udb_mv.sCardType IN (1) AND (bitand(tmp_ms_udb_mv.sSaleFlag,1) = 0 AND bitand(tmp_ms_udb_mv.sSaleFlag,4) = 0) AND tmp_ms_udb_mv.sArtClassRef < 100
    AND tmp_ms_udb_mv.tActionTime >= TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.25
    AND tmp_ms_udb_mv.tActionTime < TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.5
    ORDER BY tActionTime, lBlock, lSequenz
    call count cpu elapsed disk query current rows
    Parse 1 0.04 0.10 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 596 0.17 27.07 2874 8894 0 8925
    total 598 0.21 27.18 2874 8894 0 8925
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 60
    Rows Row Source Operation
    8925 SORT ORDER BY (cr=8894 pr=2874 pw=0 time=27071773 us)
    8925 MAT_VIEW ACCESS BY INDEX ROWID TMP_MS_UDB_MV (cr=8894 pr=2874 pw=0 time=31458291 us)
    8925 INDEX RANGE SCAN EEETMP_MS_ACTTIMEDEVICE (cr=68 pr=68 pw=0 time=161347 us)(object id 149251)
    SELECT
    UDBMovement.zIdDevice, UDBMovement.sDevice, UDBMovement.zIdLocal, UDBMovement.sComputer, UDBMovement.tActionTime, UDBIdentData.sCardSubType, UDBIdentData.sCardType, UDBMovement.cEpan, UDBMovement.cText, UDBMovement.lArtRef, UDBMovement.sArtClassRef, UDBMovement.lSequenz, UDBMovement.sTransMark, UDBMovement.lBlock, UDBMovement.sTransType, UDBMovement.lGlobalID, UDBMovement.sFacility, UDBIdentData.sCardClass, UDBMovement.lSingleAmount, UDBMovement.sVAT, UDBMovement.lVATTot, UDBIdentData.tTarifTimeStart, UDBIdentData.tTarifTimeEnd, UDBIdentData.cLicensePlate, UDBIdentData.lMoneyValue, UDBIdentData.lPointValue, UDBIdentData.lTimeValue, UDBIdentData.tProdTime, UDBIdentData.tExpireDate
    FROM UDBMOVEMENT_orig UDBMovement, Udbidentdata_orig UDBIdentData
    WHERE
    UDBMovement.lGlobalId = UDBIdentData.lGlobalRef(+) AND UDBMovement.sComputer = UDBIdentData.sComputer(+)
    AND UDBMovement.sTransType > 0 AND UDBMovement.sDevice < 1000 AND UDBMovement.sDevice>= 0 AND UDBIdentData.sCardType IN (1) AND (bitand(UDBMovement.sSaleFlag,1) = 0 AND bitand(UDBMovement.sSaleFlag,4) = 0) AND UDBMovement.sArtClassRef < 100
    AND UDBMovement.tActionTime >= TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.25
    AND UDBMovement.tActionTime < TO_DATE('05/05/2011 00:00:00', 'dd/mm/yyyy hh24:mi:ss') + 0.5
    ORDER BY tActionTime, lBlock, lSequenz
    call count cpu elapsed disk query current rows
    Parse 1 0.03 0.06 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 596 0.76 16.94 3278 85529 0 8925
    total 598 0.79 17.01 3278 85529 0 8925
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 60
    Rows Row Source Operation
    8925 SORT ORDER BY (cr=85529 pr=3278 pw=0 time=16942799 us)
    8925 NESTED LOOPS (cr=85529 pr=3278 pw=0 time=15017857 us)
    22567 TABLE ACCESS BY INDEX ROWID UDBMOVEMENT_ORIG (cr=17826 pr=1659 pw=0 time=7273473 us)
    22570 INDEX RANGE SCAN IDX_UDBMOVARTICLE (cr=111 pr=111 pw=0 time=112351 us)(object id 143693)
    8925 TABLE ACCESS BY INDEX ROWID UDBIDENTDATA_ORIG (cr=67703 pr=1619 pw=0 time=8154915 us)
    22567 INDEX UNIQUE SCAN UDBIDENTDATA_PRIM (cr=45136 pr=841 pw=0 time=3731470 us)(object id 108324)

  • Can a SQL WITH Clause be used in Materialized View

    Hello,
    Can we use SQL WITH clause in Materialized View.
    Thanks

    Hello,
    Here is an example
    CREATE MATERIALIZED VIEW MV_TEST
    BUILD IMMEDIATE
    REFRESH FORCE ON DEMAND
    AS
    WITH t AS (SELECT owner, object_type, COUNT ( * )
               FROM my_objects
               GROUP BY object_type, owner)
    SELECT *
    FROM t
    WHERE owner IN ('SYS', 'SYSTEM');Regards

  • Performance tuning in SQL query using join of views

    Hi,
    Am trying to tune a query of the format
    select ........ from view1,view2
    where view1.keyfield = view2.keyfield
    The base tables of the views view1 and view2 have indexes specified on 'keyfield'.
    However, when I do an explain plan of the query, Full table scan of those base tables are performed.
    Even tried using Hints in this query to force Oracle to use those indexes, but still not successful.
    Any pointers on how to tune this kind of query would be highly welcome.
    Regards,
    Baish

    If your query is really of the same form as you posted, then full table scans then a hash or merge join may be the most efficient plan.
    You are asking for all of the rows from view1 and the matching rows from view2, because of this, Oracle dedcided that the cost of full table scans using multi-block reads is cheaper than using single block reads to get the rowids from the index, then single block reads to get the rows from the table.
    FULL SCAN <> BAD
    John

  • Materialized view not being used in the report

    I have had a materialized view (MV) for a particular report. Recently, the report definition has changed little bit, so the existing MV is not being used by the report anymore. I copied the code Discoverer's SQL Inspection and recreated the materialized view. But still it is not working. Obviously, I am missing something at the database level. Does anyone have any idea? The database is 9i and Discoverer is 9.0.2. Thank you!

    The SQL that you see from the Inspect SQL option will provide you with the SQL that Discoverer sends to the database. The database then may do a query rewrite to point to an available materialized view if available. This rewrite won't be seen from the inspect sql option. You need to check at the database level to verify if a query rewrite did in fact take place.
    You may want to check the section titled "Query Rewrite with Materialized Views" from Ch1 - "Introduction to the Optimizer" in the Oracle9i Database Performance Tuning Guide and Reference, Release 2 (9.2), Part Number A96533-02, available at http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#37287
    Regards
    Abhinav Agarwal
    Oracle Business Intelligence Product Management
    http://www.oracle.com/bi
    http://www.oracle.com/technology/documentation/bi_ee.html
    http://www.oracle.com/technology/software/products/ias/htdocs/101320bi.html
    http://oraclebi.blogspot.com/

  • Spatial vs. materialized views/query rewrite

    Dear all,
    we are trying to use Spatial (Locator) functionality together with performance optimization using materialized views and query rewrite, and it does not seem to work. Does anybody has experience with this?
    The problem in more detail:
    * There is a spatial attribut (vom Typ GEOMETRY) in our table;
    * we define a materialized view on that table;
    * we run a query that could be better answered using the materialized view with query rewrite;
    *the optimizer does not choose the plan using the materialized view, query rewrite does not take place;
    This happenes, even if neither the materialized view, nor the query contains the spatial attribut.
    The explanation given by the procedure DBMS_MVIEW.Explain_Rewrite is:
    "QSM-01064 query has a fixed table or view Cause: Query
    rewrite is not allowed if query references any fixed tables or views"
    We are using Oracle 9R2, Enterprise Edition, with locator. Nevertheless, it would also be interesting, if there is any improvement in 10g?
    A more complicated task, using materialized views to optimize spatial operations (e.g., sdo_relate) would also be very interesting, as spatial joins are very expensive operations.
    Thanks in advance for any comments, ideas!
    Cheers,
    Gergely Lukacs

    Hi Dan,
    thanks for your rapid response!
    A simple example is:
    alter session set query_rewrite_integrity=trusted;
    alter session set query_rewrite_enabled=true;
    set serveroutput on;
    /* Creating testtable */
    CREATE TABLE TESTTABLE (
    KEY1 NUMBER (4) NOT NULL,
    KEY2 NUMBER (8) NOT NULL,
    KEY3 NUMBER (14) NOT NULL,
    NAME VARCHAR2 (255),
    X NUMBER (9,2),
    Y NUMBER (9,2),
    ATTR1 VARCHAR2 (2),
    ATTR2 VARCHAR2 (30),
    ATTR3 VARCHAR2 (80),
    ATTR4 NUMBER (7),
    ATTR5 NUMBER (4),
    ATTR6 NUMBER (5),
    ATTR7 VARCHAR2 (40),
    ATTR8 VARCHAR2 (40),
    CONSTRAINT TESTTABLE_PK
    PRIMARY KEY ( KEY1, KEY2, KEY3 ));
    /* Creating materialized view */
    CREATE MATERIALIZED VIEW TESTTABLE_MV
    REFRESH COMPLETE
    ENABLE QUERY REWRITE
    AS SELECT DISTINCT ATTR7, ATTR8
    FROM TESTTABLE;
    /* Creating statistics, just to make sure */
    execute dbms_stats.gather_table_stats(ownname=> 'TESTSCHEMA', tabname=> 'TESTTABLE', cascade=>TRUE);
    execute dbms_stats.gather_table_stats(ownname=> 'TESTSCHEMA', tabname=> 'TESTTABLE_MV', cascade=>TRUE);
    /* Explain rewrite procedure */
    DECLARE
    Rewrite_Array SYS.RewriteArrayType := SYS.RewriteArrayType();
    querytxt VARCHAR2(1500) :=
    'SELECT COUNT(*) FROM (
    SELECT DISTINCT
    ATTR8 FROM
    TESTTABLE
    i NUMBER;
    BEGIN
    DBMS_MVIEW.Explain_Rewrite(querytxt, 'TESTTABLE_MV', Rewrite_Array);
    FOR i IN 1..Rewrite_Array.count
    LOOP
    DBMS_OUTPUT.PUT_LINE(Rewrite_Array(i).message);
    END LOOP;
    END;
    The message you get is:
    QSM-01009 materialized view, string, matched query text
    Cause: The query was rewritten using a materialized view, because query text matched the materialized view text.
    Action: No action required.
    i.e. query rewrite works!
    /* Adding geometry column to the testtable -- not to the materialized view, and not to the query! */
    ALTER TABLE TESTTABLE
    ADD GEOMETRYATTR mdsys.sdo_geometry;
    /* Explain rewrite procedure */
    DECLARE
    Rewrite_Array SYS.RewriteArrayType := SYS.RewriteArrayType();
    querytxt VARCHAR2(1500) :=
    'SELECT COUNT(*) FROM (
    SELECT DISTINCT
    ATTR8 FROM
    TESTTABLE
    i NUMBER;
    BEGIN
    DBMS_MVIEW.Explain_Rewrite(querytxt, 'TESTTABLE_MV', Rewrite_Array);
    FOR i IN 1..Rewrite_Array.count
    LOOP
    DBMS_OUTPUT.PUT_LINE(Rewrite_Array(i).message);
    END LOOP;
    END;
    The messages you get are:
    QSM-01064 query has a fixed table or view
    Cause: Query rewrite is not allowed if query references any fixed tables or views.
    Action: No action required.
    QSM-01019 no suitable materialized view found to rewrite this query
    Cause: There doesn't exist any materialized view that can be used to rewrite this query.
    Action: Consider creating a new materialized view.
    i.e. query rewrite does not work!
    If this works, the next issue is to use materialized views for optimizing spatial operations, e.g., a spatial join. I can supply you with an example, if necessary (only makes sense, I think, after the first problem is solved).
    Thanks in advance for any ideas, comments!
    Cheers,
    Gergely

  • Oracle - Query taking too long (Materialized view)

    Hi,
    I am extracting billing informaiton and storing in 3 different tables... in order to show total billing (80 to 90 columns, 1 million rows per month), I've used a materialized view... I do not have indexes on 3 billing tables - do have 3 indexes on Materialized view...
    at the moment it's taking too long to query the data (running a query via toad fails and shows "Out of Memory" error message; runing a query via APEX though is providing results but taking way too long)...
    Please advice how to make the query efficient...

    tparvaiz,
    Is it possible when building your materialized view to summarize and consolidate the data?
    Out of a million rows, what would your typical user do with that amount data if they could retrieve it readily? The answer to this question may indicate if and how to summarize the data within the materialized view.
    Jeff
    Edited by: jwellsnh on Mar 25, 2010 7:02 AM

  • Materialized View Logs Query

    Hi All,
    I had some problem with my Materialized views, that's why Dropped all of the Logs + Materialized Views from my Production Database. Kindly tell me that, Is there any Query, which I can run and make Materialized View Logs from my Existing Tables . Thanks
    Regards,
    Imran

    Incremental Materialized View creation steps
    Hi,
    Find the below steps to create MV's with logs.
    1.     Materialized view log creation at master.
    2.     DB link creation at MV site to master site.
    3.     Materialized view creation at MV site.
    4.     Refresh the MV.
    Materialized view log creation at master.
    SQLPLUS <USER_MASTER_SITE>/<PASSWORD>@<MASTER_SITE>
    CREATE MATERIALIZED VIEW LOG ON <TABLE_NAME>;
    DB link creation at MV site.
    SQLPLUS <USER_MV_SITE>/<PASSWORD>@<MV_SITE>
    CREATE Database Link <MASTER_SITE> Connect To <USER_MASTER_SITE> Identified By <PASSWORD> Using ‘<tnsnames>’
    Materialized view creation at MV site.
    SQLPLUS <USER_MV_SITE>/<PASSWORD>@<MV_SITE>
    CREATE MATERIALIZED VIEW <TABLE_NAME> BUILD
    IMMEDIATE REFRESH FAST ON DEMAND
    ENABLE QUERY REWRITE
    AS SELECT * FROM <TABLE_NAME>@<MASTER_SITE> REFRESH ;
    Refresh the MV.
    SQLPLUS <USER_MV_SITE>/<PASSWORD>@<MV_SITE>
    Execute DBMS_SNAPSHOT.REFRESH( '<TABLE_NAME>','f');
    Regards,
    Prasanna

  • Materialized view query (Oracle 9i)

    I have dropped a materialized view query and trying to create the same with additional columns in the prebuilt table.
    Option - 1
    when Iam using a query in the materialized view query "select * from schema.table@link, with refresh mode fast option, the database throws an error " no table or view exists"
    Option - 2
    When Iam using a query in the materialized view query "select * from schema.table@link, with refresh mode option either complete or force, it gets created.
    I need to create the above materialized view query in the fast mode option, Please help.
    -bala

    Hi,
    Does a table named profit_mvw already exist?
    The following example illustrates the two steps required to register a user-defined table. First, the table is created, then the materialized view is defined using exactly the same name as the table. This materialized view sum_sales_tab is eligible for use in query rewrite.
    CREATE TABLE sum_sales_tab
    PCTFREE 0 TABLESPACE demo
    STORAGE (INITIAL 16k NEXT 16k PCTINCREASE 0) AS
    SELECT s.prod_id, SUM(amount_sold) AS dollar_sales,
    SUM(quantity_sold) AS unit_sales
    FROM sales s GROUP BY s.prod_id;
    CREATE MATERIALIZED VIEW sum_sales_tab
    ON PREBUILT TABLE WITHOUT REDUCED PRECISION
    ENABLE QUERY REWRITE AS
    SELECT s.prod_id, SUM(amount_sold) AS dollar_sales,
    SUM(quantity_sold) AS unit_sales
    FROM sales s GROUP BY s.prod_id;
    Regards,
    Simon

  • Map Viewer Query Rewriting for Dynamic themes and  Materialized Views.

    Hi,
    I am usng a WMS request to render FOI points in my map.
    Internally query rewrite is happening in Mapviewer for this dynamic theme and my data points query is getting converted as
    select FROM
    ( select status, shape from MatView.MyTab where id = '3' )
    WHERE MDSYS.SDO_FILTER(shape, MDSYS.SDO_GEOMETRY(2003, 4283, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 3), MDSYS.SDO_ORDINATE_ARRAY(144.948120117188,-37.8162934802451,144.950866699219,-37.8141237016045)), 'querytype=WINDOW') = 'TRUE'
    here the rewritten query is not correct and is throwing exceptions in mapviewer log
    How can I make this query to be written correctly.
    (My orginal query before rewrite is: select status,shape from MatView.MyTab where id='3' )
    I am using a materialised view : MatView is a materialized view.
    When I used normal tables, the query is re written correctly.But for this materialized view this is happening.
    How can I correct the error?
    Is this has something to do with some Spatial Indexing in Materialised view or Query Rewriting for materialized view?
    Edited by: 841309 on Mar 10, 2011 11:04 PM

    Oops!
    The Materialized view was not accessible from the schema I tried :)
    And so when I gave permissions,it formed the correct query.
    So if permission is not there,map viewer will rewrite the query in a wrong way! New information.

Maybe you are looking for