Чтобы обеспечить быстрое обновление, нужны MV журналы на:
- все базовые таблицы
- все базовые MV лежащие в основе целевого MV.
Другими словами, нужно создать журналы для всех объектов в цепочке зависимостей, кроме корневого MV.
Посмотрим на самом простом примере:
create table t1 (c1 int primary key, c2 int)
/
create table t2 (c1 int, c2 int, primary key (c1, c2))
/
create materialized view log on t1
with rowid, primary key ( c2 ) including new values
/
create materialized view log on t2
with rowid, primary key including new values
/
create materialized view mv1 refresh fast on commit as
select * from t1
/
create materialized view mv2 refresh fast on commit as
select * from t2
/
Журналы на MV создаются таким же образом, как и на обычные таблицы:
create materialized view log on mv1
with rowid (c1, c2) including new values
/
create materialized view log on mv2
with rowid (c1, c2) including new values
/
create materialized view mv3 refresh fast on commit as
select mv1.c1, count (*) total
from mv1
join mv2 on mv2.c1 = mv1.c1
group by mv1.c1;
Тестовые данные и результат:
insert into t1 values (1, 1);
insert into t1 values (2, 2);
insert into t2 values (1, 1);
insert into t2 values (1, 2);
insert into t2 values (2, 2);
commit;
select * from mv3;
C1 COUNT(*)
---------- ----------
1 2
2 1
Свободный перевод ответа от участника @Chris Saxon