Documente Academic
Documente Profesional
Documente Cultură
Materialized views are one of the single most important SQL tuning tools and they are
a true silver bullet, allowing you to pre-join complex views and pre-compute
summaries for super-fast response time.
I've devoted over a hundred pages to SQL tuning with materialized views in my book
"Oracle Tuning: The Definitive Reference", and also see "Oracle Replication" a
deeply-technical book on creating and managing materialized views.
Also see my notes now how to identify opportunities for Materialized Views.
Materialized views were first introduced in Oracle8, and in Oracle9i MV's were
enhanced to allow very fast dynamic creation of complex objects. Materialized views
allow sub-second response times by pre-computing aggregate information, and
Oracle9i dynamically rewrites SQL queries to reference existing materialized views.
In this article, we continue our discussion of materialized views and discuss how to
set up and configure your Oracle database to use this powerful new feature. We begin
with a look at the initialization parameters and continue with details of the effective
management and use of materialized views.
Without materialized views you may see unnecessary repeating large-table full-table
scans, as summaries are computed, over and over:
Note that if the CURSOR_SHARING parameter is set to FORCE, some rewrites that
were text-match based in 8.1.5 may no longer be possible with 8.1.6. There are three
acceptable values for query_rewrite_integrity:
Next, you must grant several system privileges to all users who will be using the
materialized views. In many cases, the Oracle DBA will encapsulate these grant
statements into a single role and grant the role to the end users:
grant query rewrite to scott;
grant create materialized view to scott;
alter session set query_rewrite_enabled = true;
You can use the DBMS_MVIEW package to manually invoke either a fast refresh or a
complete refresh, where F equals Fast Refresh and C equals Complete Refresh:
EXECUTE DBMS_MVIEW.REFRESH('emp_dept_sum','F');
d.rowid dep_rowid
FROM emp e, dept d
WHERE e.deptno = d.deptno;
SCOTT
Conclusion
Oracle materialized views are quite complex in nature and require a significant
understanding to be used effectively. In this article, I covered the required set-up
methods and the steps for creating materialized views and appropriate refresh
intervals.