物化视图日志问题

Materialized view logs questions

我有一个基于两个或更多其他实体化视图的实体化视图。我想为物化视图安排快速刷新,但问题是它没有任何日志,所以我必须先创建日志。我是物化视图的新手,所以我不确定如何为两个底层物化视图创建日志。我是否为这些视图使用的每个底层 table 创建一个日志?

假设您希望所有内容都可以快速刷新,您需要将 MV 登录到:

  • 基表
  • "final" 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;

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 (*) 
  from   mv1 
  join   mv2
  on     mv1.c1 = mv2.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