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
Similar Messages
-
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
-
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. -
Can a SQL WITH Clause be used in Materialized View
Hello,
Can we use SQL WITH clause in Materialized View.
ThanksHello,
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 -
Update Database using Materialized Views
I have a need to update the database across the firewall (on a partner network). Are there any issues/problems with this approach like performance, security,etc. I do not want to use dblinks.
Materialized views generally don't work too well without a database link between the machines-- in fact, they don't work at all. Oracle replication is built around the assumption that the databases involved can communicate with each other.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Creating a Materialized View Log After the Data has been instered
Hi,
I am trying to create a method of replication from Oracle to MySQL using the Materialized View Log table.
This has been done before and works quite well, the only problem is that I am trying to impliment the log after the table has been created and populated and wish to push all the existing data through the log file...
Does anyone know if it is possible to refresh the Materialized View Log and not a Materialized View.
The way the replication is intended to work is:
Oracle> Data inserted into table
Oracle> writes the vector data to the MVL
Script> Monitors the MVL and can see the changes being made to the Oracle Table
Script> Updates MySQL with the data and removes the rows from the MVL
MySQL is then used with other unix systems
Currently we export the data from the table using Triggers and a cronjob running every x minute to check for changes in the TriggerTables
Many thanks for your time on this, I have been checking for almost a whole working day and not found the answer to this problem.Thats what I thought, the MVL will only read data that has changed since it was created and wont have the option to load in all the data as though it was made before the table was created.
From what I have read, the MVL is quicker than a Trigger and I have some free code that prooved to work from a MVL using it as a reference to know what records to update. There is not that much to a MVL, a record ID and type of update, New, Update or Delete.
I think what I will have to do is work on a the same principle for the MVL but use a Trigger as this way we can do a full reload if required at any point.
Many thanks for your help. -
Fast refresh on MATERIALIZED VIEW
Oracle 10 g R2 (10.2.0.5)
CREATE MATERIALIZED VIEW scott.mv_test
TABLESPACE users
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
AS
Select ....
I have this MV, when I do the FAST refersh as follows , I am getting error
SQL> execute DBMS_MVIEW.REFRESH( 'MV_TEST','f');
BEGIN DBMS_MVIEW.REFRESH( 'MV_TEST','f'); END;
ERROR at line 1:
ORA-12004: REFRESH FAST cannot be used for materialized view "SCOTT"."MV_TEST"
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2251
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2457
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2426
ORA-06512: at line 1
But it's working with Complete refresh.
Is that expecte, any help would be appreciated.
Thanks,ORA-12004: REFRESH FAST cannot be used for materialized view "string"."string"
Cause: The materialized view log does not exist or cannot be used. PCT refresh is also not enabled on the materialized view
Action: Use just REFRESH, which will reinstantiate the entire table. If a materialized view log exists and the form of the materialized view allows the use of a materialized view log or PCT refresh is possible after a given set of changes, REFRESH FAST will be available starting the next time the materialized view is refreshed.http://ora-12004.ora-code.com/ -
How to create materialized view based on a view?
Hi,
I hope this is not very far fetched idea.
I have a very complex view and I would like to replicate it 'in place' that is I would like to make a materialized view that is based on this view complex view. I would like to use this materialized view (i.e table) to query data instead of using the original view, since it takes Oracle some 10-15 seconds to execute my query on the original view and I am not allowed to create indexes on most of the tables that are included in the original view.
Can this be done?
Best regards,
Tamas SzecsyThe best way to do this is to create a materialzed view based on the underlying code of the original view. If you don't have this handy, issue the following in sqlplus:
select text
from user_views
where view_name = 'NAME_OF_VIEW'
You can then cut and paste the sql statement into your create materialized view statement.
Please note, you will probable have to set the long parameter to a higher value to reveal the complete statement for example:
SQL> set long 2048 -
How to CREATE MATERIALIZED VIEW LOG (MV fast refresh) with some JOINS
Hi @ all,
i'm trying to create a MATERIALIZED VIEW LOG for a fast refresh of a MATERIALIZED VIEW.
It works fine with a simple Request in the MATERIALIZED VIEW:
CREATE MATERIALIZED VIEW MV_ZOTD43_P
TABLESPACE GDII
BUILD IMMEDIATE
REFRESH FORCE AS
SELECT * FROM ZOTD43_P;
COMMIT;
CREATE MATERIALIZED VIEW LOG ON ZOTD43_P
TABLESPACE "GDII"
WITH PRIMARY KEY, ROWID, SEQUENCE INCLUDING NEW VALUES;
call DBMS_MVIEW.REFRESH('MV_ZOTD43_P', 'f');
But when I use a complex SQL-Request with some JOINS (one of the Table with spatial Data) in the MATERIALIZED VIEW, I get an error:
CREATE MATERIALIZED VIEW MV_TEST
TABLESPACE GDII
BUILD IMMEDIATE
REFRESH FORCE AS
SELECT lptd04_p.sst_nr AS sst_nr,
lptd03_p.aaaa AS aaaa,
lptd04_geom.geom as geom
FROM lptd04_p lptd04_p
JOIN lptd01_p lptd01_p ON lptd01_p.cre_nr = lptd04_p.sst_nr
JOIN lptd04_geom ON lptd04_geom.sst_nr = lptd04_p.sst_nr
JOIN lptd03_p lptd03_p ON lptd03_p.lief_nr = lptd04_p.lief_nr;
COMMIT;
CREATE MATERIALIZED VIEW LOG ON LPTD04_P
TABLESPACE "GDII"
WITH PRIMARY KEY, ROWID, SEQUENCE INCLUDING NEW VALUES;
call DBMS_MVIEW.REFRESH('MV_TEST', 'f');
Error report:
SQL Error: ORA-12004: REFRESH FAST kann für Materialized View "GDI"."MV_GDI_SST_STAMM" nicht benutzt werden
ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2255
ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2461
ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2430
ORA-06512: in Zeile 1
12004. 00000 - "REFRESH FAST cannot be used for materialized view \"%s\".\"%s\""
*Cause: The materialized view log does not exist or cannot be used. PCT
refresh is also not enabled on the materialized view
*Action: Use just REFRESH, which will reinstantiate the entire table.
If a materialized view log exists and the form of the materialized
view allows the use of a materialized view log or PCT refresh is
possible after a given set of changes, REFRESH FAST will
be available starting the next time the materialized view is
refreshed.
Am I doing something wrong or is it not possible CREATE MATERIALIZED VIEW LOG when the MATERIALIZED VIEW got some JOINS?
Regards,
GreqThanks for the link Alessandro ,
the error seems something to do with the Column-Type SDO_GEOMETRY, so
i create a new thread in the Spatial Discussion forum:
FAST REFRESHing of Oracle Materialized Views containing SDO_GEOMETRY column
Regards,
Greq -
How to Refresh materialized view
Hi,
I am using 11G owb. I would like to know if any one can help me know if there is any easy to Refresh materialized view . I will be using this materialized view to source data from my maps. this map will be part of a process flow. i would like to refresh the materialized view before every run of the map in process flow.
Thanks,
Ash.
Edited by: user591315 on Aug 6, 2009 1:26 PMA couple of approaches;
* refresh the MV from a procedure in a pre map process operator (its an operator in a mapping), or
* call the procedure from a process flow activity before the map
Cheers
David -
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 LukacsHi 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 -
Materialized view with date range
hey,
i have a Statistics Query with start date and end date and its Table table_a would be refreshed every hour....:
e.g.
select ...
from table_a a, table_b b ....
where table_a.transactiondate between start_date and end_date and ....;
So I am wondering how to create a effective materialized view? This is a big query with mutilple tables and each table has many rows.
I have tried to use:
create materialized view view_a
refresh fast
start with sysdate next sysdate + 1/24
as
select a.start_date, a.end_date, ....
from table_a a, table_b b ....
where ....;
Thanks.If you want to use FAST REFRESH, you must create a MV Log. It would be something like this:
create materialized view log on TABLE
with primary key including new values
create materialized view mv_TABLE
refresh fast
start with sysdate next sysdate + 1/24
as select * from TABLE
For more info about MV:
http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_6002.htm
Hope I've helped!
Regards,
Marcos -
Materialized view with dynamic filter
I have a query which has a dynamic filter in the where clause. Dynamic in the sense, the value in the where condition will be obtained only when the query is run.
The user interface is Business Objects tool i am using, based on the user login variable, the query is formed. Is there a possibilty to create a materialized view using this query.
The query looks like this. The part in BOLD section is the filter. This query is taking long time and hence i am going for materialized view. Please suggest a solution
SELECT
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC,
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.NET_SALES_USD else 0 end),
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.NET_SALES_USD else 0 end),
SUM(case when
PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.NET_SALES_USD else 0 end),
SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1
AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
then SALES_FACT.NET_SALES_USD else 0 end),
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR )and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
SUM(case when
PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.MUNITS_SOLD_QTY
else 0 end),
SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then
SALES_FACT.CASES_SOLD_QTY else 0 end),
SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR )and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.CASES_SOLD_QTY else 0 end),
SUM(case when
PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.CASES_SOLD_QTY
else 0 end),
SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
then SALES_FACT.CASES_SOLD_QTY else 0 end),
DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR,
DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_MONTH_NAME,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_6_DESC,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_7_DESC,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_8_DESC,
CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SOLD_TO_CUST_NAME),
CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SHIP_TO_CUST_LOC_NAME)
FROM
DM_SALES.SALES_ORG_DIM,
PERIOD_DIM,
SALES_FACT,
DM_SALES.CURRENT_DATE_PERIOD_DIM,
SHIP_TO_CUST_DIM
WHERE
( SALES_FACT.INVOICE_DATE_KEY(+)=PERIOD_DIM.PERIOD_KEY )
AND ( SHIP_TO_CUST_DIM.SHIP_TO_CUST_KEY=SALES_FACT.SHIP_TO_CUST_KEY )
AND ( SALES_FACT.SALES_ORG_KEY=DM_SALES.SALES_ORG_DIM.SALES_ORG_KEY )
AND ( PERIOD_DIM.PERIOD_KEY<=DM_SALES.CURRENT_DATE_PERIOD_DIM.PERIOD_KEY )
AND
( DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC=(SELECT DM_SALES.SECURITY_HEADER.SALES_ORG_POSITION_DESC from DM_SALES.SECURITY_HEADER
WHERE DM_SALES.SECURITY_HEADER.BOLOGIN = @VARIABLE('BOUSER')) ) AND
( PERIOD_DIM.FISCAL_YEAR>=DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR-1 )
GROUP BY
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC,
DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR,
DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_MONTH_NAME,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_6_DESC,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_7_DESC,
DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_8_DESC,
CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SOLD_TO_CUST_NAME),
CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SHIP_TO_CUST_LOC_NAME)You could potentially create a single materialized view that had no restriction on the BOLOGIN column and allow Oracle to use that materialized view to be used to satisfy requests from the different users. You may need to add appropriate indexes to the materialized view for that to be a reasonable option, depending on how many distinct BOLOGIN values you expect.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
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 PMBingo!
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! -
Materialized Views appear twice - under MV and under tables
Hi,
I've encountered a wierd issue.
It seems that every materialized view is also appearing under the tables tab.
For example sh.cal_month_sales_mv. Another example, run this as sh:
CREATE MATERIALIZED VIEW SH.OFIR_MV
REFRESH FORCE ON DEMAND
ENABLE QUERY REWRITE
AS SELECT sum(s.amount_sold) AS dollars
FROM sales s;
You'll see a table OFIR_MV under the table tab. If you try to drop it(right-click-> table-> drop), you get ora-12083 must use DROP MATERIALIZED VIEW to drop "SH"."OFIR_MV"
Also, SQL tab of the "table" has the folowing remark
-- DBMS_METADATA was unable to use TABLE_EXPORT to generate sql. Now trying to use TABLE
I guess this is the source of the issue:
select object_name,object_type from user_objects where object_name = 'OFIR_MV';
OBJECT_NAME OBJECT_TYPE
OFIR_MV TABLE
OFIR_MV MATERIALIZED VIEW
2 rows selected
So, creating a MV also adds a table to user_objects/tables. (Huh? that suprised me)
Could SQL Dev filter these fake tables or at least have a different icon/color for them?
Thanks.
Ofir
BTW - Win XP, 10.2.0.3EE, SQL Dev 1.1.1.25.14e.g Re: Materialized Views, indexes and Raptor Eeerrr... no.
That user wanted to be able to access indexes, etc., which he thought could be easily accomplished by adding the MV to the tables node.
To what the response was: the options on the MV will be improved (which it has), NOT bringing it in the tables node. As Ofir also pointed out, there's a reason for it not belonging there: the operations performed on the objects of the table node expect tables, not MVs.
So, between fixing the tables node for accepting MVs and it's operations, and just removing the MVs from the node, I'd go for the second, faster, more correct solution.
K.
Maybe you are looking for
-
Failed to load resource: the server responded with a status of 404 (Not Found)
I uploaded 2 x small Wordpress sites to Azure this morning using the local Git repository on my iMac. They worked fine when I checked them earlier and now I see the websites are not loading correctly with 30+ errors on each effecting all .css, .js an
-
Audio and video out of synchronization in iTune for Windows 8.1
When playing back a downloaded iTunes file, the audio and video are out of synchronization a lot of the time. The audio can be several seconds behind the video. How can this be corrected/fixed? I am running the latest iTunes software on a 3.8Ghz AMD
-
Hi all, I have a 2 structures used in the query. Also have some input parameters to bring the query result. Suppose if data is not there in the cube as per the input parameters then query wll not bring any result. but if i want those structures to be
-
Why can't I open my vi's anymore.
When I try an open a particlur set of vi's I can't. Other vi's I have open fine, but there are a few that can't and here is the error message that I get. Windows cannot find 'c:\ALO v1.1\ALO lidar\ALO LIDAR.vi'. Make sure you typed the name correctly
-
We have a security requirement on a dimension containing cost centers. Different users are allowed access to different cost centers. On the relational cube side, I have implementated such security requirement with some success using Virtual Private D