2011-03-04 66 views
5

假設我有一個表TABLE與兩欄COL_1COL_2物化視圖刷新致力

我有一個物化視圖,只是讀取TABLE.COL_1,並設置爲:REFRESH FAST ON COMMIT

如果我更新TABLE.COL_2,物化視圖是否會刷新?

回答

4

是的,看來更新COL_2也會刷新視圖。

更新COL_2比沒有實例化視圖的類似表上的類似更新使用更多的資源。更新COL_2將更新物化視圖的行時間戳(ORA_ROWSCN)。

------- 
--Compare the amount of work done to update. 
--The difference isn't huge, but is significant and consistent. 
------- 

--Create table and materialized view 
create table table1 (col_1 number primary key, col_2 number); 
create materialized view log on table1; 
create materialized view table1_mv refresh fast on commit 
    as select col_1 from table1; 
insert into table1 values(1, 1); 
commit; 

--Create a regular table for comparison 
create table table2 (col_1 number primary key, col_2 number); 
insert into table2 values(1, 1); 
commit; 

--Parse the queries so traces won't count that work. 
update table1 set col_1 = 2; 
update table1 set col_2 = 2; 
update table2 set col_1 = 2; 
update table2 set col_2 = 2; 
rollback; 

set autotrace on 
alter system flush buffer_cache; 
update table1 set col_1 = 2; 
--   11 db block gets 
--   8 consistent gets 
--   13 physical reads 

rollback; 
alter system flush buffer_cache; 
update table1 set col_2 = 2; 
--   6 db block gets 
--   8 consistent gets 
--   12 physical reads 

rollback; 
alter system flush buffer_cache;  
update table2 set col_1 = 2; 
--   7 db block gets 
--   7 consistent gets 
--   9 physical reads 

rollback; 
alter system flush buffer_cache; 
update table2 set col_2 = 2; 
--   3 db block gets 
--   7 consistent gets 
--   8 physical reads 

set autotrace off 


------- 
--Compare ORA_ROWSCN. 
--The times are different, implying the materialized view was modified. 
------- 

--(You may need to run these steps slowly to reproduce. ORA_ROWSCN is 
--not perfect, sometimes you'll see the same timestamp.) 
select scn_to_timestamp(ora_rowscn) from table1_mv; 
    --3/5/2011 12:25:25.000000000 AM 
update table1 set col_1 = 3; 
commit; 
select scn_to_timestamp(ora_rowscn) from table1_mv; 
    --3/5/2011 12:25:37.000000000 AM 
update table1 set col_2 = 3; 
commit; 
select scn_to_timestamp(ora_rowscn) from table1_mv; 
    --3/5/2011 12:25:46.000000000 AM 
+0

謝謝,這是相當全面的。 – Johnny5 2011-03-07 17:17:10

+0

我的猜測是物化視圖日誌確定這一點。所以如果你只在col1上創建一個物化視圖日誌,我認爲更新col2將不再有效果,對嗎? – nathanvda 2016-02-23 16:44:36