Rowids of all the tables in the FROM list must appear in the SELECT list of the query.
Materialized view logs must exist with rowids for all the base tables in the FROM list of the query.
You cannot create a fast refreshable materialized view from multiple tables with simple joins that include an object type column in the SELECT statement.
Also, the refresh method you choose will not be optimally efficient if:
The defining query uses an outer join that behaves like an inner join. If the defining query contains such a join, consider rewriting the defining query to contain an inner join.
The SELECT list of the materialized view contains expressions on columns from multiple tables.
5.3.8.6 Restrictions on Fast Refresh on Materialized Views with Aggregates
Defining queries for materialized views with aggregates or joins have the following restrictions on fast refresh:
Fast refresh is supported for both ONCOMMIT and ONDEMAND materialized views, however the following restrictions apply:
All tables in the materialized view must have materialized view logs, and the materialized view logs must:
Contain all columns from the table referenced in the materialized view.
Specify with ROWID and INCLUDINGNEWVALUES.
Specify the SEQUENCE clause if the table is expected to have a mix of inserts/direct-loads, deletes, and updates.
Only SUM, COUNT, AVG, STDDEV, VARIANCE, MIN and MAX are supported for fast refresh.
COUNT(*) must be specified.
Aggregate functions must occur only as the outermost part of the expression. That is, aggregates such as AVG(AVG(x)) or AVG(x)+ AVG(x) are not allowed.
For each aggregate such as AVG(expr), the corresponding COUNT(expr) must be present. Oracle recommends that SUM(expr) be specified.
If VARIANCE(expr) or STDDEV(expr) is specified, COUNT(expr) and SUM(expr) must be specified. Oracle recommends that SUM(expr *expr) be specified.
The SELECT column in the defining query cannot be a complex expression with columns from multiple base tables. A possible workaround to this is to use a nested materialized view.
The SELECT list must contain all GROUPBY columns.
The materialized view is not based on one or more remote tables.
If you use a CHAR data type in the filter columns of a materialized view log, the character sets of the master site and the materialized view must be the same.
If the materialized view has one of the following, then fast refresh is supported only on conventional DML inserts and direct loads.
Materialized views with MIN or MAX aggregates
Materialized views which have SUM(expr) but no COUNT(expr)
Materialized views without COUNT(*)
Such a materialized view is called an insert-only materialized view.
A materialized view with MAX or MIN is fast refreshable after delete or mixed DML statements if it does not have a WHERE clause.
The max/min fast refresh after delete or mixed DML does not have the same behavior as the insert-only case. It deletes and recomputes the max/min values for the affected groups. You need to be aware of its performance impact.
Materialized views with named views or subqueries in the FROM clause can be fast refreshed provided the views can be completely merged. For information on which views will merge, see Oracle Database SQL Language Reference.
If there are no outer joins, you may have arbitrary selections and joins in the WHERE clause.
Materialized aggregate views with outer joins are fast refreshable after conventional DML and direct loads, provided only the outer table has been modified. Also, unique constraints must exist on the join columns of the inner join table. If there are outer joins, all the joins must be connected by ANDs and must use the equality (=) operator.
For materialized views with CUBE, ROLLUP, grouping sets, or concatenation of them, the following restrictions apply:
The SELECT list should contain grouping distinguisher that can either be a GROUPING_ID function on all GROUPBY expressions or GROUPING functions one for each GROUPBY expression. For example, if the GROUPBY clause of the materialized view is «GROUPBYCUBE(a, b)«, then the SELECT list should contain either «GROUPING_ID(a, b)» or «GROUPING(a)ANDGROUPING(b)» for the materialized view to be fast refreshable.
GROUPBY should not result in any duplicate groupings. For example, «GROUP BY a, ROLLUP(a, b)» is not fast refreshable because it results in duplicate groupings «(a), (a, b), AND (a)«.
5.3.8.7 Restrictions on Fast Refresh on Materialized Views with UNION ALL
Materialized views with the UNIONALL set operator support the REFRESHFAST option if the following conditions are satisfied:
The defining query must have the UNIONALL operator at the top level.
The UNIONALL operator cannot be embedded inside a subquery, with one exception: The UNIONALL can be in a subquery in the FROM clause provided the defining query is of the form SELECT * FROM (view or subquery with UNIONALL) as in the following example:
CREATE VIEW view_with_unionall AS
(SELECT c.rowid crid, c.cust_id, 2 umarker
FROM customers c WHERE c.cust_last_name = 'Smith'
UNION ALL
SELECT c.rowid crid, c.cust_id, 3 umarker
FROM customers c WHERE c.cust_last_name = 'Jones');
CREATE MATERIALIZED VIEW unionall_inside_view_mv
REFRESH FAST ON DEMAND AS
SELECT * FROM view_with_unionall;
Note that the view view_with_unionall satisfies the requirements for fast refresh.
Each query block in the UNIONALL query must satisfy the requirements of a fast refreshable materialized view with aggregates or a fast refreshable materialized view with joins.
The appropriate materialized view logs must be created on the tables as required for the corresponding type of fast refreshable materialized view.
Note that the Oracle Database also allows the special case of a single table materialized view with joins only provided the ROWID column has been included in the SELECT list and in the materialized view log. This is shown in the defining query of the view view_with_unionall.
The SELECT list of each query must include a UNIONALL marker, and the UNIONALL column must have a distinct constant numeric or string value in each UNIONALL branch. Further, the marker column must appear in the same ordinal position in the SELECT list of each query block. See «UNION ALL Marker and Query Rewrite» for more information regarding UNIONALL markers.
Some features such as outer joins, insert-only aggregate materialized view queries and remote tables are not supported for materialized views with UNIONALL. Note, however, that materialized views used in replication, which do not contain joins or aggregates, can be fast refreshed when UNIONALL or remote tables are used.
The compatibility initialization parameter must be set to 9.2.0 or higher to create a fast refreshable materialized view with UNIONALL.
In addition to the SET options and deterministic function requirements, the following requirements must be met:
The user that executes CREATE INDEX must be the owner of the view.
When you create the index, the IGNORE_DUP_KEY option must be set to OFF (the default setting).
Tables must be referenced by two-part names, schema.tablename in the view definition.
User-defined functions referenced in the view must be created by using the WITH SCHEMABINDING option.
Any user-defined functions referenced in the view must be referenced by two-part names, <schema>.<function>.
The data access property of a user-defined function must be NO SQL, and external access property must be NO.
Common language runtime (CLR) functions can appear in the select list of the view, but cannot be part of the definition of the clustered index key. CLR functions cannot appear in the WHERE clause of the view or the ON clause of a JOIN operation in the view.
CLR functions and methods of CLR user-defined types used in the view definition must have the properties set as shown in the following table.
Property
Note
DETERMINISTIC = TRUE
Must be declared explicitly as an attribute of the Microsoft .NET Framework method.
PRECISE = TRUE
Must be declared explicitly as an attribute of the .NET Framework method.
DATA ACCESS = NO SQL
Determined by setting DataAccess attribute to DataAccessKind.None and SystemDataAccess attribute to SystemDataAccessKind.None.
EXTERNAL ACCESS = NO
This property defaults to NO for CLR routines.
The view must be created by using the WITH SCHEMABINDING option.
The view must reference only base tables that are in the same database as the view. The view cannot reference other views.
The SELECT statement in the view definition must not contain the following Transact-SQL elements:
COUNT
ROWSET functions (OPENDATASOURCE, OPENQUERY, OPENROWSET, AND OPENXML) OUTER joins (LEFT, RIGHT, or FULL)
Derived table (defined by specifying a SELECT statement in the FROM clause)
Self-joins
Specifying columns by using SELECT * or SELECT <table_name>.*
DISTINCT STDEV, STDEVP, VAR, VARP, or AVG
Common table expression (CTE)
float1, text, ntext, image, XML, or filestream columns
Subquery OVER clause, which includes ranking or aggregate window functions
Full-text predicates (CONTAINS, FREETEXT) SUM function that references a nullable expression ORDER BY
CLR user-defined aggregate function TOP CUBE, ROLLUP, or GROUPING SETS operators
MIN, MAX UNION, EXCEPT, or INTERSECT operators TABLESAMPLE
Table variables OUTER APPLY or CROSS APPLY PIVOT, UNPIVOT
1 The indexed view can contain float columns; however, such columns cannot be included in the clustered index key.
If GROUP BY is present, the VIEW definition must contain COUNT_BIG(*) and must not contain HAVING. These GROUP BY restrictions are applicable only to the indexed view definition. A query can use an indexed view in its execution plan even if it does not satisfy these GROUP BY restrictions.
If the view definition contains a GROUP BY clause, the key of the unique clustered index can reference only the columns specified in the GROUP BY clause.