『ORACLE』快速重新整理物化檢視的方法(11g)
阿新 • • 發佈:2019-01-07
1、on demand:使用DBMS_MVIEW包中的儲存過程啟用手工重新整理(預設設定)
refresh [fast|complete|force] 檢視重新整理的方式: complete:全部重新整理。相當於重新執行一次建立檢視的查詢語句。 fast: 增量重新整理.假設前一次重新整理的時間為t1,那麼使用fast模式重新整理物化檢視時,只向檢視中新增t1到當前時間段內,主表變化過的資料.為了記錄這種變化,建立增量重新整理物化檢視還需要一個物化檢視日誌表。create materialized view log on (主表名)。(多張表時,此語句也生效,建立後,原來的表中會多出兩類視圖表:MLOG$_table_name和RUPD$_table_name)2、on commit:在事務提交後重新整理
使用情況
⑴僅用於快速重新整理的物化檢視
⑵需要on commit refresh物件許可權
⑶如果重新整理失敗需要進行手工重新整理
3、never:禁止物化檢視重新整理
在計劃時間進行重新整理:使用start with 和next選項。從指定的時間開始,每隔一段時間(由next指定)就重新整理一次;
比如說我們要全重新整理一張mv_test物化檢視: begindbms_mview.refresh(TAB=>'MV_TEST',
METHOD=>'COMPLETE',
PARALLELISM=>8);
end;
/ 增量重新整理就不需要使用什麼並行了,通常情況下,是沒有那個必要的。 begin
dbms_mview.refresh(TAB=>'MV_TEST',
METHOD=>'FAST',
PARALLELISM=>1);
end;
/ 或者,也可以這樣執行: exec dbms_mview.refresh('MV_TEST','F');
create matherialized view emp_data
pctfree 5
tablespace example
storage (initial 50K next 50K)
refresh fast next sysdate + 7
as select ...;
create matherialized view emp_data
pctfree 5
tablespace example
using index storage (initial 25K next 25K)
refresh start with round(sysdate + 1) + 11/24
next next_day(trunc(sysdate),'MONDAY') + 15/24
as select * from [email protected] union
select * from [email protected];