Presentation is loading. Please wait.

Presentation is loading. Please wait.

9 Copyright © 2006, Oracle. All rights reserved. Summary Management.

Similar presentations


Presentation on theme: "9 Copyright © 2006, Oracle. All rights reserved. Summary Management."— Presentation transcript:

1 9 Copyright © 2006, Oracle. All rights reserved. Summary Management

2 Copyright © 2006, Oracle. All rights reserved. 9- 2 Objectives After completing this lesson, you should be able to do the following: Discuss summary management and Oracle implementation of summaries Describe materialized views Identify the types, build modes, and refresh methods for materialized views Explain the query rewrite mechanism in Oracle Describe the significance of Oracle dimensions

3 Copyright © 2006, Oracle. All rights reserved. 9- 3 Summary Management Need How can you improve query’s response time? –Using indexes –Partitioning your data What about precomputing query results? Create summaries: –Use normal tables before Oracle8 i : — Need to rewrite applications — Need to manually maintain data –Use materialized views beginning with Oracle8 i : — Automatically rewrite SQL applications. — Automatically refresh data.

4 Copyright © 2006, Oracle. All rights reserved. 9- 4 Summary Management Summary management: –Improves query response time –Is the key to the performance of data warehouses A summary is a table that: –Stores preaggregated and prejoined data –Is based on user query requirements

5 Copyright © 2006, Oracle. All rights reserved. 9- 5 Summary Navigation Effective use of summary tables requires summary table awareness. Methods for summary navigation: –Warehouse database engine –Proprietary summary-aware products –Open summary-aware middleware –3GL and metadata solutions select total_sales... Which summaries?

6 Copyright © 2006, Oracle. All rights reserved. 9- 6 Managing Historical Summary Data in the Warehouse 2001200019991997/1998 Last 12 months daily detail Monthly summary data Quarterly summary data Yearly summary data

7 Copyright © 2006, Oracle. All rights reserved. 9- 7 Summary Management in Oracle Database 10g Materialized views: –Store precomputed aggregates and joins. –Results are stored in the database. –Use query rewrite. –Improve query performance. Summary Advisor: –Is a collection of functions and procedures (the DBMS_OLAP package) –Helps in defining and analyzing materialized views DBMS_OLAP

8 Copyright © 2006, Oracle. All rights reserved. 9- 8

9 Copyright © 2006, Oracle. All rights reserved. 9- 9 Before Materialized Views SELECT c.cust_id, SUM(amount_sold) FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id; CREATE TABLE cust_sales_sum AS SELECT c.cust_id, SUM(amount_sold) AS amount FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id; SELECT * FROM cust_sales_sum;

10 Copyright © 2006, Oracle. All rights reserved. 9- 10 After Materialized Views CREATE MATERIALIZED VIEW cust_sales_mv ENABLE QUERY REWRITE AS SELECT c.cust_id, SUM(amount_sold) AS amount FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id; SELECT c.cust_id, SUM(amount_sold) FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id; SELECT STATEMENT TABLE ACCESS (FULL) OF cust_sales_mv

11 Copyright © 2006, Oracle. All rights reserved. 9- 11 Types of Materialized Views Materialized views with aggregates Materialized views containing only joins CREATE MATERIALIZED VIEW cust_sales_mv AS SELECT c.cust_id, s.channel_id, SUM(amount_sold) AS amount FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id, s.channel_id; CREATE MATERIALIZED VIEW sales_products_mv AS SELECT s.time_id, p.prod_name FROM sales s, products p WHERE s.prod_id = p.prod_id(+);

12 Copyright © 2006, Oracle. All rights reserved. 9- 12 Nested Materialized Views A materialized view whose definition is based on another materialized view Definition that can also reference normal tables Common data warehouse situation: products sales times sales_time_prod_mv products sales times sales_prod_time_mv products sales times sales_prod_time_join sales_time_prod_mv sales_prod_time_mv

13 Copyright © 2006, Oracle. All rights reserved. 9- 13 Materialized View: Example CREATE MATERIALIZED VIEW cust_sales_mv PCTFREE 0 TABLESPACE summ STORAGE (initial 1M next 1M pctincrease 0) BUILD DEFERRED REFRESH COMPLETE ENABLE QUERY REWRITE USING NO INDEX AS SELECT c.cust_id, s.channel_id, SUM(amount_sold) AS amount FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id, s.channel_id ORDER BY c.cust_id, s.channel_id; Name Storage options When to build it How to refresh the data Use this for query rewrite Detail query Detail tables MV keys Do not create an index

14 Copyright © 2006, Oracle. All rights reserved. 9- 14 Materialized Views: Build Modes BUILD DEFERRED: MV created but not populated BUILD IMMEDIATE: MV created and populated ON PREBUILT TABLE : –Existing table is converted to MV : Same name and same schema. –Table is retained after MV is dropped. –Column aliases in detail query must correspond. –Detail tables and kidnapped table columns data types must match exactly by default. — WITH[OUT] REDUCED PRECISION clause –It is possible to have unmanaged columns in the table. – MV ’s STALENESS is set to UNKNOWN. BUILD_MODE in DBA_MVIEWS

15 Copyright © 2006, Oracle. All rights reserved. 9- 15 Materialized Views: Refresh Methods COMPLETE FAST FORCE NEVER

16 Copyright © 2006, Oracle. All rights reserved. 9- 16 Materialized Views: Refresh Modes ON DEMAND : Manual ON COMMIT : –Refresh is done at transaction commit. –It is possible only for fast-refreshable materialized views. –In case of failure, subsequent refreshes are manual. Schedule: At regular intervals

17 Copyright © 2006, Oracle. All rights reserved. 9- 17 Query Rewrite Mechanism in Oracle Database Choose (based on cost) Generate plan RewriteGenerate plan Execute

18 Copyright © 2006, Oracle. All rights reserved. 9- 18 Query Rewrite Execute query: SELECT c.cust_id, s.channel_id, SUM(amount_sold) AS amount FROM sales s, customers c WHERE s.cust_id = c.cust_id GROUP BY c.cust_id, s.channel_id Observe the execution plan: OPERATION NAME ---------------------- ----------------- SELECT STATEMENT TABLE ACCESS FULL cust_sales_mv

19 Copyright © 2006, Oracle. All rights reserved. 9- 19 Guidelines for Creating Materialized Views Define a single materialized view including all measures. Include COUNT(x) when using the aggregating measure AVG(x).

20 Copyright © 2006, Oracle. All rights reserved. 9- 20 How to Find the Best Materialized Views? One materialized view can be used to satisfy multiple queries. Multiple materialized views can satisfy the same query. A balance between performance and space usage must be found. Which one is the best? –Analyze your workload. –Use Summary Advisor. –Use EXPLAIN_REWRITE to see why a materialized view is used or ignored.

21 Copyright © 2006, Oracle. All rights reserved. 9- 21 Why Are Dimensions Important? Dimensions are data dictionary structures that have zero or more hierarchies based on existing columns. Create more hierarchies in dimensions for the following reasons: –They enable additional query rewrites without the use of constraints. –They help document hierarchies. –They can be used by online analytical processing (OLAP) tools.

22 Copyright © 2006, Oracle. All rights reserved. 9- 22 Month_Desc Attribute Year_Key Quarter_Key Month_Key Dimensions and Hierarchies ALL Calendar hierarchy Sales_Date Level keys

23 Copyright © 2006, Oracle. All rights reserved. 9- 23 Dimension Example Table TIME - YEAR_KEY - QUARTER_KEY - MONTH_KEY - MONTH_DESC - SALES_DATE Dimension TIME_DIM - YR - QTR - MON, MONTH_DESC - SDATE

24 Copyright © 2006, Oracle. All rights reserved. 9- 24 Defining Dimensions and Hierarchies CREATE DIMENSION time_dim LEVEL sdate IS time.sales_date LEVEL mon IS time.month_key LEVEL qtr IS time.quarter_key LEVEL yr IS time.year_key HIERARCHY calendar_rollup ( sdate CHILD OF mon CHILD OF qtr CHILD OF yr ) ATTRIBUTE mon DETERMINES month_desc; Year Quarter Month Sales date

25 Copyright © 2006, Oracle. All rights reserved. 9- 25 Dimensions with Multiple Hierarchies YR QTR MON YR WK DT Calendar hierarchy Week hierarchy = =

26 Copyright © 2006, Oracle. All rights reserved. 9- 26 Rewrites Using Dimensions SELECT v.year, s.brand, s.city_name, SUM(s.tot_sales) FROM sales_sumry s, (SELECT distinct t.month, t.year FROM time t) v WHERE s.month = v.month GROUP BY v.year, s.brand, s.city_name; SELECT t.year, p.brand, c.city_name, SUM(s.amt) FROM sales s, city c, time t, product p WHERE s.sales_date = t.sdate AND s.city_name = c.city_name AND s.state_code = c.state_code AND s.prod_code = p.prod_code GROUP BY t.year, p.brand, c.city_name;

27 Copyright © 2006, Oracle. All rights reserved. 9- 27 Summary In this lesson, you should have learned how to: Discuss summary management and Oracle implementation of summaries Describe materialized views Identify the types, build modes, and refresh methods for materialized views Explain the query rewrite mechanism in Oracle Describe the significance of Oracle dimensions

28 Copyright © 2006, Oracle. All rights reserved. 9- 28 Practice 9-1: Overview This practice covers the following topics: Identifying the importance of summary management for RISD data warehouse Identifying the refresh strategy for the RISD materialized views Examining materialized views and other concepts discussed in the lesson

29 Copyright © 2006, Oracle. All rights reserved. 9- 29

30 Copyright © 2006, Oracle. All rights reserved. 9- 30


Download ppt "9 Copyright © 2006, Oracle. All rights reserved. Summary Management."

Similar presentations


Ads by Google