gpt4 book ai didi

sql - 提交时刷新物化 View

转载 作者:行者123 更新时间:2023-12-04 15:26:58 26 4
gpt4 key购买 nike

假设我有一张 table TABLE两列 COL_1COL_2 .

我有一个物化 View ,它只是读取 TABLE.COL_1 ,并设置为:REFRESH FAST ON COMMIT .

如果我更新 TABLE.COL_2 ,物化 View 刷新了吗?

最佳答案

是的,更新 COL_2 似乎也会刷新 View 。

与没有物化 View 的类似表上的类似更新相比,更新 COL_2 使用更多的资源。并且更新 COL_2 将更新物化 View 的行时间戳 (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

关于sql - 提交时刷新物化 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5199333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com