행위

오라클 mv

DB CAFE

Dbcafe (토론 | 기여)님의 2019년 12월 19일 (목) 12:39 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
thumb_up 추천메뉴 바로가기


오라클 M/V 생성[편집]

-- 테이블 생성 
create table t (x not null primary key, y not null) as
  select rownum x, mod(rownum, 10) y from dual connect by level <= 1000;

-- M/V 생성 
create materialized view log on t with rowid (x, y) including new values;

create materialized view mv
refresh fast on demand
enable on query computation
enable query rewrite
as
  select y , count(*) c1
  from t
  group by y;

-- 테이블 입력 
insert into t
  select 1000+rownum, 1 from dual connect by level <= 100;

commit;

-- M/V rewrite 
select /*+ rewrite */y , count(*) from t
group by y;

-- M/V reflash 수동
select /*+ fresh_mv */* from mv;  

-- M/V 실시간 반영 
alter materialized view mv enable on query computation;