Oracle’s Materialized View Defined
A materialized view within an Oracle database is an object that extends the functionality of an ordinary view and contains the results of a query (SQL select statement) in a persistent or physical format. Materialized views can use either tables, views, and other materialized views as its data source and can be both indexed and/or refreshed.
Within an Oracle database, a view is a virtual table representing the result of a database query or select command with a table or another view as its source. Whenever a select query or an update addresses a view, the database converts these statements into select queries or updates against the source tables of the view’s select query. Thus a view is just a stored query or virtual table with no storage of physical data, and the physical data is stored in a table. However, a materialized view takes a different approach in which the query result is cached as a concrete table that can be refreshed from the source tables of the select query. This enables better query performance, at the cost of some data being potentially out-of-date.
Because a materialized view is manifested as a physical table, anything that can be performed to a real table can be done to the materialized view. With the most important thing that can be performed is the ability to build indexes on any field, enabling drastic speedups in query performance time. In a view, it’s typically only possible to utilize indexes on columns that come directly from (or have a mapping to) indexed columns in the source table. In addition, a materialized view can contain denormalized data that physically exists in multiple tables, a subset of fields and records that exist in physical tables, pre-calculation of table fields, and data pre-aggregated at summary levels.
Materialized views are most useful in analytical data repositories such data warehouses or data marts, where query performance is important and data refreshes and updates occur infrequently. Materialized views are one of the single most important database tuning tools that exist allowing you to pre-join complex table and views and pre-compute summaries for fast response time of queries.
Create Materialized View Syntax
- Create Materialized View DeptCheckMV
- Start with Sysdate
- As
- Select * From EmployeeTbl
- Where Salary > (Select avg (salary) from EmployeeTbl