Materialized Views Acknowledgement to Author: Willie Albino.

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Refreshing Materialized Views
12 Copyright © 2005, Oracle. All rights reserved. Query Rewrite.
Oracle Materialized Views for Replication COUG Presentation, Feb 20, 2014 Jane Lamont,
Materialized Views.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
OLAP Services Business Intelligence Solutions. Agenda Definition of OLAP Types of OLAP Definition of Cube Definition of DMR Differences between Cube and.
Chapter 13 (Web): Distributed Databases
Introduction to Structured Query Language (SQL)
Data Replication with Materialized Views ISYS 650.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
View and Materialized view. What is a view? Logically represents subset of data from one or more table. In sql, a view is a virtual relation based on.
10 Copyright © 2009, Oracle. All rights reserved. Managing Undo Data.
Materialized views1 Materialized views (snapshot tables) Using Oracle.
Definition of terms Definition of terms Explain business conditions driving distributed databases Explain business conditions driving distributed databases.
ADVANCE REPLICATION Oracle Coretech Surabaya (OCS) One Day Seminar Surabaya, August 30 th 2008.
1.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Chapter 6 Additional Database Objects
1 Oracle Database 11g – Flashback Data Archive. 2 Data History and Retention Data retention and change control requirements are growing Regulatory oversight.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Materialized Views. 2 Materialized Views – Agenda What is a Materialized View? – Advantages and Disadvantages How Materialized Views Work – Parameter.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
Part Two: - The use of views. 1. Topics What is a View? Why Views are useful in Data Warehousing? Understand Materialised Views Understand View Maintenance.
1 Chapter 14 DML Tuning. 2 DML Performance Fundamentals DML Performance is affected by: – Efficiency of WHERE clause – Amount of index maintenance – Referential.
Overview – Chapter 11 SQL 710 Overview of Replication
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
Introduction to Oracle. Oracle History 1979 Oracle Release client/server relational database 1989 Oracle Oracle 8 (object relational) 1999.
1 Distributed Databases BUAD/American University Distributed Databases.
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Indexes and Views Unit 7.
Ing. Erick López Ch. M.R.I. Replicación Oracle. What is Replication  Replication is the process of copying and maintaining schema objects in multiple.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
Chapter 4 Logical & Physical Database Design
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
CERN/IT/DB Oracle9i & VLDB Montse Collados Polidura, IT/DB Database Workshop - July 2001.
20 Copyright © 2008, Oracle. All rights reserved. Cache Management.
Session id: Darrell Hilliard Senior Delivery Manager Oracle University Oracle Corporation.
Chapter 1 Database Access from Client Applications.
Oracle9i Performance Tuning Chapter 11 Advanced Tuning Topics.
Materialized views (snapshot tables)
Chapter 15 Materialized Views.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
14 Copyright © 2004, Oracle. All rights reserved. Using Materialized Views.
SQL Basics Review Reviewing what we’ve learned so far…….
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
9 Copyright © 2006, Oracle. All rights reserved. Summary Management.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
ORACLE's Approach ORALCE uses a proprietary mechanism for security. They user OLS.... ORACLE Labeling Security. They do data confidentiality They do adjudication.
10 Copyright © 2007, Oracle. All rights reserved. Managing Undo Data.
Client Warehouse Builder Your Chance to Learn! Why Would I Use It? Have some custom tables you want to warehouse and report off of Have additional reporting.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Table spaces.
How To Pass Oracle 1z0-060 Exam In First Attempt?
Materialized Views Willie Albino May 15, 2003.
Contents Preface I Introduction Lesson Objectives I-2
So What are Views and Triggers anyway?
SQL Views Presented by: Dr. Samir Tartir
Presentation transcript:

Materialized Views Acknowledgement to Author: Willie Albino

2 Materialized Views – Agenda What is a Materialized View? – Advantages and Disadvantages How Materialized Views Work – Parameter Settings, Privileges, Query Rewrite Creating Materialized Views – Syntax, Refresh Modes/Options, Build Methods – Examples

3 What is a Materialized View? A database object that stores the results of a query – Marries the query rewrite features found in Oracle Discoverer with the data refresh capabilities of snapshots Features/Capabilities – Can be partitioned and indexed – Can be queried directly – Can have DML applied against it – Several refresh options are available – Best in read-intensive environments

4 Ordinary views vs. materialized views Ordinary views – Virtual table – Named select statement Part of the SQL standard Syntax – CREATE VIEW viewName AS selectStatement Physical table – Replication of master data at a single point in time Not part of the SQL standard Syntax – CREATE MATERIALIZED VIEW viewName AS selectStatement

5 Why use materialized views? Replicate data to non-master sites – To save network traffic when data is used in transactions Cache expensive queries – Expensive in terms of time or memory – Example: Sum, average or other calculations on large amounts of data

6 Advantages and Disadvantages Advantages – Useful for summarizing, pre-computing, replicating and distributing data – Faster access for expensive and complex joins – Transparent to end-users MVs can be added/dropped without invalidating coded SQL Disadvantages – Performance costs of maintaining the views – Storage costs of maintaining the views

7 Database Parameter Settings System or session settings – query_rewrite_enabled={true|false} Can be set for a session using – alter session set query_rewrite_enabled=true; Privileges which must be granted to users directly – QUERY_REWRITE - for MV using objects in own schema – GLOBAL_QUERY_REWRITE - for objects in other schemas

8 Syntax For Materialized Views CREATE MATERIALIZED VIEW TABLESPACE { } REFRESH [ENABLE|DISABLE] QUERY REWRITE AS SELECT ; The determines when MV is built – BUILD IMMEDIATE: view is built at creation time – BUILD DEFFERED: view is built at a later time

9 Refresh Options – COMPLETE – totally refreshes the view Can be done at any time; can be time consuming – FAST – incrementally applies data changes A materialized view log is required on each detail table Data changes are recorded in MV logs or direct loader logs Many other requirements must be met for fast refreshes – FORCE – Try a FAST refresh, if not possible make COMPLETE The default refresh option Materialized View Refresh Options

10 Materialized View Refresh Modes Refresh Modes – ON COMMIT – refreshes occur whenever a commit is performed on one of the view’s underlying detail table(s) Available only with single table aggregate or join based views Keeps view data transactionally accurate Need to check alert log for view creation errors – ON DEMAND – refreshes are initiated manually using one of the procedures in the DBMS_MVIEW package Can be used with all types of materialized views Manual Refresh Procedures – DBMS_MVIEW.REFRESH(, ) – DBMS_MVIEW.REFRESH_ALL_MVIEWS() – START WITH [NEXT] - refreshes start at a specified date/time and continue at regular intervals

11 Materialized View Example CREATE MATERIALIZED VIEW items_summary_mv REFRESH FORCE AS SELECT a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID, sum(a.GMS) GMS, sum(a.NET_REV) NET_REV, sum(a.BOLD_FEE) BOLD_FEE, sum(a.BIN_PRICE) BIN_PRICE, sum(a.GLRY_FEE) GLRY_FEE, sum(a.QTY_SOLD) QTY_SOLD, count(a.ITEM_ID) UNITS FROM items a GROUP BY a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID; ANALYZE TABLE item_summary_mv COMPUTE STATISTICS;

12 Materialized View Example (cont’d) -- Query to test impact of materialized view select categ_id, site_id, sum(net_rev), sum(bold_fee), count(item_id) from items where prd_id in ('2000M05','2000M06','2001M07','2001M08') and site_id in (0,1) and categ_id in (2,4,6,8,1,22) group by categ_id, site_id save mv_example.sql

13 Materialized View Example (cont’d) SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=FALSE; CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID) Elapsed: 01:32:17.93 Execution Plan SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost= Card=6 Bytes=120) 1 0 SORT (GROUP BY) (Cost= Card=6 Bytes=120) 2 1 PARTITION RANGE (INLIST 3 2 TABLE ACCESS (FULL) OF ‘ ITEMS' (Cost= Card= Bytes= )

14 Materialized View Example (cont’d) SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=TRUE; CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID) Elapsed: 00:01:40.47 Execution Plan SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=3749 Card=12 Bytes=276) 1 0 SORT (GROUP BY) (Cost=3749 Card=12 Bytes=276) 2 1 PARTITION RANGE (INLIST) 3 2 TABLE ACCESS (FULL) OF ‘ ITEMS_SUMMARY_MV' (Cost=3723 Card=7331 Bytes=168613)

15 Example of FAST REFRESH MV CREATE MATERIALIZED VIEW LOG ON ITEMS TABLESPACE MV_LOGS STORAGE(INITIAL 10M NEXT 10M) WITH ROWID; CREATE MATERIALIZED VIEW LOG ON CUSTOMERS TABLESPACE MV_LOGS STORAGE(INITIAL 1M NEXT 1M) WITH ROWID; CREATE MATERIALIZED VIEW cust_activity BUILD IMMEDIATE REFRESH FAST ON COMMIT AS SELECT u.ROWID cust_rowid, l.ROWID item_rowid, u.cust_id, u.custname, u. , l.categ_id, l.site_id, sum(gms), sum(net_rev_fee) FROM customers u, items l WHERE u.cust_id = l.seller_id GROUP BY u.cust_id, u.custname, u. , l.categ_id, l.site_id;

16 Getting Information About an MV Getting information about the key columns of a materialized view: SELECT POSITION_IN_SELECT POSITION, CONTAINER_COLUMN COLUMN, DETAILOBJ_OWNER OWNER, DETAILOBJ_NAME SOURCE, DETAILOBJ_ALIAS ALIAS, DETAILOBJ_TYPE TYPE, DETAILOBJ_COLUMN SRC_COLUMN FROM USER_MVIEW_KEYS WHERE MVIEW_NAME= ‘ ITEMS_SUMMARY_MV ’ ; POS COLUMN OWNER SOURCE ALIAS TYPE SRC_COLUMN PRD_ID TAZ ITEMS A TABLE PRD_ID 2 SITE_ID TAZ ITEMS A TABLE SITE_ID 3 TYPE_CODE TAZ ITEMS A TABLE TYPE_CODE 4 CATEG_ID TAZ ITEMS A TABLE CATEG_ID

17 Getting Information About an MV Getting information about the aggregate columns of a materialized view: SELECT POSITION_IN_SELECT POSITION, CONTAINER_COLUMN COLUMN, AGG_FUNCTION FROM USER_MVIEW_AGGREGATES WHERE MVIEW_NAME= ‘ ITEMS_SUMMARY_MV ’ ; POSITION COLUMN AGG_FUNCTION GMS SUM 7 NET_REV SUM : : : 11 QTY_SOLD SUM 12 UNITS COUNT

Willie Albino May 15, Summary Materialized Views – reduce system cpu/io resource requirements by pre- calculating and storing results of intensive queries – allow for the automatic rewriting of intensive queries – are transparent to the application – have storage/maintenance requirements – can understand complex data relationships – can be refreshed on demand or on a schedule

19 Requirements for FAST REFRESH

20 Rqmts For FAST REFRESH (cont’d)