MV Refresh Parallel PDF
MV Refresh Parallel PDF
Materialized views provide performance benefits to data warehouse applications. Some OLTP
applications also benefit from materialized views involving non-volatile data. Oracle provides
flexible ways to refresh materialized views – you can refresh them full or incremental; you can
refresh them on demand or at the commit time in the source table. When the size of the
materialized view grows, one needs to explore ways to perform the refresh faster. One of the
ways to expedite the refresh is to use parallel execution.
A FAST refresh means an incremental refresh, which indicates that the materialized view will be
refreshed based on only the data changes that have occurred in the master table(s). A
COMPLETE refresh indicates that the materialized view will be refreshed by re-executing the
query defining the materialized view.
The ON COMMIT refresh indicates that the materialized view will be whenever the data in the
master table changes. The ON DEMAND refresh indicates that the materialized view will be
refreshed on demand by explicitly executing one of the REFRESH procedures in the
DBMS_MVIEW package.
In this article, we will consider the ON DEMAND COMPLETE refresh of a materialized view.
However, the concepts discussed here will be applicable to all refresh methods. In this article,
the materialized view will be based on the following table:
DESC SALES_HISTORY
Name Null? Type
----------------------------------------- -------- ------------------
PART_ID NOT NULL VARCHAR2(50)
STORE_ID NOT NULL VARCHAR2(50)
SALE_DATE NOT NULL DATE
QUANTITY NOT NULL NUMBER(10,2)
We will use the following materialized view to illustrate various parallel refresh mechanisms.
Now that you have enabled parallel execution in the database, you can employ it while
refreshing the materialized view. In the following sections, we will discuss various ways to
invoke parallel refresh.
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES',PARALLELISM=>4);
At the outset, it appears that the PARALLELISM parameter will invoke a parallel refresh of the
materialized view. However, it doesn’t. The dynamic performance views V$PX_PROCESS and
V$PX_SESSION provide information on the parallel execution processes and the sessions
using parallel execution respectively. When the above refresh process is running, if we query
these views, we will see that there are no parallel execution processes in use.
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES',PARALLELISM=>4);
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES');
When the materialized view is created with the PARALLEL clause, the creation process is
parallelized, but the refresh process is not. Whether or not you specify the PARALLELISM
parameter in the REFRESH clause, it doesn’t matter. The refresh will be executed in serial.
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES',PARALLELISM=>4);
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES');
When the master table of the materialized view has the PARALLEL attribute set to > 1, then the
creation as well as the refresh processes will be parallelized. Whether or not you specify the
PARALLELISM parameter in the REFRESH clause, it doesn’t matter.
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES',PARALLELISM=>4);
EXECUTE DBMS_MVIEW.REFRESH(LIST=>'MV_PART_SALES');
When the materialized view is created with a PARALLEL hint, then the creation as well as the
refresh processes will be parallelized. Whether or not you specify the PARALLELISM parameter
in the REFRESH clause, it doesn’t matter.
Conclusion
In this article we discussed various ways to refresh a materialized view in parallel. The important
thing to note here is that the PARALLELISM parameter of the REFRESH procedure doesn’t
help in invoking parallel refresh of a materialized view. You can invoke parallelism while
creating a materialized view by specifying a PARALLEL clause in the create materialized view
statement, or by using a PARALLEL hint in the create materialized view statement, or by
specifying the PARALLEL attribute for the master table(s). To invoke parallelism while
refreshing a materialized view you have one less option. You can do it either by using a
PARALLEL hint in the create materialized view statement, or by specifying the PARALLEL
attribute for the master table(s).
[Author Bio]
Sanjay Mishra has more than 12 years of industry experience, and has extensively worked in
the areas of database architecture, database management, performance tuning, scalability,
ETL, backup / recovery, parallel server and parallel execution. He has coauthored 3 Oracle
books published by O'Reilly & Associates (Mastering Oracle SQL, Oracle SQL Loader: The
Definitive Guide, Oracle Parallel Processing). He has published articles in the Oracle Magazine,
SELECT Journal and dbazine.com. Presently, he works as the lead database architect at Dallas
based i2 Technologies. Sanjay can be reached at [email protected].