Thanks for the question, Gabriel.
Asked: April 15, 2014 - 6:44 pm UTC
Last updated: April 17, 2014 - 5:32 pm UTC
Version: 11.2.0.4
Viewed 10K+ times! This question is
You Asked
Hello Mr. Kyte,
Can you please explain to me how can I use materialized views to replicate a subset of the data of a table based on the comparison of the date found in a column with the current time.
The logical query would be of type
where date_column < sysdate - 7;
I was able to create a writeable materialized view that contained all the data from my base table. I then ran a delete on the mview, deleting all data
where date_column < sysdate - 7;
However, on the next fast refresh, instead of getting just the new and modified data, all of the data, including the one I deleted was reinserted. I always thought that mlogs would store the rowids of the modified records and move these. Of course I was wrong as explained by the documentation on writeable mviews.
So, is there a way to replicate just a subset of data from a table based on a comparison with a date that is not in the same table?
Thank you very much,
and Tom said...
the goal, the sole goal, of a materialized view is to synchronize the materialized view with the defining table(s).
when you refresh a writeable materialized view, the data - by definition - will be whatever is in the defining table(s).
If you use sysdate, you cannot fast refresh - your refresh was a complete refresh. Read only materialized views cannot fast refresh with sysdate either.
You would have to use a complete refresh of this particular materialized view - or go to a more sophisticated method, such as golden gate, where you would stream over the modifications and periodically delete the old data. A changes only materialized view is not going to work here.
think about for a minute...
In order for "create materialized view mv refresh fast as select * from t where date_column > sysdate-7" to work - we'd have to put a "delete" record into the materialized view log every time sysdate advanced by one second and a new record(s) was to be deleted.
If the materialized view log were to be used, we would need to know
a) NEW records
b) MODIFIED records
(so far, so good)
c) records to be deleted.... we can get the records that were really deleted, but how would you suggest to record all of the records that need to be deleted based on the "date_column > sysdate-7" constraint? every second, we'd have to poll the table to find any records that would need to be deleted!!
Rating
(1 rating)
Is this answer out of date? If it is, please let us know via a Comment