Definition | A materialized view is a database object that contains the results of a query. The FROM clause of the query can name tables, views, and other materialized views. Collectively these objects are called master tables (a replication term) or detail tables (a data warehousing term). This reference uses "master tables" for consistency. The databases containing the master tables are called the master databases. Materialized views, which store data based on remote tables are also known as snapshots.
| ||||||||||||||||
Materialized View Syntaxes |
| ||||||||||||||||
Data Dictionary Objects |
| ||||||||||||||||
Related Packages and Libraries |
| ||||||||||||||||
System Privileges |
| ||||||||||||||||
| |||||||||||||||||
Related Definitions | |||||||||||||||||
Materialized View Log | When DML changes are made to master table data, Oracle Database stores rows describing those changes in the materialized view log and then uses the materialized view log to refresh materialized views based on the master table. This process is called incremental or fast refresh. Without a materialized view log, Oracle Database must re-execute the materialized view query to refresh the materialized view. This process is called a complete refresh. Usually, a fast refresh takes less time than a complete refresh. | ||||||||||||||||
Build | Specifies when to populate the materialized view. Specify IMMEDIATE to indicate that the materialized view is to be populated immediately: The default. Specify DEFERRED to indicate that the materialized view is to be populated by the next REFRESH operation. The first (deferred) refresh must always be a complete refresh. Until then, the materialized view has a staleness value of UNUSABLE, so it cannot be used for query rewrite.
| ||||||||||||||||
Caching | For data that will be accessed frequently, CACHE specifies that the blocks retrieved for this table are placed at the most recently used end of the least recently used (LRU) list in the buffer cache when a full table scan is performed. This attribute is useful for small lookup tables. NOCACHE specifies that the blocks are placed at the least recently used end of the LRU list. | ||||||||||||||||
Cluster | Creates materialized views as part of a cluster. A cluster materialized view uses the space allocation of the cluster. Partitioning is not allowed when an MV is built on a cluster. | ||||||||||||||||
Complex Materialized View | Each row in the materialized view can not be mapped back to a single row in a source table. For example a materialized view based on an aggregation, concatenation, group by, having, rollup, cube, or similar functionality. | ||||||||||||||||
Compression | Use the table_compression clause to instruct the database whether to compress data segments to reduce disk and memory use. The COMPRESS keyword enables table compression. The NOCOMPRESS keyword disables table compression. | ||||||||||||||||
Organization Index | Create an index-organized materialized view. IOT can be specified for the following:
The keywords and parameters of the index_org_table_clause have the same semantics as described in CREATE TABLE, with the restrictions that follow. | ||||||||||||||||
Parallel | The parallel_clause indicates whether parallel operations will be supported for the materialized view and sets the default degree of parallelism for queries and DML on the materialized view after creation. | ||||||||||||||||
Partitioning | Materialized views can be partitioned just like any other heap table. | ||||||||||||||||
Prebuilt Tables | The ON PREBUILT TABLE clause lets you register an existing table as a preinitialized materialized view. This clause is particularly useful for registering large materialized views in a data warehousing environment. The table must have the same name and be in the same schema as the resulting materialized view. | ||||||||||||||||
Query Rewrite | If the schema owner does not own the master tables, then the schema owner must have the GLOBAL QUERY REWRITE privilege or the QUERY REWRITE object privilege on each table outside the schema. | ||||||||||||||||
Refresh Group | A grouping of materialized views so that they can be refreshed as a single transaction for consistency. | ||||||||||||||||
Refresh Log | When DML changes are made to master table data, Oracle Database stores rows describing those changes in the materialized view log and then uses the materialized view log to refresh materialized views based on the master table. This process is called incremental or fast refresh. Without a materialized view log, Oracle Database must re-execute the materialized view query to refresh the materialized view. This process is called a complete refresh. Usually, a fast refresh takes less time than a complete refresh. | ||||||||||||||||
Refresh Types |
| ||||||||||||||||
Simple Materialized View | Each row in the materialized view can be mapped back to a single row in a source table. | ||||||||||||||||
Snapshot | The keyword SNAPSHOT is supported in place of MATERIALIZED VIEW for backward compatibility. In 11g and 12c it can be ignored. | ||||||||||||||||
Using Index | The USING INDEX clause allow establishing values for INITRANS and STORAGE parameters for the default index used to maintain the materialized view. If USING INDEX is not specified, then default tablespace values are used. The default index is used to speed up incremental (FAST) refresh of the materialized view. | ||||||||||||||||
Enables creation of a materialized view on top of a table that has a non-NULL Virtual Private Database (VPD) policy on it. It ensures that the materialized view behaves correctly. Materialized view results are computed based on the rows and columns filtered by VPD policy. Therefore, you must coordinate the materialized view definition with the VPD policy to ensure the correct results. Without the USING TRUSTED CONSTRAINTS clause, any VPD policy on a master table will prevent a materialized view from being created. | |||||||||||||||||
| |||||||||||||||||
Create Materialized View | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
Force Refresh Using Trusted Constraints | CREATE MATERIALIZED VIEW <schema.name> | ||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn sh/sh@pdborcl | |||||||||||||||||
CREATE MATERIALIZED VIEW <schema.name> | |||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
| |||||||||||||||||
Allocate Extent | ALTER MATERIALIZED VIEW <schema.materialized_view> | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple ALLOCATE EXTENT (SIZE 64K); | |||||||||||||||||
Caching | ALTER MATERIALIZED VIEW <schema.materialized_view> <CACHE | NOCACHE>; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple CACHE; | |||||||||||||||||
Coalesce | ALTER MATERIALIZED VIEW <schema.materialized_view> | ||||||||||||||||
See IOT Library page linked at page bottom | |||||||||||||||||
Compile | ALTER MATERIALIZED VIEW <schema.materialized_view> COMPILE; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple COMPILE; | |||||||||||||||||
Consider Fresh | ALTER MATERIALIZED VIEW <schema.materialized_view> CONSIDER FRESH; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_complete CONSIDER FRESH; | |||||||||||||||||
Deallocate Unused | ALTER MATERIALIZED VIEW <schema.materialized_view> DEALLOCATE UNUSED; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_complete DEALLOCATE UNUSED; | |||||||||||||||||
LOB Storage | ALTER MATERIALIZED VIEW <schema.materialized_view> LOB (lob_item) STORE AS (lob_storage_parameters); | ||||||||||||||||
See LOBs linked at page bottom | |||||||||||||||||
Logging | ALTER MATERIALIZED VIEW <schema.materialized_view> <LOGGING | NOLOGGING>; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple LOGGING; | |||||||||||||||||
Modify LOB Storage | ALTER MATERIALIZED VIEW <schema.materialized_view> | ||||||||||||||||
See LOBs linked at page bottom | |||||||||||||||||
Parallel Access | ALTER MATERIALIZED VIEW <schema.materialized_view> <PARALLEL | NO_PARALLEL>; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple PARALLEL; | |||||||||||||||||
Physical Attributes | ALTER MATERIALIZED VIEW <schema.materialized_view> ( | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple PCTFREE 1; | |||||||||||||||||
Query Rewrite | ALTER MATERIALIZED VIEW <schema.materialized_view> <ENABLE | DISABLE> QUERY REWRITE; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple ENABLE QUERY REWRITE; | |||||||||||||||||
Refresh | ALTER MATERIALIZED VIEW <schema.materialized_view> | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_complete REFRESH COMPLETE; | |||||||||||||||||
Shrink | ALTER MATERIALIZED VIEW <schema.materialized_view> SHRINK SPACE <COMPACT | CASCADE>; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple ENABLE ROW MOVEMENT; | |||||||||||||||||
Table Compression | ALTER MATERIALIZED VIEW <schema.materialized_view> <COMPRESS | NOCOMPRESS>; | ||||||||||||||||
ALTER MATERIALIZED VIEW mv_simple COMPRESS; | |||||||||||||||||
Table Partitioning | ALTER MATERIALIZED VIEW <schema.materialized_view> .... | ||||||||||||||||
See Partitioning Library Page | |||||||||||||||||
| |||||||||||||||||
Drop | |||||||||||||||||
Drop Materialized View | DROP MATERIALIZED VIEW <schema.materialized_view>; | ||||||||||||||||
SELECT table_name | |||||||||||||||||
Drop Snapshot | DROP MATERIALIZED VIEW <schema.materialized_view>; | ||||||||||||||||
SELECT table_name | |||||||||||||||||
Drop Materialized View Preserve Table | DROP MATERIALIZED VIEW <schema.materialized_view> PRESERVE TABLE; | ||||||||||||||||
SELECT table_name | |||||||||||||||||
| |||||||||||||||||
Create Fast Refresh Log Table | CREATE MATERIALIZED VIEW LOG ON <schema.table_name> | ||||||||||||||||
conn uwclass/uwclass@pdbdev | |||||||||||||||||
Include a base table column in the materialized view log | CREATE MATERIALIZED VIEW LOG ON servers | ||||||||||||||||
CREATE MATERIALIZED VIEW LOG ON servers | |||||||||||||||||
| |||||||||||||||||
Add Clause | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers ADD SEQUENCE; | |||||||||||||||||
Alter Physical Attributes | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> | ||||||||||||||||
SELECT table_name, pct_free, pct_used | |||||||||||||||||
Alter Parallel Access | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> <NOPARALLEL | PARALLEL <integer>>; | ||||||||||||||||
SELECT table_name, degree | |||||||||||||||||
Alter Logging Clause | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> <LOGGING | NOLOGGING>; | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers LOGGING; | |||||||||||||||||
Alter Allocate Extent by Size | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers | |||||||||||||||||
Alter Allocate Extent by Datafile | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers | |||||||||||||||||
Alter Allocate Extent by Instance | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers ALLOCATE EXTENT (INSTANCE 1); | |||||||||||||||||
Log Caching | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> <CACHE | NOCACHE>; | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers CACHE; | |||||||||||||||||
Shrink Log | ALTER MATERIALIZED VIEW LOG [FORCE] ON <schema.table_name> [COMPACT] [CASCADE]; | ||||||||||||||||
ALTER MATERIALIZED VIEW LOG ON servers | |||||||||||||||||
| |||||||||||||||||
Truncate Refresh Log | |||||||||||||||||
MV Log Purging does not shrink the logs. This technique shrinks them though it does require obtaining an exclusive lock on the base table. |
| ||||||||||||||||
| |||||||||||||||||
| |||||||||||||||||
Drop Refresh Log | |||||||||||||||||
Drop Log | DROP MATERIALIZED VIEW LOG ON <table_name>; | ||||||||||||||||
DROP MATERIALIZED VIEW LOG ON servers; | |||||||||||||||||
| |||||||||||||||||
Addendum | |||||||||||||||||
| |||||||||||||||||
To determine if a materialized view is in the process of being refreshed | SELECT 1 | ||||||||||||||||
No comments:
Post a Comment