Mat View Logs

Was passiert mit Mat View Logs wenn man nachträglich die Bedingung in der Mat View ändert?


------------------------------- auf T:

drop table tmp_ue
/

create table tmp_ue as select * from air_land
/

select * from tmp_ue
where sld_code < 'T'
/

ALTER TABLE tmp_ue
ADD CONSTRAINT pk_tmp_ue PRIMARY KEY (sld_code)
USING INDEX
/

create materialized view log on tmp_ue
/

------------------------------- auf P:

create table tmp_ue_tcdp570 as
select * from tmp_ue@tcum
where 1=2
/

create materialized view tmp_ue_tcdp570
on prebuilt table
using index
  tablespace  DATAPOOL_I
refresh on demand
  with primary key
as
select * from tmp_ue@tcum
where sld_code < 'T'
/

select * from tmp_ue_tcdp570
/

begin
  dbms_mview.refresh('TMP_UE_TCDP570', 'c');
end;
/

select * from tmp_ue_tcdp570
/

-- Jetzt haben wir unsere Ausgangsbedingungen.

-- Wir wollen jetzt die Bedingung der MV ändern

------------------------------- auf T:

-- Wir wollen jetzt die Bedingung der MV ändern

-- aber inzwischen steht schon was im Log:

update tmp_ue set sld_name = 'EAST TIMOR....' where sld_code = 'TL'
/

update tmp_ue set sld_name = 'SENEGAL....' where sld_code = 'SN'
/

update tmp_ue set sld_name = 'MALI....' where sld_code = 'ML'
/

commit
/

select * from MLOG$_tmp_ue
/
------------------------------- auf P:

-- Jetzt gucken wir erstmal, ob das Refresh funktioniert:

begin
  dbms_mview.refresh('TMP_UE_TCDP570', 'f');
end;
/

select * from tmp_ue_tcdp570
/

-- prima.

------------------------------- auf T:

-- Jetzt wollten wir wie gesagt eine andere Bedingung für die MV.

-- Das Log ist jetzt leer, daher nochmal was ändern:

select * from MLOG$_tmp_ue
/

update tmp_ue set sld_name = 'EAST TIMOR.... ....' where sld_code = 'TL'
/

update tmp_ue set sld_name = 'SENEGAL.... ....' where sld_code = 'SN'
/

update tmp_ue set sld_name = 'MALI.... ....' where sld_code = 'ML'
/

commit
/

select * from MLOG$_tmp_ue
/

------------------------------- auf P:

-- Bedingung für die MV ändern:

drop materialized view tmp_ue_tcdp570
/

create materialized view tmp_ue_tcdp570
on prebuilt table
using index
  tablespace  DATAPOOL_I
refresh on demand
  with primary key
as
select * from tmp_ue@tcum
where sld_code < 'N'
/

select * from tmp_ue_tcdp570
/

-- Durch das neu-Anlegen der MV wurden die Logs geleert:
select * from MLOG$_tmp_ue@tcum
/

-- Tabelle muss nochmal befüllt werden:
begin
  dbms_mview.refresh('TMP_UE_TCDP570', 'c');
end;
/

select * from tmp_ue_tcdp570
/

select * from MLOG$_tmp_ue@tcum
/

------------------------------- auf T:

-- Jetzt finden munter weiter Änderungen statt:

select * from MLOG$_tmp_ue
/

update tmp_ue set sld_name = 'EAST TIMOR.... .... ....' where sld_code = 'TL'
/

update tmp_ue set sld_name = 'SENEGAL.... .... ....' where sld_code = 'SN'
/

update tmp_ue set sld_name = 'MALI.... .... ....' where sld_code = 'ML'
/

commit
/

select * from MLOG$_tmp_ue
/

------------------------------- auf P:

select * from MLOG$_tmp_ue@tcum
/

-- fast refresh:
begin
  dbms_mview.refresh('TMP_UE_TCDP570', 'f');
end;
/

-- Die Änderungen sind zu sehen
select * from tmp_ue_tcdp570
/

-- Und die Logs sind komplett geleert, auch die Datensätze die gar nicht unserer Bedingung entsprechen sind weg.
select * from MLOG$_tmp_ue@tcum
/



drop materialized view TMP_UE_TCDP570
/

drop table TMP_UE_TCDP570
/

------------------------------- auf T:

drop table TMP_UE
/


No comments:

Post a Comment