Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - Materialized View still accessible during complete refresh. How does this work?

In one of our applications, we have a massive Materialized View that refreshes three times a day, and takes seven hours to refresh. (Not ideal, I know). This perplexed me, because I surely thought that users and sessions could not access this materialized view while it was being refreshed, but apparently they can!. (The type of refresh is a complete refresh)

During a complete refresh, to my understanding, the existing dataset is dropped and the query is then re-executed. If this is true, then how are users/other sessions able to access the materialized view while the materialized view is being refreshed?

like image 706
contactmatt Avatar asked Aug 09 '11 17:08

contactmatt


People also ask

Is materialized view accessible during refresh?

At the end of the refresh, the transaction is committed, and the new data is visible for all users. The advantage of this behavior is that the users can still use the materialized view while it is refreshed.

What is the difference between fast refresh and complete refresh in materialized view?

A fast refresh requires having a materialized view log on the source tables that keeps track of all changes since the last refresh, so any new refresh only has changed (updated, new, deleted) data applied to the MV. A complete refresh does what it says: it completely refreshes all data in the MV.

How long does it take to refresh a materialized view?

Automatic refresh. By default, materialized views are automatically refreshed within 5 minutes of a change to the base tables, but no more frequently than every 30 minutes.


1 Answers

There are two different ways that a complete refresh can happen-- an atomic refresh or a non-atomic refresh. An atomic refresh simply issues a DELETE to delete all the rows in the materialized view and then does an INSERT to insert the new data. This is all within a single transaction so Oracle's standard multi-version read consistency architecture lets Oracle show other sessions the old data until the refresh completes. In a non-atomic refresh, Oracle does a TRUNCATE on the materialized view and then a direct-path INSERT to insert the new data. This is substantially more efficient but since TRUNCATE is DDL, it means that the old data is not visible to other sessions during the refresh.

like image 110
Justin Cave Avatar answered Sep 20 '22 16:09

Justin Cave