Let's take a look at Oracle materialized view combing

-- Materialized views can be divided into three types:

* Contains aggregated materialized views

* Contains only connected materialized views

* Nested materialized views

The constraints for fast refresh of the three materialized views are quite different, but not much in other respects.

--Build Methods for materialized views, including BUILD IMMEDIATE and BUILD DEFERRED.

* BUILD IMMEDIATE generates data when creating a materialized view,

* BUILD DEFERRED does not generate data when it is created, and generates data later as needed.

Default is BUILD IMMEDIATE.

--Materialized view query rewrite (Query Rewrite), including ENABLE QUERY REWRITE and DISABLE QUERY REWRITE.

Indicates whether the created materialized view supports query rewriting.

Query rewriting means that when querying the base table of the materialized view, Oracle will automatically determine whether the materialized view can be queried.

Graph to get the result, if possible, avoid the aggregation or join operation, and directly from the already calculated materialized view

read data in. Default is DISABLE QUERY REWRITE.

When creating a materialized view, you can specify an ORDER BY statement to save the generated data in a certain order. Do not

Passing this statement will not be written to the definition of the materialized view, and it will not be valid for subsequent refreshes.

--Refresh mode of materialized view data:

Refresh (REFRESH) only when the materialized view "needs" to be refreshed, that is, update the materialized view,

To ensure consistency with the base table data;

When the base table has COMMIT, that is, the transaction is committed, it will be refreshed immediately, and the materialized view will be updated immediately, so that the data

consistent with the base table

The difference between the two is the refresh method.

--There are four ways to refresh: FAST, COMPLETE, FORCE and NEVER.

FAST refresh uses incremental refresh, which refreshes only the modifications made since the last refresh.

COMPLETE refresh performs a complete refresh of the entire materialized view.

If the FORCE method is selected, Oracle will judge whether a fast refresh can be performed when refreshing, and if so, the FAST method is used, otherwise the COMPLETE method is used.

NEVER means that the materialized view does not perform any refresh.

 

--materialized view log

If a 'fast refresh' is required, a materialized view log needs to be established.

The materialized view log can be established as ROWID or PRIMARY KEY type according to the needs of fast refresh of different materialized views.

You can also choose whether to include SEQUENCE, INCLUDING NEW VALUES, and a list of specified columns.

The ON PREBUILD TABLE statement can be specified to create the materialized view on an existing table. In this case, materialization

View and table must have the same name. When a materialized view is dropped, a table with the same name is not dropped. Query rewrite for this materialized view requires the parameter

The number QUERY_REWRITE_INTEGERITY must be set to trusted or stale_tolerated.

--materialized view partition

Partition-based materialized views can support Partition Change Tracking (PCT). A materialized view with this property, when the base table is partitioned

After the zone maintenance operation, the fast refresh operation can still be performed. For aggregated materialized views, you can use the GROUP BY list

CUBE or ROLLUP to create aggregated materialized views of different levels.

http://www.ljhseo.com/
http://www.xyrjkf.net/
http://www.xyrjkf.cn/
http://www.xyrjkf.com.cn/
http://www.zjdygsi.cn/
http://www.zjdaiyun.cn/
http://www.jsdygsi.cn/
http://www.xyrjkf.top/
http://www.xyrjkf.com/
http://www.daiyunzj.cn/

--Manual refresh of materialized views:

Refresh the specified materialized view

execute dbms_mview.refresh('MV_TEST');

Refresh all materialized views that utilize the table

execute dbms_mview.refresh_defresh_dependent('TEST');

Refresh all materialized views in this schema that have not been refreshed since the last refresh

execute dbms_mview.refresh_all_mviews;

--Features of materialized views:

* A materialized view is in a sense a physical table (and not just a physical table);

* A materialized view is also a segment, so it has its own physical storage properties;

* Materialized views will occupy database disk space;

--Set the parameters of init.ora:

Using a materialized view:

JOB_QUEUE_PROCESSES, must be set greater than 1.

QUERY_REWRITE_ENABLED, when set to TRUE, allows dynamic query rewriting.

QUERY_REWRITE_INTEGRITY, which determines the degree to which data consistency is observed when accessing materialized views.

OPTIMIZER_MODE, must be set to some way of CBO.

Disable materialized views:

Modify the query_rewrite_enabled parameter of the init.ora parameter to false, and restart the instance.

Use alter system set query_rewrite_enabled = flase; to modify dynamically.

Use alter session set query_rewrite_enabled = flash; to modify the session.

Use norewrite prompt.

--------------------------------------------------------------------------------------

Source host: y, target host: m

1. Source table

create table y.test(id varchar2(10) primary key ,name varchar2(20));

2. Materialized view log

create:

create materialized view log on y.test [tablespace MV_DATA WITH ROWID, sequence(seq_tid)];

delete:

drop materialized view log on test;

2. Materialized view

create:

CREATE MATERIALIZED VIEW m.mv_test [tablespace mview_data]

BUILD IMMEDIATE

REFRESH FORCE

ON DEMAND -- refresh mode, the default value, can not be written

START WITH SYSDATE

NEXT SYSDATE+2/1444

WITH PRIMARY KEY

DISABLE QUERY REWRITE -- query rewrite, the default value, can not be written

AS

SELECT * FROM y.test;

delete:

drop materialized view m.mv_test;

Oracle

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324962866&siteId=291194637