Guideline

ReportNet Usage with Oracle Materialized Views
Product(s): IBM Cognos ReportNet Area of Interest: Modeling

ReportNet Usage with Oracle Materialized Views

2

Copyright Copyright © 2008 Cognos ULC (formerly Cognos Incorporated). Cognos ULC is an IBM Company. While every attempt has been made to ensure that the information in this document is accurate and complete, some typographical errors or technical inaccuracies may exist. Cognos does not accept responsibility for any kind of loss resulting from the use of information contained in this document. This document shows the publication date. The information contained in this document is subject to change without notice. Any improvements or changes to the information contained in this document will be documented in subsequent editions. This document contains proprietary information of Cognos. All rights are reserved. No part of this document may be copied, photocopied, reproduced, stored in a retrieval system, transmitted in any form or by any means, or translated into another language without the prior written consent of Cognos. Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. All other names are trademarks or registered trademarks of their respective companies. Information about Cognos products can be found at www.cognos.com This document is maintained by the Best Practices, Product and Technology team. You can send comments, suggestions, and additions to cscogpp@ca.ibm.com .

IBM Cognos Proprietary Information

ReportNet Usage with Oracle Materialized Views

3

Contents
1 2 3 3.1 3.2 3.3 3.4 3.5 4 5 6 INTRODUCTION ............................................................................................ 4 WHEN TO USE MATERIALIZED VIEWS WITH REPORTNET ........................... 4 GENERAL IMPLEMENTATION GUIDELINES FOR MATERIALIZED VIEWS ..... 5 CREATE MODEL AND REPORTS ..................................................................................... 6 SCHEMA AND DIMENSION DEFINITION ............................................................................ 7 MATERIALIZED VIEWS DEFINITION AND CREATION ............................................................ 9 TESTING QUERIES ................................................................................................... 12 SHOW THE PLAN ..................................................................................................... 12 EXAMPLES ................................................................................................... 14 TOOLS ......................................................................................................... 26 TIPS ............................................................................................................ 27

RECOMMENDED READING...................................................................................... 30

IBM Cognos Proprietary Information

month week. even in situations where the MV only partially fulfills the query requirement. 2 When to use Materialized Views with ReportNet The use of an Oracle Materialized Views approach for optimizing query performance for large data warehouses is a widely implemented technique. improving not just individual performance but also overall system performance.Materialized Views are used by the RDBMS query optimizer transparently by rewriting queries to use pre-calculated views.ReportNet Usage with Oracle Materialized Views 4 1 Introduction Materialized views are used to improve query performance on large databases. Improved Load times and an ability to more effectively manage and reduce the staleness of the data. Reduced development associated with the optimization of your application. Here are three areas where primary benefits would be realized through this approach: • Optimized query performance against large data warehouses . • • IBM Cognos Proprietary Information . These queries often involve operations such as joins or aggregation which are expensive in terms of processing and time. The query optimizer transparently re-writes query requests so that they use the materialized views as opposed to the detail tables. MV can be used by a report at different levels of aggregation. Materialized views can be designed using a dimensional approach. The Oracle query re-write mechanisms operate transparently and developing new reports and queries can benefit directly from past efforts and new optimizations do not requires updates to existing reports. such as year. These pre-computed summaries would typically be very small compared to the original source data. This is something that is difficult to achieve with custom aggregate aware applications. They accomplish this by transparently using pre-computed summarizations and joins of data. It represents a set of functionality which offers a more cost efficient approach than the aggregate table approach. More queries can be improved with fewer materialized views. Higher percentage of queries benefit.

Large materialized views may also need to be partitioned. • Presume to define sum and count of the same expression • Count(*) is mandatory • Review the business requirements with regards to refreshing the views. • Avoid building views that have wide rows or how cardinality (number of rows) starts to come within 10%1 of the size of the original fact table • Ensure to have the ReportNet (CRN) and database administrator (DBA) teams work together at the start of the project as the FM model and core reports/queries are designed. This may enable some views to include fast refresh unfriendly aggregates because less frequent full refreshes would be acceptable. 1 This is a very general value IBM Cognos Proprietary Information .ReportNet Usage with Oracle Materialized Views 5 3 General Implementation Guidelines for Materialized Views Here are some general guidelines when implementing Materialized as part of the solution. • All constraints can be declared to ORACLE as non-enforced constraints if preferred. • Large fact tables are often partitioned frequently by the time dimension. • Ensure to include the appropriate aggregate expressions to solve as many queries as possible. • Each child must uniquely identify a single parent and ideally be verified against the data using the DBMS_DIMENSION package to ensure integrity. • The child side of a parent-child relationship between a dimension and fact table or between tables in snowflake dimension should be described with primary-foreign keys and the child side columns should be declared as not null. • The view should be indexed to support query execution and refresh performance. This ensures that queries and view designs can be reviewed and adjusted appropriately.

IBM Cognos Proprietary Information . Using best practices model the dimensional metadata when creating the star or snowflake model.1 Create Model and Reports The steps in this process are to create the desired data model and the reports or queries required. While a DBA may be able to explain what ORACLE is doing with a given SQL statement they frequently do not know what factors influence ReportNet as it generated it. It is important to have the person(s) responsible for the Framework Manager (FM) model.ReportNet Usage with Oracle Materialized Views 6 This document will give an overview of the major activities involved in the implementation of Materialized views in a ReportNet environment. The SQL generated by the query engine attempts to preserve the query subject names which can aid in isolating which objects are being used by a report/query. The below figure gives a Flow of these activities. ORACLE database and reports/queries to work closely together. If relationships defined are not accurate they could result in impedance with the view. Create Model & Reports Verify Schema Create Define & Create Test Dimensions Materialized Queries Views 3. Because relationships could be defined in multiple places in an FM model it is very important to verify which relationship to review.

2 Schema and Dimension definition The next activity after creating your model and reports is to review the schema and identify the dimensions. • • • • • The parent-child relationships between a dimension and fact table should be described using PRIMARY and FOREIGN keys. The constraints can be declared and not enforced using the RELY clause. The columns in the FOREIGN KEY should be defined with the NOT NULL constraint. A dimension that is physically implemented as a snowflake should also use PRIMARY and FOREIGN keys. Query re-write must be configured at the instance or session level to TRUSTED or FORCED when RELY is used. Example of a table definition with constraints IBM Cognos Proprietary Information . There a few guidelines when dimensions are defined and what constraints should exist to maximize query re-writes.ReportNet Usage with Oracle Materialized Views 7 3.

"DOCUMENT_CLASS_SID" NUMBER(38).... These objects are used to perform join-back and rollup along a dimension. The specification of this metadata enables a much richer set of query re-writes and materialized view recommendations by ORACLE.CUSTOMER_CAT5_CD LEVEL CUSTOMER_KEY IS CUSTOMER. "SALES_ORG_SID" NUMBER(38). This metadata provides the database engine the rollup structure within the dimension which it can use at runtime.LEVEL1_CUSTOMER_NO LEVEL LEVEL2_CUSTOMER_NO IS CUSTOMER. ) Dimension and hierarchy metadata should also be defined in the Oracle Database.CUSTOMER_CAT3_CD LEVEL CUSTOMER_CAT4_CD IS CUSTOMER. "CREATED_DT" DATE..CITY LEVEL COUNTRY_CD IS CUSTOMER.CUSTOMER_CAT1_CD LEVEL CUSTOMER_CAT2_CD IS CUSTOMER.CUSTOMER_CAT2_CD LEVEL CUSTOMER_CAT3_CD IS CUSTOMER. . "CHANGED_DT" DATE."ORGANIZATION" ("SALES_ORG_SID") RELY NOVALIDATE .CUSTOMER_CAT4_CD LEVEL CUSTOMER_CAT5_CD IS CUSTOMER..ReportNet Usage with Oracle Materialized Views 8 CREATE TABLE "EAPPS". A dimension contains multiple levels and hierarchies that can map against a snow-flake or de-normalized dimension table."BILLING" ( ..COUNTRY_CD LEVEL CUSTOMER_CAT1_CD IS CUSTOMER..LEVEL3_CUSTOMER_NO IBM Cognos Proprietary Information .CUSTOMER_SID LEVEL LEVEL1_CUSTOMER_NO IS CUSTOMER. … CONSTRAINT "BILLING_FK1151013785192867" FOREIGN KEY ("SALES_ORG_SID") REFERENCES "EAPPS".LEVEL2_CUSTOMER_NO LEVEL LEVEL3_CUSTOMER_NO IS CUSTOMER. Example of dimension object CREATE DIMENSION EAPPS.. . .CUSTOMER_DIM LEVEL CITY_CD IS CUSTOMER. CHECK ("SALES_ORG_SID" IS NOT NULL) VALIDATE .

A materialized view definition can include aggregation such as SUM. • If a materialized view is to be used by query rewrite.ReportNet Usage with Oracle Materialized Views 9 LEVEL LEVEL4_CUSTOMER_NO IS CUSTOMER. MAX. COUNT(x). VARIANCE or STDDEV. MIN. AVG. one or more tables joined together and a GROUP BY. When creating materialized views there a few basic guidelines to follow • Create materialized views that satisfy the largest number of queries.3 Materialized Views Definition and creation Once the above two activities have been accomplished successfully the next step is to define the materialized views. COUNT (DISTINCT). IBM Cognos Proprietary Information . COUNT (*). it must be stored in the same database as the detail tables on which it relies.LEVEL4_CUSTOMER_NO LEVEL REGION_CD IS CUSTOMER.REGION_CD HIERARCHY CATEGORY_HIER ( CUSTOMER_KEY CHILD OF CUSTOMER_CAT5_CD CHILD OF CUSTOMER_CAT4_CD CHILD OF CUSTOMER_CAT3_CD CHILD OF CUSTOMER_CAT2_CD CHILD OF CUSTOMER_CAT1_CD ) HIERARCHY CUSTOMER_NM_HIER ( CUSTOMER_KEY CHILD OF LEVEL4_CUSTOMER_NO CHILD OF LEVEL3_CUSTOMER_NO CHILD OF LEVEL2_CUSTOMER_NO CHILD OF LEVEL1_CUSTOMER_NO ) HIERARCHY GEO_HIER ( CUSTOMER_KEY CHILD OF CITY_CD CHILD OF REGION_CD CHILD OF COUNTRY_CD ) 3. The view may also be indexed partitioned.

count(*) “KNT”. IBM Cognos Proprietary Information .TAX_AMT) – BILLING.ReportNet Usage with Oracle Materialized Views • • • 10 A materialized view definition can include any number of aggregations.EXTENDED_PRICE_AMT + BILLING. … sum(((BILLING. A materialized view can be partitioned. and you can define a materialized view on a partitioned table You can also define one or more indexes on the materialized view. count(BILLING.EXTENDED_PRICE_AMT). It can also include any number of joins. MATERIAL.FREIGHT_AMT) + BILLING. … from CUSTOMER.DISCOUNT_AMT). sum(BILLING. One approach to defining the view which includes the dimension keys as opposed to projecting for the attributes of the dimensions.QUANTITY). ORGANIZATION. sum(BILLING. count(BILLING. One reason for using this approach is that it reduces the space occupied by the view and supports a wider set of re-writes such as ad-hoc queries that reference a subset of the dimensions in the star schema. Example creating a View CREATE MATERIALIZED VIEW EAPPS. ALL_TIME.EXTENDED_PRICE_AMT). sum(BILLING.QUANTITY). ORGANIZATION.SALES_ORG_SID.CUSTOMER_SID. This is possible because ORACLE has the metadata to enable it to join-back to the dimension tables at runtime should a query project. MATERIAL.DISCOUNT_AMT). filter or group.TIME_SID.MATERIAL_SID.MV_BILLINGS1 TABLESPACE EAPPS BUILD IMMEDIATE REFRESH FORCE ENABLE QUERY REWRITE as select CUSTOMER.

• Exact Match . ALL_TIME."MV_BILLINGS1" ("SALES_ORG_SID") TABLESPACE "EAPPS". countries UK and USA and query requests data for the UK only IBM Cognos Proprietary Information . but query groups by store name • Filtered data . A SQL query does not have to exactly match the materialized view definition in order for it to be used."MV_BILLINGS1" ("MATERIAL_SID") TABLESPACE "EAPPS". CREATE BITMAP INDEX "EAPPS". ANALYZE TABLE "EAPPS".CUSTOMER_SID = BILLING.CUSTOMER_SID. ORGANIZATION. because query rewrite uses a number of different types of rewrite methods which are listed below.where the join conditions and grouping columns in the query and materialized view match exactly • Aggregation to All . for example.MATERIAL_SID and ORGANIZATION.SALES_ORG_SID. materialized view grouped on store_id. materialized view is at month level.MATERIAL_SID = BILLING."MV_BILL_ORG" ON "EAPPS". e."MV_BILL_CUST" ON "EAPPS". CREATE BITMAP INDEX "EAPPS".materialized view only contains part of the data.TIME_SID .CUSTOMER_SID and MATERIAL.g. but a dimension exists which defines how to rollup data from month to quarter • Join Back . CREATE BITMAP INDEX "EAPPS".g.ReportNet Usage with Oracle Materialized Views ALL_TIME.the materialized view is grouped by product and month. e.SALES_ORG_SID = BILLING. one should define indexes for the dimension columns. For performance reasons.TIME_SID = BILLING.column in materialized view is used to join back to dimension."MV_BILLINGS1" ("TIME_SID") TABLESPACE "EAPPS".SALES_ORG_SID and ALL_TIME.MATERIAL_SID. CREATE BITMAP INDEX "EAPPS"."MV_BILLINGS1" ("CUSTOMER_SID") TABLESPACE "EAPPS"."MV_BILL_TIME" ON "EAPPS"."MV_BILLINGS1" ESTIMATE STATISTICS."MV_BILL_MATL" ON "EAPPS". BILLING where 11 CUSTOMER.TIME_SID group by CUSTOMER. but the query is by products • Rollup . MATERIAL.query is by quarter.

set lines 130 set head off select plan_table_output from table(dbms_xplan. Use either approach and ensure to test the queries and reports as interactive HTML or PDF as appropriate. IBM Cognos Proprietary Information . TOAD etc. This or other 3rd party tools that trace the wire protocol can allow the logs to be captured locally to the workstation. HTML) report. Assuming the DBA has created the re-write table the following command can be used to ask ORACLE if the query would re-write to a specified view. The following examples use the SQL*plus interface (command line) that will be found on most machines while tools such as Enterprise Manager.display('PLAN_TABLE'.4 12 Testing queries There are several methods in ORACLE to look at queries.5 Show the plan Assuming that the DBA constructed the plan table for the RDBMS and the RDBMS is 9iR2 or 10G the following skeleton could be used to review a query. ORACLE also offers SQL statement tracing that requires access to the location used by the ORACLE instance to write the traces. 3. The rollup processing will default to assuming that the query reflects an interactive (a.ReportNet Usage with Oracle Materialized Views 3. This feature does not prompt the user prior to generating the SQL which results in optional filters being dropped from the query and default values for the prompts.'ALL')). are less common. It is also possible to leave ORACLE to define why any views in the system were considered good or bad candidates. Assuming the native SQL is available the following commands can be used to review a statement. truncate table plan_table.a. Report Studio has the ability to show native SQL for a query.null. Obtaining the native SQL generated by IBM Cognos tools is to enable IPF logging to capture native SQL commands. explain plan for put-your-sql-here . Doing so will avoid the following anomalies as it relates to prompting and the mode of execution.k. Note: Any literals in the SQL must use double single quotes to escape them within the string being passed to the procedure.

create procedure p( p_string in varchar2 ) is l_string long default p_string. END. ‘put-your-mview-name-here). 1. dbms_output. begin loop exit when l_string is null.rewriteArrayType := SYS.EXPLAIN_REWRITE (qrytext. 250 ) ). DBMS_MVIEW. DECLARE qrytext VARCHAR2(4000). IBM Cognos Proprietary Information .put_line( substr( l_string. Create this procedure so it can be used by the following statement when testing a query. 251 ). / set serveroutput on size 1000000 declare Rewrite_Array sys. QSM-01033: query rewritten with materialized view. end loop. end.RewriteArrayType().ReportNet Usage with Oracle Materialized Views 13 truncate table rewrite_table. MV_BILLINGS1 ORACLE 10 has improved the parameter interface over 9i. 2 Courtesy Tom Kyte of ORACLE. l_string := substr( l_string. / select message from rewrite_table order by sequence. BEGIN qrytext :=' put-your-sql-here '. querytxt varchar2(4000) := ' put-your-sql-here '. this means that it should be harder to submit a large SQL string and run into buffer overflow errors that seem to occur with 9i. The following code presents a workaround method which includes a workaround to an ORACLE output routine as well2.

"EAPPS". "CUSTOMER".mv_name)."CUSTOMER_CAT1_CD" IBM Cognos Proprietary Information . for i in 1. p('Message: ' ||Rewrite_Array(i).message). "ALL_TIME".query_text)."ALL_TIME" "ALL_TIME".ReportNet Usage with Oracle Materialized Views 14 msg_no number. end loop. -."CALENDAR_YEAR"."TIME_SID" group by "ALL_TIME"."CALENDAR_QUARTER".. "EAPPS"."CUSTOMER_SID" and "BILLING"."CUSTOMER_CAT1_CD" "C2". "ALL_TIME". The native SQL generated for this query when run as HTML is: select "ALL_TIME".count.p('Query : ' ||Rewrite_Array(1)."QUANTITY") "C3" from "EAPPS". 4 Examples ReportNet generates a rich set of SQL statements and quickly allows authors to construct complex expressions and aggregations."BILLING" "BILLING" where "BILLING". i number. msg_no := rewrite_array. Rewrite_Array). end."CUSTOMER" "CUSTOMER"."CALENDAR_YEAR" "C0"."CALENDAR_QUARTER" "C1". "CUSTOMER".explain_rewrite(querytxt. Often. Consider the basic group query in Query Studio. begin dbms_snapshot. sum("BILLING". the resultant SQL does not look like the ‘traditional’ SQL shown in manuals and documentation."TIME_SID"="ALL_TIME".msg_no loop p('MV Name: ' ||Rewrite_Array(i). 'put-your-mvname-here'."CUSTOMER_SID"="CUSTOMER".

"C1" "CALENDAR_QUARTER"."CALENDAR_YEAR"."C3") over (partition by "T0"."C0") "QUANTITY2" from (select "ALL_TIME"."TIME_SID" group by "ALL_TIME"."CUSTOMER_CAT1_CD" "C2"."BILLING" "BILLING" where "BILLING"."CUSTOMER_CAT1_CD" ) "T0" order by "CALENDAR_YEAR" asc Both of these queries will re-write to use the example materialized view."CUSTOMER_SID"="CUSTOMER". sum("T0"."ALL_TIME" "ALL_TIME". "T0". "T0".ReportNet Usage with Oracle Materialized Views 15 The equivalent PDF report will use an extended aggregation that is pushed to ORACLE: select "T0". "EAPPS"."C0" "CALENDAR_YEAR"."QUANTITY") "C3" from "EAPPS"."CALENDAR_QUARTER" "C1". "CUSTOMER"."C2" "CUSTOMER_CAT1_CD". sum("BILLING". "ALL_TIME". "T0"."TIME_SID"="ALL_TIME"."C3" "QUANTITY"."CUSTOMER_SID" and "BILLING"."CUSTOMER" "CUSTOMER". "ALL_TIME". "EAPPS"."C3") over () "QUANTITY1"."CALENDAR_QUARTER"."CALENDAR_YEAR" "C0". sum("T0". "CUSTOMER". IBM Cognos Proprietary Information .

limit the region codes to the North East) that result in derived tables being generated.ReportNet Usage with Oracle Materialized Views 16 Query subjects may be defined with embedded filters (i. IBM Cognos Proprietary Information .e. Consider the following simple cross tabular report.

"CUSTOMER"."CALENDAR_YEAR" "CALENDAR_YEAR"."ALL_TIME" "ALL_TIME"."CITY" "CITY". sum("BILLING"."REGION_NM" "REGION_NM"."REGION_NM" "REGION_NM" from "EAPPS"."REGION_NM" "REGION_NM"."CUSTOMER_SID" "CUSTOMER_SID"."CUSTOMER" "CUSTOMER" IBM Cognos Proprietary Information . "Q3"."CALENDAR_YEAR" "CALENDAR_YEAR". "CUSTOMER".ReportNet Usage with Oracle Materialized Views 17 select "Q3"."REGION_CD" "REGION_CD". "CUSTOMER". "CUSTOMER"."QUANTITY") "QUANTITY" from "EAPPS". (select "CUSTOMER". "CUSTOMER"."COUNTRY_CD" "COUNTRY_CD"."QUANTITY" "QUANTITY" from (select "ALL_TIME". "Q3".

SEL$E30F1547 3 ."TIME_SID" group by "ALL_TIME". 'OH'. 'MD'. 'NJ'. 'MS'."TIME_SID") 4 ."CUSTOMER_SID") 5 .ReportNet Usage with Oracle Materialized Views where 18 "CUSTOMER". "CUSTOMER". 'FL'. 'SC'. 'KY'."CUSTOMER_SID" and "BILLING". 'CT'."CUSTOMER_SID"="CUSTOMER".filter("CUSTOMER". 'AL'."REGION_CD"='CT' OR IBM Cognos Proprietary Information . 'RI'.access("MV_BILLINGS1". 'ME'. 'VT'."REGION_CD" in ('MA'.SEL$E30F1547 / MV_BILLINGS1@SEL$0F4384E5 Predicate Information (identified by operation id): --------------------------------------------------2 ."CALENDAR_YEAR".SEL$E30F1547 / ALL_TIME@SEL$2 5 ."REGION_NM" ) "Q3" -------------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | -------------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 357 | 14280 | | 8861 (4)| 00:01:47 | | 1 | SORT GROUP BY | | 357 | 14280 | | 8861 (4)| 00:01:47 | |* 2 | HASH JOIN | | 2028K| 77M| | 8684 (2)| 00:01:45 | | 3 | TABLE ACCESS FULL | ALL_TIME | 2920 | 29200 | | 12 (0)| 00:00:01 | |* 4 | HASH JOIN | | 2028K| 58M| 792K| 8652 (2)| 00:01:44 | |* 5 | TABLE ACCESS FULL | CUSTOMER | 26859 | 472K| | 1241 (2)| 00:00:15 | | 6| MAT_VIEW REWRITE ACCESS FULL| MV_BILLINGS1 | 2028K| 23M| | 4685 (1)| 00:00:57 | -------------------------------------------------------------------------------------------------------Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------1 . 'WV'. 'NY'."CUSTOMER_SID"="CUSTOMER"."BILLING" "BILLING" where "BILLING".access("ALL_TIME". 'NH'. 'VT') ) "CUSTOMER". 'NC'."REGION_CD"='AL' OR "CUSTOMER". 'PA'. 'NH'."TIME_SID"="ALL_TIME". "EAPPS"."TIME_SID"="MV_BILLINGS1". 'VA'. 'GA'. 'MA'. 'MI'. 'TN'. 'IN'. 'ME'.SEL$E30F1547 / CUSTOMER@SEL$3 6 .

"REGION_CD"='KY' OR "CUSTOMER"."REGION_CD"='MA' OR "CUSTOMER"."REGION_CD"='FL' OR "CUSTOMER". 'Cans'."REGION_CD"='NH' OR "CUSTOMER". "EAPPS". "EAPPS"."QUANTITY") "C3" from (select "CUSTOMER"."REGION_CD"='RI' OR "CUSTOMER". 'CT'. 'FL'. "CUSTOMER". sum("BILLING"."BILLING" "BILLING" where "MATERIAL"."REGION_CD"='NY' OR "CUSTOMER"."MATERIAL" "MATERIAL". 'SC'."REGION_NM" "REGION_NM" from "EAPPS". 'AL'. 'VT'. 'MI'. "ALL_TIME". 'ME'."REGION_CD"='IN' OR "CUSTOMER"."REGION_CD"='NJ' OR "CUSTOMER"."REGION_CD"='GA' OR "CUSTOMER". 'WV'. 'NC'."REGION_CD"='MS' OR "CUSTOMER"."REGION_CD"='OH' OR "CUSTOMER"."COUNTRY_CD" "COUNTRY_CD". 'IN'."CUSTOMER_SID" "CUSTOMER_SID". 'OH'. "CUSTOMER". 'ME'."REGION_CD" "REGION_CD". 'MA'. 'NY'."REGION_CD"='MI' OR "CUSTOMER". 'Boxes'. "MATERIAL"."CUSTOMER_SID"="CUSTOMER"."CALENDAR_YEAR" "C2"."REGION_CD" in ('MA'."REGION_NM" "C0". 'NJ'. 'GA'."MATERIAL_CAT2_DSC" in ('Bottles'. 'NH'."REGION_CD"='SC' OR "CUSTOMER"."REGION_CD"='WV') This scenario introduces additional filters on the dimensions and group filters select "CUSTOMER"."REGION_CD"='ME' OR "CUSTOMER". "CUSTOMER". "EAPPS". 'NH'. 'VT') ) "CUSTOMER". "CUSTOMER"."REGION_CD"='VT' OR "CUSTOMER". 'KY'."CUSTOMER_SID" IBM Cognos Proprietary Information ."CUSTOMER" "CUSTOMER" where "CUSTOMER". 'RI'."REGION_CD"='TN' OR "CUSTOMER". 'VA'. 'Chemicals') and "BILLING". 'PA'."REGION_CD"='VA' OR "CUSTOMER"."CITY" "CITY"."REGION_CD"='MD' OR "CUSTOMER". 'MD'. 'MS'."REGION_CD"='NC' OR "CUSTOMER". 'TN'."REGION_CD"='PA' OR "CUSTOMER"."ALL_TIME" "ALL_TIME"."MATERIAL_CAT2_DSC" "C1".ReportNet Usage with Oracle Materialized Views 19 "CUSTOMER".

"REGION_NM". "MATERIAL".ReportNet Usage with Oracle Materialized Views and "BILLING"."MATERIAL_SID"="MATERIAL". "ALL_TIME"."TIME_SID" group by "CUSTOMER"."CALENDAR_YEAR" having sum("BILLING"."QUANTITY") between 500 and 1000 20 Due to the size of the plan only the operation table is shown."MATERIAL_SID" and "BILLING". -------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | -------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | 1 | TEMP TABLE TRANSFORMATION | 2 | LOAD AS SELECT |* 3 | TABLE ACCESS FULL 472K| | 4 | LOAD AS SELECT |* 5 | TABLE ACCESS FULL 814K| |* 6 | FILTER | | 7 | SORT GROUP BY |* 8 | | 9| |* 10 | HASH JOIN TABLE ACCESS FULL HASH JOIN | | ALL_TIME | | | | | CUSTOMER | | MATERIAL | | | 202 | 11514 | | | | | | | | 26859 | | | | | 52105 | | | | 202 | 11514 | | 185K| 10M| | 2920 | 29200 | | 185K| 8498K| | 11 | TABLE ACCESS FULL 52105 | 814K| |* 12 | HASH JOIN | SYS_TEMP_0FD9D66DB_4C5EFD | | | 185K| 5605K| | 13 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66DA_4C5EFD | 26859 | 393K| | 14 | MAT_VIEW REWRITE ACCESS BY INDEX ROWID| MV_BILLINGS1 185K| 2893K| | 15 | BITMAP CONVERSION TO ROWIDS | | | | 16 | BITMAP AND | | | | | 17 | BITMAP MERGE | | | | | 18 | BITMAP KEY ITERATION | | | | | | IBM Cognos Proprietary Information ."MATERIAL_CAT2_DSC"."TIME_SID"="ALL_TIME".

"C2" "C2". select "T0"."C1" "C1". "T0". The native SQL generated by ReportNet is still re-written to leverage the materialized view. "T0". IBM Cognos Proprietary Information ."C0" "C0".ReportNet Usage with Oracle Materialized Views | 19 | | 13 | |* 20 | | | 21 | | 22 | | 23 | | 13 | |* 24 | | TABLE ACCESS FULL BITMAP INDEX RANGE SCAN 21 1 | | SYS_TEMP_0FD9D66DA_4C5EFD | | MV_BILL_CUST | BITMAP MERGE BITMAP KEY ITERATION TABLE ACCESS FULL BITMAP INDEX RANGE SCAN | | | | | | | | | SYS_TEMP_0FD9D66DB_4C5EFD | | MV_BILL_MATL | | 1 This example introduces a % of group and ranking that were not specified in the materialized view.

"C4") over (partition by "T0"."C0") "C3". "CUSTOMER"."REGION_NM" "REGION_NM" from "EAPPS". first_value("T0". 'MS'."REGION_NM" "C0". "CUSTOMER". 'VT') ) "CUSTOMER"."CUSTOMER_SID" "CUSTOMER_SID"."ALL_TIME" "ALL_TIME"."C2" "C2". 'OH'.ReportNet Usage with Oracle Materialized Views sum("T0"."CUSTOMER_SID"="CUSTOMER"."COUNTRY_CD" "COUNTRY_CD". "EAPPS"."C1" "C1"."C3" "C4"."CITY" "CITY". 'MI'. sum("T0". "T0". 'FL'."CUSTOMER_SID" and "BILLING"."C0" "C0"."C0") "C7" from (select "T0". 'WV'. 'VA'. 'KY'."C2") over (partition by "T0"."TIME_SID"="ALL_TIME". "T0"."C2") over () "C3"."REGION_CD" in ('MA'. sum("T0"."C4" "C6". "CUSTOMER"."C0") "C4" from (select "CUSTOMER". 'SC'. 'PA'. 'MA'. 'ME'."C2") over (partition by "T0". 'NH'. sum("BILLING". 'ME'. first_value("T0". "CUSTOMER"."C0") "C5". 'NC'. 'CT'."TIME_SID" group by "CUSTOMER". 'RI'."CALENDAR_YEAR" ) "T0" ) "T0" IBM Cognos Proprietary Information ."REGION_NM"."BILLING" "BILLING" where "BILLING". 'AL'."CALENDAR_YEAR" "C1". 'NJ'. 'GA'. 'TN'. 'VT'. 'IN'."QUANTITY") "C2" from (select 22 "CUSTOMER". "ALL_TIME". 'MD'. "ALL_TIME". 'NY'."C3") over (partition by "T0". 'NH'. "T0". "EAPPS". "T0"."REGION_CD" "REGION_CD"."CUSTOMER" "CUSTOMER" where "CUSTOMER".

"CUSTOMER" "CUSTOMER" where "CUSTOMER". 'CT'. ORACLE will attempt to re-write the query to leverage the materialized view. 'PA'. "CUSTOMER"."REGION_NM" "REGION_NM". 'IN'. 'MA'. "CUSTOMER"."QUANTITY")*0. 'NJ'. "ALL_TIME"."CUSTOMER_SID" and "BILLING". 'VT') ) "CUSTOMER". 'WV'."CALENDAR_QUARTER" "CALENDAR_QUARTER". "REGION_NM" asc The model may contain predefined derived measures in the fact table that the user simply drags onto their report."COUNTRY_CD" "COUNTRY_CD"."CALENDAR_YEAR"=1998 and "BILLING". select "ALL_TIME". "EAPPS"."CALENDAR_QUARTER" order by "CALENDAR_YEAR" asc.ReportNet Usage with Oracle Materialized Views 23 Calculations can be performed against aggregates such as this simple calculation to compute 50% of the total value."CUSTOMER_SID" "CUSTOMER_SID". 'MS'."CALENDAR_YEAR"."REGION_NM". 'NH'. 'ME'. sum("BILLING". 'MI'."QUANTITY") "QUANTITY". 'SC'."TIME_SID"="ALL_TIME". (select "CUSTOMER". 'TN'. 'MD'. 'VA'."REGION_NM" "REGION_NM" from "EAPPS"."BILLING" "BILLING" where "ALL_TIME". "ALL_TIME". "CUSTOMER". IBM Cognos Proprietary Information . 'OH'. 'GA'. "CUSTOMER"."CITY" "CITY". "CUSTOMER". 'VT'."REGION_CD" in ('MA'. 'FL'. 'KY'."TIME_SID" group by "CUSTOMER"."ALL_TIME" "ALL_TIME". 'ME'."CUSTOMER_SID"="CUSTOMER". 'NH'. "ALL_TIME".5 "calc1" from "EAPPS"."REGION_CD" "REGION_CD". 'RI'. 'NC'."CALENDAR_YEAR" "CALENDAR_YEAR". 'NY'. 'AL'. sum("BILLING".

"C2" "c4" from (select "ALL_TIME".ReportNet Usage with Oracle Materialized Views 24 select "T0"."COUNTRY_CD" "COUNTRY_CD". "T0"."C0" "CALENDAR_YEAR"."Calculation") "C2" from "EAPPS". "T0"."REGION_NM" "C1". IBM Cognos Proprietary Information ."CALENDAR_YEAR" "C0". "CUSTOMER"."ALL_TIME" "ALL_TIME". 1 "C_____CubeDetailsItem"."C1" "REGION_NM". sum("BILLING". "CUSTOMER". (select "CUSTOMER"."CITY" "CITY"."REGION_CD" "REGION_CD". "CUSTOMER"."CUSTOMER_SID" "CUSTOMER_SID". "CUSTOMER".

(("BILLING"."BILLING" "BILLING" ) "BILLING" where "BILLING". 'CT'. 'MS'."FREIGHT_AMT")+"BILLING"."TIME_SID"="ALL_TIME"."CUSTOMER" "CUSTOMER" where 25 "CUSTOMER". 'NC'. 'VT'."REGION_CD" in ('MA'."REGION_NM" "REGION_NM" from "EAPPS". "BILLING". 'VA'. 'NY'. 'NH'."CUSTOMER_SID" and "BILLING". 'ME'. 'TN'. 'WV'. 'SC'. "REGION_NM" asc -----------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -----------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 357 | 14637 | 6146 (5)| 00:01:14 | | 1 | SORT GROUP BY | | 357 | 14637 | 6146 (5)| 00:01:14 | |* 2 | HASH JOIN | | 2028K| 79M| 5969 (2)| 00:01:12 | | 3 | TABLE ACCESS FULL | ALL_TIME | 2920 | 29200 | 12 (0)| 00:00:01 | |* 4 | HASH JOIN | | 2028K| 59M| 5937 (2)| 00:01:12 | |* 5 | TABLE ACCESS FULL | CUSTOMER | 4671 | 84078 | 1233 (1)| 00:00:15 | | 6| MAT_VIEW REWRITE ACCESS FULL| MV_BILLINGS1 | 2028K| 25M| 4685 (1)| 00:00:57 | IBM Cognos Proprietary Information . 'ME'."TIME_SID" group by "ALL_TIME". 'MD'. 'IN'.ReportNet Usage with Oracle Materialized Views "CUSTOMER". "TAX_AMT") . 'MA'. 'RI'."CALENDAR_YEAR". 'NH'. (select "BILLING". "CUSTOMER"."CUSTOMER_SID"="CUSTOMER"."TIME_SID" "TIME_SID". 'PA'."EXTENDED_PRICE_AMT"+"BILLING". 'FL'."DISCOUNT_AMT" "Calculation" from "EAPPS"."BILLING". 'AL'. 'OH'. 'KY'. 'GA'."REGION_NM" ) "T0" order by "CALENDAR_YEAR" asc. 'MI'. 'NJ'."CUSTOMER_SID" "CUSTOMER_SID". 'VT') ) "CUSTOMER".

"REGION_NM"[VARCHAR2."TIME_SID"[NUMBER."MV_BILLINGS1".SEL$0FBF33B2 / ALL_TIME@SEL$2 5 ."SUM(((BILLING. "ALL_TIME".22]. SUM("MV_BILLINGS1".EXTENDED_PRICE_A"[NUMBER.22] 5 Tools Oracle9i came with a feature known as the Summary Advisor that recommended a set of materialized views for a given query workload.SEL$0FBF33B2 / MV_BILLINGS1@SEL$0F4384E5 Predicate Information (identified by operation id): --------------------------------------------------2 . IBM Cognos Proprietary Information .22]."CUSTOMER_SID"[NUMBER. "CUSTOMER".EXTENDED_PRICE_A")[22] 2 . "MV_BILLINGS1". "CUSTOMER". together with GUI functionality within Oracle Enterprise Manager.22] 4 .22]. Consisting of a number of procedures and functions within the DBMS_OLAP package.30].22].22].EXTENDED_PRICE_A"[NUMBER. "MV_BILLINGS1"."REGION_NM"[VARCHAR2."CUSTOMER". "MV_BILLINGS1".22].ReportNet Usage with Oracle Materialized Views 26 -----------------------------------------------------------------------------------------------Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------1 ."REGION_CD"='MA' OR "CUSTOMER".access("ALL_TIME"."CALENDAR_YEAR"[NUMBER."CUSTOMER"."TIME_SID"[NUMBER."SUM(((BILLING.SEL$0FBF33B2 3 ."TIME_SID") 4 .30]."ALL_TIME".22] 5 ."SUM(((BILLING. "CUSTOMER"."ALL_TIME". "MV_BILLINGS1".30]."CUSTOMER_SID"="MV_BILLINGS1"."TIME_SID"[NUMBER."REGION_NM"[VARCHAR2.22]. Summary Manager was a useful tool for recommending an aggregation strategy for your data warehouse. "MV_BILLINGS1"."REGION_CD"='VT') Column Projection Information (identified by operation id): ----------------------------------------------------------1 .30] 6 ."CALENDAR_YEAR"[NUMBER.22] 3 .filter("CUSTOMER"."REGION_NM"[VARCHAR2."CUSTOMER_SID") 5 ."CUSTOMER_SID"[NUMBER."REGION_CD"='NH' OR "CUSTOMER"."CALENDAR_YEAR"[NUMBER."TIME_SID"="MV_BILLINGS1"."SUM(((BILLING.EXTENDED_PRICE_A"[NUMBER."ALL_TIME".SEL$0FBF33B2 / CUSTOMER@SEL$3 6 ."REGION_CD"='ME' OR "CUSTOMER".access("CUSTOMER".

which needs to be licensed separately if using in a production environment. that now makes recommendations for both materialized views and indexes. the SQL Access Advisor can be used to either tune existing materialized views and indexes. Oracle has acknowledged this by providing a new tool. An important point to note with the SQL Access Advisor is that whilst it is installed by default as part of the 10g database installation. The effective creation of indexes is just as important and with Oracle Database 10g. it is actually part of the Enterprise Manager Tuning Pack. DBMS_ADVISOR. or to recommend them for new schemas that need tuning. the SQL Access Advisor. 6 Tips Always ensure to obtain the native SQL generated by CRN using either configuring the server to log Native Queries or via ORACLE SQL tracing IBM Cognos Proprietary Information . when looking to improve query response time within your Oracle data warehouse. Oracle 10g includes a number of enhancements to materialized views and the query rewrite mechanism.ReportNet Usage with Oracle Materialized Views 27 Summaries are only part of the story. and can now be delivered through alternative technologies such as the Oracle 10g OLAP Option.TUNE_MVIEW and the new query equivalence mechanism. Available through the DBMS_ADVISOR PL/SQL package. DBAs will find that summaries are easier to create. however. By using new features such as the SQL Access Advisor. are more likely to qualify for query rewrite.

Simple copy and paste the SQL into the query subject and right-mouse click and select the reformat option. To avoid this and make the text more readable define an empty query subject which is based on a database query. IBM Cognos Proprietary Information .ReportNet Usage with Oracle Materialized Views 28 Due to the size of the SQL statements errors may occur in tools when pasting in the statement.

ReportNet Usage with Oracle Materialized Views 29 IBM Cognos Proprietary Information .

oracle.html IBM Cognos Proprietary Information .1MR2) Recommended Reading ORACLE white papers and articles http://www.html ORACLE online documentation library (look for the Data Warehousing PDF) http://www.com/technology/products/bi/db/10g/dbbi_tech_info_perf.com/technology/documentation/database10g.ReportNet Usage with Oracle Materialized Views 30 If the customer requires that the application set the session settings instead of setting them at the instance they could: • Define ORACLE logon triggers that issue the statements • Define connection or session commands for the connection in the portal (Requires 1.oracle.

Sign up to vote on this title
UsefulNot useful