Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to partially refresh a materialized view in Oracle?

I have a very complex Oracle view based on other materialized views, regular views as well as some tables (I can't "fast refresh" it). Most of the time, existing records in this view are based on a date and are "stable", with new record sets having new dates.

Occasionally, I receive back-dates. I know what those are and how to deal with them if I were maintaining a table, but I would like to keep this a "view". A complete refresh would take around 30 minutes, but it only takes 25 seconds for any given date.

Can I specify that only a portion of a materialized view should be updated (i.e. the affected dates)?

Do I have to scrap the view and use a table and a procedure to populate or refresh a given date in that table?

like image 588
Galghamon Avatar asked Nov 23 '09 14:11

Galghamon


People also ask

Can you partition materialized view?

Materialized views on partitioned tables can be partitioned. Partitioning a materialized view is similar to partitioning a normal table, in that it provides benefit when queries often access a subset of the partitions.

Can you update data in a materialized view in Oracle?

A fast refresh will only insert/update/delete changed data into the materialized view. A complete refresh will empty the materialized view and then copy over all rows. The "on commit" means the materialized view will be refreshed whenever a change is committed in the master table.

What are the types of refresh in materialized view?

Materialized views can be refreshed in two ways: fast or complete.

Can we refresh materialized view on timely basis?

Unlike indexes, materialized views are not automatically updated with every data change. They must explicitly be refreshed, either on every commit, on a periodically time schedule or – typically in data warehouses – at the end of an ETL job.


2 Answers

Partition by date as in answer 3 (skaffman).

You could just do the refresh of a normal mv(table_refreshed below) and than use the exchange keyword i.e.

ALTER TABLE all_partitions
  EXCHANGE PARTITION to_calculate
  WITH TABLE table_refreshed
  WITHOUT VALIDATION
  UPDATE GLOBAL INDEXES;
like image 105
Conrad Avatar answered Oct 19 '22 09:10

Conrad


After more reading and judging by the lack of answers to this question, I come come to the conclusion that it is not possible to refresh a single partition of a materialized view.

If you can give a syntax example that proves otherwise, I will happily mark your answer the accepted one.

To others who might find this questions useful in the future: you might also want to know that in Oracle 10g, refreshing a partition (or any mview) will cause Oracle to issue DELETE, followed by INSERT.

If this is giving you performance problems (like me), there is an option to use atomic_refresh => false, which will TRUNCATE, then INSERT /*+APPEND*/.

like image 37
Galghamon Avatar answered Oct 19 '22 10:10

Galghamon