Materialized Views
Materialized views are query results that have been stored or "materialized" in advance as schema objects. The FROM clause of the query can name tables, views, and materialized views. Collectively
these objects are called master tables (a replication term) or detail tables (a data warehousing term).
Materialized views are used to summarize, compute, replicate, and distribute data. They are suitable in various computing environments,
such as the following:
■In data warehouses, you can use materialized views to compute and store data generated from aggregate functions such as sums and averages.
A summary is an aggregate view that reduces query time by precalculating joins and aggregation operations and storing the
results in a table. Materialized views are equivalent to summaries (see "Data Warehouse Architecture (Basic)" on page 17-17). You can also use materialized views to compute joins with or without aggregations. If compatibility is set to Oracle9i or higher,
then materialized views are usable for queries that include filter selections.
■In materialized view replication, the view contains a complete or partial copy of a table from a single point in time. Materialized
views replicate data at distributed sites and synchronize updates performed at several sites. This form of replication is suitable for environments such as field sales when databases are not always connected to the network.
■In mobile computing environments, you can use materialized views to download a data subset from central servers to mobile clients, with periodic refreshes from the central servers and
propagation of updates by clients to the central servers.
In a replication environment, a materialized view shares data with a table in a different database, called a master database. The table associated with the materialized view at the master
site is the master table. Figure 4–7 illustrates a materialized view in one database based on a master table in another database. Updates to the master table replicate to the materialized view database.
Characteristics of Materialized Views
Materialized views share some characteristics of nonmaterialized views and indexes. Materialized views are similar to indexes
in the following ways:
■They contain actual data and consume storage space.
■They can be refreshed when the data in their master tables changes.
■They can improve performance of SQL execution when used for query rewrite operations.
■Their existence is transparent to SQL applications and users.
A materialized view is similar to a nonmaterialized view because it represents data in other tables and views. Unlike indexes,
users can query materialized views directly using SELECT statements. Depending on the types of refresh that are required, the views can also be updated with DML statements.
The following example creates and populates a materialized aggregate view based on three master tables in the sh sample schema:
CREATE MATERIALIZED VIEW sales_mv AS
SELECT t.calendar_year, p.prod_id, SUM(s.amount_sold) AS sum_sales
FROM times t, products p, sales s
WHERE t.time_id = s.time_id
AND p.prod_id = s.prod_id
GROUP BY t.calendar_year, p.prod_id;
The following example drops table sales, which is a master table for sales_mv, and then queries sales_mv. The query selects data because the rows are stored (materialized) separately from the
data in the master tables.
SQL> DROP TABLE sales;
Table dropped.
SQL> SELECT * FROM sales_mv WHERE ROWNUM < 4;
CALENDAR_YEAR PROD_ID SUM_SALES
------------- ---------- ----------
1998 13 936197.53
1998 26 567533.83
1998 27 107968.24
A materialized view can be partitioned. You can define a materialized view on a partitioned table and one or more indexes on
the materialized view.
Refresh Methods for Materialized Views
The database maintains data in materialized views by refreshing them after changes to their master tables. The refresh method
can be incremental, known as fast refresh, or a complete refresh.
A complete refresh occurs when the materialized view is initially defined as BUILD IMMEDIATE, unless the materialized view references a prebuilt table. The refresh involves executing
the query that defines the materialized view. This process can be slow, especially if the database must read and process huge amounts of data.
A fast refresh eliminates the need to rebuild materialized views from scratch. Thus, processing only the changes can result in a very fast refresh time. Materialized views can be refreshed
either on demand or at regular time intervals. Alternatively, materialized views in the same database as their master tables can be refreshed whenever a transaction commits its changes to the master tables.
For materialized views that use the fast refresh method, a materialized view log or direct loader log keeps a record of changes
to the master tables. A materialized viewlog is a schema object that records changes to master table data so that a materialized view defined on the master table can be refreshed incrementally. Each materialized view log is associated with a single master
table. The materialized view log resides in the same database and schema as its master table.
Query Rewrite
Query rewrite is an optimization technique that transforms a user request written in terms of master tables into a semantically
equivalent request that includes materialized views. When base tables contain large amounts of data, computing an aggregate or join is expensive and time-consuming. Because materialized views contain precomputed aggregates and joins, query rewrite can quickly
answer queries using materialized views.
The optimizer query transformer transparently rewrites the request to use the materialized view, requiring no user intervention and no reference to the materialized view in the SQL statement.
Because query rewrite is transparent, materialized views can be added or dropped without invalidating the SQL in the application code.
In general, rewriting queries to use materialized views rather than detail tables improves response time. Figure 4–8 shows the database generating an execution plan for the original
and rewritten query and choosing the lowest-cost plan.
查询重写相关资料
分享到:
相关推荐
数据库领域关于“实视图”方面的论文汇编。是从事数据库研究、应用不可多得的资料。
Simulation for Generate Efficient Evaluation Plans With Materialized Views
9 Advanced Materialized Views 10 Dimensions Part IV Managing the Data Warehouse Environment 11 Overview of Extraction, Transformation, and Loading 12 Extraction in Data Warehouses 13 Transportation ...
ORACLE只支持以下分区:tables, indexes on tables, materialized views, and indexes on materialized views 分区对SQL和DML是透明的(应用程序不必知道已经作了分区),但是DDL可以对不同的分区进行管理。 ...
Materialized views are similar to views. A materialized view enables you to save a frequently used or complex query, then access the query results in a SELECT statement as if they were a table. ...
This second edition covers LATERAL queries, augmented JSON support, materialized views, and other key topics. If you're a current PostgreSQL user, you'll pick up gems you may have missed before.
为了进一步提高数据仓库的性能, 通过分析数据仓库中性能优化技术的特点, 提出了索引和物化视图耦合的性能优化技术。通过数据挖掘自动选择候选索引和物化视图, 减少查询的扫描范围; 然后研究在物化视图上建立索引的...
The rapidly increasing volume of information contained in relational databases places a strain on databases, performance, and ... materialized views, bitmap indexes, automated design tools, and more!
Create reusable components that bring Bootstrap and Angular together and effectively use materialized views for caching within Postgres. Get your front end working with Webpack, use Postgres' ...
materialized_views ==================== 使用在 Postgres 中创建自动更新物化视图的方法扩展ActiveRecord::Migration 。 可以执行来检查物化视图是否与其非物化版本保持同步。 背景 以下是有关物化视图的一些...
He applies previous approaches to other physical structures, such as materialized views, partitioning, and multidimensional clustering. He also analyzes workload models for new types of applications,...
Blend partitioning and materialized views into your indexing strategy Who This Book Is For Expert Oracle Indexing and Access Paths is for all levels of database administrators and application ...
Use secondary indexes and materialized views to avoid denormalization of data Effortlessly handle concurrent updates with collection columns Ensure data integrity with lightweight transactions and ...
Materialized Views (Snapshots) 938 Materialized View (Snapshot) Logs 940 Oracle Scheduler 941 Packages 953 Policies 955 Policy Groups 956 Procedures 957 Profiles 959 Queue Tables 960 Queues 964 ...
You can now refresh materialized views from the popup menu. File Browser enhancements Git and Subversion support has been added. File icons now indicate the PL/SQL Developer file type. You can now ...
You can now refresh materialized views from the popup menu. File Browser enhancements Git and Subversion support has been added. File icons now indicate the PL/SQL Developer file type. You can now ...
13.5 Materialized Views 607 13.6 Advanced Topics in Query Optimization 612 13.7 Summary 615 Exercises 617 Bibliographical Notes 622 Chapter 14 Transactions 14.1 Transaction Concept 627 14.2 A Simple ...
12. Materialized Views .................................................... 155 Materialized View Principles 156 A View to Materialize 157 Getting into Form 158 The Target Table 160 Refresh and ...
Introduction . . . . . . . . . ....1.1 Distributed Data Processing .... ....1.3 Data Delivery Alternatives ....1.4 Promises of DDBSs ....1.4.2 Reliability Through Distributed Transactions ....1.4.3 Improved Performance...
This doc describes a new extensible query optimization framework that ... (ii) operators that are both logical and physical for predicates etc., (iii) schema-specific rules for materialized views,