首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >物化视图日志问题

物化视图日志问题
EN

Stack Overflow用户
提问于 2020-01-03 21:45:57
回答 1查看 1K关注 0票数 1

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-06 11:31:20

假设您希望所有内容都可以快速刷新,则需要MV日志:

  • 基表
  • MVs作为“最终”MV

的基础

在MV上创建MV日志的方式与常规表相同:

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59585716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档