11g OLAP cube MV's with Query Rewrite option
Hi All,
I am trying to test the 11g OLAP cube MV's with the Query Rewrite option.
I had created a cube on the schema OLAPTRAIN problem by oracle. I an selected necessary options in 'Materialized Views' tab of the Cube definition in AWM. here is the screenshot
!http://i40.tinypic.com/9jzpte.png!
and then I try to run the SQL query
select SUM(S.QUANTITY) AS QUAN,
SUM(S.SALES) AS SALES,
T.CALENDAR_YEAR_NAME,
P.DEPARTMENT_NAME,
C.COUNTRY_NAME
FROM
TIMES T,CUSTOMERS C,PRODUCTS P, SALES_FACT S
WHERE
C.CUSTOMER_KEY = S.CUSTOMER AND
T.DAY_KEY = S.DAY_KEY AND
P.ITEM_KEY = S.PRODUCT
group by T.CALENDAR_YEAR_NAME, P.DEPARTMENT_NAME, C.COUNTRY_NAME;
and observed the Explain plan, it is not using OLAP cube built, instead it is using the relational tables given in the above sql query.
Also, i have observed that , though enabling or disabling of the Query Rewrite option doesn't make any change in the Explain query for the above query.
alter materialized view olaptrain.cb$sales_cube enable query rewrite;
alter materialized view OLAPTRAIN.cb$sales_cube disable query rewrite;
No idea why is this Query Rewrite feature is not working on my Database instance of 11g R2 . Do am I missing any steps that has be taken care of , to make this working. Any inputs would be appreciated.
Thanks
S
Hi there,
You should check out Note 577293.1 on Metalink - 'Oracle OLAP 11g: How to ensure use of Cube Materialized Views/Query Rewrite'
Thanks,
Stuart Bunby
OLAP Blog: http://oracleOLAP.blogspot.com
OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
OLAP on OTN: http://www.oracle.com/technology/products/bi/olap/index.html
DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html
Similar Messages
-
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...thanksJes, 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 -
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 - query rewrite -- optional joins & dimensions
Hi,
I've implemented a number of materialized views that are accessible via query rewrite.
Most of these views make use of duplicate tables (DD_TIME table is joined via purchase, load, process, ... date columns)
I've also created a dimension to make Oracle aware of the time relation (month is child of year...)
The issue:
--> If I create the mat. view with inner joins, query rewrite works with the dimensions, but I need to provide ALL joined tables in the query
--> If I create the mat. view with outer joins, query rewrite works even with 1 joined table, but the dimension seems to be ignored
How can I create 'optional' joins in the Mat. View while making use of dimensions for rollup?
(the limitations on materialized view delta joins mentioned on [oracle docs|http://docs.oracle.com/cd/B28359_01/server.111/b28313/qradv.htm#autoId16] kinda has me worried)
Example Mat. View:
CREATE MATERIALIZED VIEW DA_REPOSITORY_MERCHANT_MM
... ENABLE QUERY REWRITE
AS SELECT
DDFPC.YEAR_NO,
DDFPC.YEAR_MONTH,
DDPUR.YEAR_NO,
DDPUR.YEAR_MONTH,
SUM( DF.TRANSACTION_AMOUNT )
FROM DF_REP DF,
DD_TIME DDFPC,
DD_TIME DDPUR
WHERE DF.FPC_DTE = DDFPC.DAY_DATE(+)
AND DF.PUR_DTE = DDPUR.DAY_DATE(+)
GROUP BY
DDFPC.YEAR_NO,
DDFPC.YEAR_MONTH,
DDPUR.YEAR_NO,
DDPUR.YEAR_MONTH
Example query launched:
SELECT
DDFPC.YEAR_NO,
SUM( DF.TRANSACTION_AMOUNT )
FROM DF_REP DF,
DD_TIME DDFPC
WHERE DF.FPC_DTE = DDFPC.DAY_DATE
GROUP BY
DDFPC.YEAR_NOThe problem was resolved by setting foreign keys in the fact table and making them not nullable + using inner joins.
--> this informs oracle there can be no difference between a query without the dimensions and a query with the dimensions.
As a result, the materialized view can contain 1 fact linked to 2 dimension tables, but the query rewrite will work for queries on the 1 fact joined with only 1 dimension -
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. -
Is Query Rewrite being used?
How do I check if query rewrite is being used?
This is an 8174 database. When I run explain plan on the query used to create the MV, the plan shows all the tables/indexes to be used. It doesn't show the MV name in the explain plan.
Is this the correct way of verifying if query rewrite is being used?Yes it is correct to see execution plan to check if query rewrite is used.
But keep in mind, than you must enable query_rewrite at least on session level and MV must be created with query rewrite option too.
ALTER SESSION SET QUERY_REWRITE_ENABLED = TRUE;
CREATE MATERIALIZED VIEW sales_by_month_by_state
TABLESPACE example
PARALLEL 4
BUILD IMMEDIATE
REFRESH COMPLETE
ENABLE QUERY REWRITE
AS SELECT t.calendar_month_desc, c.cust_state_province,
SUM(s.amount_sold) AS sum_sales
FROM times t, sales s, customers c
WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id
GROUP BY t.calendar_month_desc, c.cust_state_province;
See doc for more details -
Error while enabling query rewrite on cube
Hi
Trying to enable query rewrite option for OLAP cube throws below error message :
Your metadata changes have been saved, with the following errors
Invalid Metadata Objects:
Invalid Object "FUSION.FLINE_STATUS_CUBE2": "CREATE MATERIALIZED VIEW "FUSION"."CB$FLINE_STATUS_CUBE2"
ORGANIZATION CUBE ON FUSION.DOO_STATUS (
FACT "FLINE_STATUS_CUBE2_STORED"("FLINE_STATUS_CUBE2_MEASURE_DIM" 'SYS_COUNT') IS "SYS_COUNT",
FACT "FLINE_STATUS_CUBE2_STORED"("FLINE_STATUS_CUBE2_MEASURE_DIM" 'TOTAL_QUANTITY') IS "TOTAL_QUANTITY",
FACT "FLINE_STATUS_CUBE2_STORED"("FLINE_STATUS_CUBE2_MEASURE_DIM" 'TOTAL_PRICE') IS "TOTAL_PRICE",
DIMENSION "WAREHOUSE1" IS "WAREHOUSE1" .............................................
ORA-30353: expression not supported for query rewrite
There are no issues with loading/viewing data from cube.
Any pointers on what could be going wrong herel.
Thanks
RaviKishoreIn the context of an OLAP cube the offending expression will be part of the cube's mapping. As already pointed out, there are a number of functions that aren't compatible. Here is the oracle documentation for the error.
ORA-30353 expression not supported for query rewrite
Cause: The SELECT clause referenced UID, USER, ROWNUM, SYSDATE, CURRENT_TIMESTAMP, MAXVALUE, a sequence number, a bind variable, correlation variable, a set result, a trigger return variable, a parallel table queue column, collection iterator, a non-deterministic date format token RR, etc.
Action: Remove the offending expression or disable the REWRITE option on the materialized view.
The most common cause in my experience is handling dates with either TO_DATE or TO_CHAR functions. If these functions do not have an explicit date format, then you will hit this error. -
Query rewrite does not always work?
Hi -
I created several cubes at this point.
Cube #1: simple time and volume. Query re-write works great.
Cube #2: simple customer (geography) hierarchy and volume. Query re-write works great.
Cube #3: Added product dimension along with time and customer. I also added ytd volume and same period prior period volume calculations.
The Cube#3 is not peforming a query re-write.
All cubes have MV and Query rewrite enabled.
I am using lastest verisons of 11G and AWM.
Any ideas how to debug why query rewrite is not working?
Thanks,
Frank.Hi Frank,
See the information at the following link:- https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=577293.1
This is titled 'Oracle OLAP 11g: How to ensure use of Cube Materialized Views/Query Rewrite'
I hope it helps
Thanks,
Stuart Bunby
OLAP Blog: http://oracleOLAP.blogspot.com
OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
OLAP on OTN: http://www.oracle.com/technology/products/bi/olap/index.html
DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html -
Reg:Webi 3.1 reporting on OLAP cube
Hallo.
I've created 2 universe in WebI 3.1 on BW OLAP cube end on Bex Query .
@funkctions, aggregate Navigation is not availible nowhere . Mergin Demension is not availible too .
Is that normal in WebI 3.1 on BW OLAP cube end on Bex Query ?
Thank you .HI Vladimir,
When you create universe on a Bex query or an OLAP cube you will have very limited options or features available in the universe designer.The @functions , aggregate navigation and merge dimensions features will not be available and you will be more dependent on the BW side as you are not free to use the functions and features which are otherwise available with oracle or sql backend.
Regards,
Neeraj -
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 -
i have a problem with query rewrite in 10gR1.
create table time_hierarchy (
day date primary key,
mmyyyy char(6) not null,
qyyyy char(5) not null,
yyyy char(4) not null
) organization index;
create table tx (
shopid number not null,
txdate date references time_hierarchy initially deferred
not null,
amount number not null
create dimension tx_dimension
level day is time_hierarchy.day
level mmyyyy is time_hierarchy.mmyyyy
level qyyyy is time_hierarchy.qyyyy
level yyyy is time_hierarchy.yyyy
hierarchy time_rollup (
day child of
mmyyyy child of
qyyyy child of
yyyy
create materialized view tx_mv
build immediate
refresh on demand
enable query rewrite
as
select a.shopid shopid,
count(*) txnum,
sum(a.amount) amountsum,
b.mmyyyy mmyyyy
from tx a join time_hierarchy b on a.txdate = b.day
group by a.shopid, b.mmyyyy;
i populated the tables and did a complete analyze.
this query was rewritten:
select /*+ REWRITE */ a.shopid shopid,
b.mmyyyy mmyyyy,
count(*) txnum,
sum(a.amount) amountsum
from tx a join time_hierarchy b on a.txdate = b.day
group by a.shopid, b.mmyyyy
order by a.shopid, b.mmyyyy;
but this not:
select /*+ REWRITE */ a.shopid shopid,
b.qyyyy qyyyy,
count(*) txnum,
sum(a.amount) amountsum
from tx a join time_hierarchy b on a.txdate = b.day
group by a.shopid, b.qyyyy
order by a.shopid, b.qyyyy;
an explain_mview gave me this;
MESSAGE
QSM-01082: Joining materialized view, TX_MV, with table, TIME_HIERARCHY, not pos
sible
QSM-01102: materialized view, TX_MV, requires join back to table, TX, on column,
AMOUNT
QSM-01102: materialized view, TX_MV, requires join back to table, TX, on column,
TXDATE
QSM-01102: materialized view, TX_MV, requires join back to table, TIME_HIERARCHY
, on column, YYYY
MESSAGE
QSM-01102: materialized view, TX_MV, requires join back to table, TIME_HIERARCHY
, on column, QYYYY
QSM-01102: materialized view, TX_MV, requires join back to table, TIME_HIERARCHY
, on column, DAY
QSM-01086: dimension(s) not present or not used in ENFORCED integrity mode
QSM-01063: query has a dictionary table or view
if i set integrity to trusted, the latter query will be rewritten too.
can anyone explain me why? i'm clueless.
Best,
-apyes, see definition of tx, relation tx.txdate->time_hierarchy.day
what puzzles me is the fact, that mmyyyy works but not qyyyy.
both are levels of day.
-j -
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,
JohnHi,
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 -
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,
PriteshWhat version of the Oracle database?
-
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 advanceI 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 -
Error when querying SSAS 2000 OLAP cube with WebI (BOXIR2)
Hi,
I'd like to access a OLAP cube on Microsoft Analysis Server 2000 through Web Intelligence. The BO server is running BO XIR2 FP 5.7 on Windows Server 2003.
I've installed the pivot table services on the BO server and am able to connect to the SSAS. I then created a connection, and on top of that connection an universe. The universe categories and objects where retrieved from the cube.
When I now try to query the new universe, I get the following error message:
BusinessObjects115.OLAPI.Cube.1] : Failed to set properties (Database 'ITZD_2010' does not exist.).
ITZD_2010 is the name of the "folder" from which I selected the cube when creating the connection. The cube itself is called NFOTD and this name is also displayed as (not editable) database name in the connection details.
Any help is greatly appreciated!
JochenIn CCM i find 4 services:
Apache
Server Intelligence Agent
WinHTTP
World Wide Web Pubblish Service
Is Server Intelligence Agent the service to change?
i can't find WebI service....
Maybe you are looking for
-
Google calender and google contacts won't sync AGA...
I am getting very tired of Nokia now! Actually I've had it with Nokia! One last Change, My wife and I have now received Nokia phones number 4 and 5 from the care center. I now have a E7-00 with a poorly responsive touchscreen, my wife now has a N8, w
-
Text in column 2 starts under the lowest line of column 1?
Hello, i posted this question also in the Dutch forum, but there are not so many viewers in there, and now i found this forum. I have a problem with Dreamweaver CS4 (i am still very new with DW, but manage to create something) I am working with CS4 a
-
Can't use airport for iphone if macbook is using ethernet cable
I recently switched to a new internet provider and noticed that downloads are faster for my macbook if it is connected by ethernet to my router. However in order to use the ethernet connection, I have to turn off airport in system preferences. When I
-
SPECIAL STOCK Indictor u201CE - Orders on Handu201D
Hi, Our existing process is as follows: We have Material with Serial Number activated. a. We sale to the Camera to our customer. Here the Status of the Serial Number becomes u201CECUSu201D. b. Due to some reason, the Customer Return the Camera. We cr
-
Account Annotations in Planning Dataform
Hi All, I've created a Dataform, but when i wanted to create Account Annotations, I can t see the option to enable account annotations in the data form . My Data form has Account in row , Period in Column and entity , scenario and version in page . A