Materialized view

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

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. Materialized views, which store data based on remote tables, are also known as snapshots. A snapshot can be redefined as a materialized view.


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 extremely expensive.

In addition, because the materialized view is manifested as a real table, anything that can be done to a real table can be done to it, most importantly building indexes on any column, enabling drastic speedups in query time. 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.



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

Example syntax to create a materialized view in Oracle:

     AS SELECT * FROM <table_name>;


It is possible to implement materialized views in PostgreSQL; version 9.3 natively supports materialized views.[2] 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.[3]


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


  1. ^ Oracle8i Tuning Release 8.1.5. Retrieved on 2012-02-09.
  2. ^ PostgreSQL: Materialized Views. (2010-05-07). Retrieved on 2013-09-25.
  3. ^ PostgreSQL: Documentation: 9.3: CREATE MATERIALIZED VIEW. Retrieved on 2014-01-25.
  4. ^ Materialized Views – Sybase SQL Anywhere. Retrieved on 2012-02-09.
  5. ^ Improving Performance with SQL Server 2005 Indexed Views. Retrieved on 2012-02-09.
  6. ^ Implementing materialized views in MySQL. (2006-11-06). Retrieved on 2012-02-09.
  7. ^ Flexviews for MySQL – incrementally refreshable materialized views w/ MySQL. Retrieved on 2012-02-09.

External links[edit]