Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - What happens when refreshing a 'REFRESH FORCE ON DEMAND' view with DBMS_MVIEW.REFRESH

I have the following materialized view -

CREATE MATERIALIZED VIEW TESTRESULT 
ON PREBUILT TABLE WITH REDUCED PRECISION
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
AS 
SELECT...
FROM...
WHERE...

This materialized view has no backing MATERIALIZED VIEW LOG. As seen in the clause above this MV has "ON DEMAND" specifies, and according to Oracle documentation,

"[ON DEMAND] indicate[s] that the materialized view will be refreshed on demand by calling one of the three DBMS_MVIEW refresh procedures."

When I call DBMS_MVIEW.REFRESH('TESTRESULT') , what is occuring? Is it manually checking each record to see if it has been updated?

Oracle Version: 10g

like image 486
contactmatt Avatar asked Feb 24 '23 21:02

contactmatt


1 Answers

By default (and this default changes in different versions of Oracle), that will do a full, atomic refresh on the materialized view. That means that the data in the materialized view will be deleted, the underlying query will be re-executed, and the results will be loaded into the materialized view. You can make the refresh more efficient by passing in a value of FALSE for the ATOMIC_REFRESH parameter, i.e.

dbms_mview.refresh( 'TESTRESULT', atomic_refresh => false );

That will cause the materialized view to be truncated, the query re-executed, and the results inserted into the materialized view via a direct path insert. That will be more efficient than an atomic refresh but the materialized view will be empty during the refresh.

like image 196
Justin Cave Avatar answered Feb 26 '23 12:02

Justin Cave