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. 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. As with other forms of precomputation, database users typically use materialized views for performance reasons, i.e. as a form of optimization.
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".)
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.
Video Materialized view
Implementations
Oracle
Materialized views were implemented first by the Oracle Database: the Query rewrite feature was added from version 8i.
Example syntax to create a materialized view in Oracle:
PostgreSQL
In PostgreSQL, version 9.3 and newer natively support materialized views. 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
. In version 9.4, the refresh may be concurrent with selects on the materialized view if CONCURRENTLY
is used.
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. In IBM DB2, they are called "materialized query tables"; Microsoft SQL Server has a similar feature called "indexed views". MySQL doesn't support materialized views natively, but workarounds can be implemented by using triggers or stored procedures or by using the open-source application Flexviews.
Maps Materialized view
References
External links
- Materialized View Concepts and Architecture - Oracle
- SQL Snippets: SQL Features Tutorials - Materialized Views - Oracle
- Oracle9i Replication Management API Reference Release 2 (9.2)
- Materialized Views in Oracle 11.2
- Materialized query tables in DB2
Source of the article : Wikipedia