Materialized View

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 using an aggregate function.

The process of setting up a materialized view is sometimes called materialization.[1] This is a form of caching the results of a query, similar to memoization of the value of a function in functional languages, and it is sometimes described as a form of precomputation.[2][3] As with other forms of precomputation, database users typically use materialized views 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.[] (C. J. Date regards the phrase "materialized view" as a deprecated term for a "snapshot".)[5]

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: the query result is cached as a concrete ("materialized") table (rather than a view as such) that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of extra storage and of some data being potentially out-of-date. Materialized views find use especially 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

Oracle

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

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

In PostgreSQL, version 9.3 and newer natively support materialized views.[7] In version 9.3, a materialized view is not auto-refreshed, and is populated only at time of creation (unless WITH NO DATA is used). It may be refreshed later manually using REFRESH MATERIALIZED VIEW.[8] In version 9.4, the refresh may be concurrent with selects on the materialized view if CONCURRENTLY is used.[9]

SQL Server

Microsoft SQL Server differs from other RDBMS by the way of implementing materialized view via a concept known as "Indexed Views". The main difference is that such views do not require a refresh because they are in fact always synchronized to the original data of the tables that compound the view. To achieve this, it is necessary that the lines of origin and destination are "deterministic" in their mapping which limits the types of possible queries to do this. This mechanism has been realised since the 2000 version of SQL Server.

Example syntax to create a materialized view in SQL Server:

CREATE VIEW MV_MY_VIEW
WITH SCHEMABINDING
AS 
SELECT COL1, SUM(COL2) AS TOTAL
FROM <table_name>
GROUP BY COL1;
GO
CREATE UNIQUE CLUSTERED INDEX XV 
   ON MV_MY_VIEW (COL1);

Stream processing frameworks

Both Apache Kafka (since v0.10.2) and Apache Spark (since v2.0) support materialized views on streams of data.

Others

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


References

  1. ^ Compare: 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.". p. 59. ISBN 978-1-4493-9115-7. Retrieved . materialization[:] A somewhat unsophisticated technique for implementing operations on views according to which (a) the relational expression that defines the view is evaluated at the time the operation is invoked, (b) the view is thereby materialized, and (c) the operation in question is then executed against the relation so materialized. 
  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. ^ 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.". p. 59. ISBN 978-1-4493-9115-7. Retrieved . materialized view[:] Deprecated term for a snapshot. [...] The problem is [...] that (as the definition indicates) snapshots have come to be known, at least in some circles, not as snapshots at all but as materialized views. But snapshots aren't views; views are virtual and snapshots aren't, and 'materialized view' is a contradiction in terms (at least as far as the model is concerned). Worse yet, the unqualified term view is often taken to mean a materialized view specifically, and thus we're in danger of no longer having a good term for a view in the original sense. 
  6. ^ Oracle8i Tuning Release 8.1.5. Ecst.csuchico.edu. Retrieved on 2012-02-09.
  7. ^ PostgreSQL: Materialized Views. Wiki.postgresql.org (2010-05-07). Retrieved on 2013-09-25.
  8. ^ PostgreSQL: Documentation: 9.3: CREATE MATERIALIZED VIEW. PostgreSQL.com. Retrieved on 2014-01-25.
  9. ^ PostgreSQL: Documentation: 9.4: REFRESHED MATERIALIZED VIEW. PostgreSQL.com. Retrieved on 2015-01-23.
  10. ^ Materialized Views - Sybase SQL Anywhere. Ianywhere.com. Retrieved on 2012-02-09.
  11. ^ Improving Performance with SQL Server 2005 Indexed Views. Microsoft.com. Retrieved on 2012-02-09.
  12. ^ Implementing materialized views in MySQL. Shinguz.ch (2006-11-06). Retrieved on 2012-02-09.
  13. ^ Flexviews for MySQL - incrementally refreshable materialized views w/ MySQL. Flexviews.sourceforge.net. Retrieved on 2012-02-09.

External links


  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

Materialized_view
 



 

Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.


Manage research, learning and skills at NCR Works. Create an account using LinkedIn to manage and organize your omni-channel knowledge. NCR Works is like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us