Materialized view

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In computing, a materialized view is a database object that contains the results of a query. For example, it may be a local copy of data located remotely, or may be a subset of the rows and/or columns of a table or join result, or may be a summary based on aggregations of a table's data.

The process of creating a materizalied view is sometimes called materialization.[1] It is sometimes described as a form of precomputation.[2][3] As with other forms of precomputation, materialized views are typically created for performance reasons, i.e. as a form of optimization.[4]

Materialized views, which store data based on remote tables, are also known as snapshots. A snapshot can be redefined as a materialized view.[clarification needed] According to C. J. Date, the term "materialized view" is deprecated in favor of "snapshot".[1]

Introduction[edit]

In any database management system following the relational model, a view is a virtual table representing the result of a database query. Whenever a query or an update addresses an ordinary view's virtual table, the DBMS converts these into queries or updates against the underlying base tables. A materialized view takes a different approach in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of some data being potentially out-of-date. It is most useful in data warehousing scenarios, where frequent queries of the actual base tables can be expensive.

In a materialized view, indexes can be built on any column. In contrast, in a normal view, it's typically only possible to exploit indexes on columns that come directly from (or have a mapping to) indexed columns in the base tables; often this functionality is not offered at all.

Implementations[edit]

Oracle[edit]

Materialized views were implemented first by the Oracle Database: the Query rewrite feature was added from version 8i.[5]

Example syntax to create a materialized view in Oracle:

 CREATE MATERIALIZED VIEW MV_MY_VIEW
REFRESH FAST START WITH SYSDATE
   NEXT SYSDATE + 1
     AS SELECT * FROM <table_name>;

PostgreSQL[edit]

It is possible to implement materialized views in PostgreSQL; version 9.3 natively supports materialized views.[6] In the current version 9.3 the materialized views are not auto-refreshed, and are populated only at time of creation (unless WITH NO DATA is used) and may be refreshed later manually using REFRESH MATERIALIZED VIEW command.[7]

Others[edit]

Materialized views are also supported in Sybase SQL Anywhere.[8] In IBM DB2, they are called "materialized query tables"; Microsoft SQL Server has a similar feature called "indexed views".[9] MySQL doesn't support materialized views natively, but workarounds can be implemented by using triggers or stored procedures [10] or by using the open-source application Flexviews.[11]

References[edit]

  1. ^ a b C.J. Date (28 August 2006). The Relational Database Dictionary: A Comprehensive Glossary of Relational Terms and Concepts, with Illustrative Examples. "O'Reilly Media, Inc.". pp. 59–. ISBN 978-1-4493-9115-7. 
  2. ^ Karen Morton; Kerry Osborne; Robyn Sands; Riyaj Shamsudeen, Jared Still (28 October 2013). Pro Oracle SQL. Apress. p. 48. ISBN 978-1-4302-6220-6. 
  3. ^ Marie-Aude Aufaure; Esteban Zimányi (16 January 2012). Business Intelligence: First European Summer School, EBISS 2011, Paris, France, July 3-8, 2011, Tutorial Lectures. Springer Science & Business Media. p. 43. ISBN 978-3-642-27357-5. 
  4. ^ Michael L. Gonzales (25 February 2003). IBM Data Warehousing: with IBM Business Intelligence Tools. John Wiley & Sons. p. 214. ISBN 978-0-471-45736-7. 
  5. ^ Oracle8i Tuning Release 8.1.5. Ecst.csuchico.edu. Retrieved on 2012-02-09.
  6. ^ PostgreSQL: Materialized Views. Wiki.postgresql.org (2010-05-07). Retrieved on 2013-09-25.
  7. ^ PostgreSQL: Documentation: 9.3: CREATE MATERIALIZED VIEW. PostgreSQL.com. Retrieved on 2014-01-25.
  8. ^ Materialized Views – Sybase SQL Anywhere. Ianywhere.com. Retrieved on 2012-02-09.
  9. ^ Improving Performance with SQL Server 2005 Indexed Views. Microsoft.com. Retrieved on 2012-02-09.
  10. ^ Implementing materialized views in MySQL. Shinguz.ch (2006-11-06). Retrieved on 2012-02-09.
  11. ^ Flexviews for MySQL – incrementally refreshable materialized views w/ MySQL. Flexviews.sourceforge.net. Retrieved on 2012-02-09.

External links[edit]