For a standard SQL view,
the results are computed each time the view is referenced in a subsequent
SQL statement. For a materialized view, the results of the view statement
are computed and saved in a temporary server table when the view is
created. As long as the input tables that the view consists of are
not changed, the materialized view returns the results from the temporary
table when the view is referenced in an SQL statement. If any of the
input tables that make up the view are modified, the materialized
view recomputes the results the next time the view is referenced and
refreshes the temporary table with the new results. The temporary
results table for a materialized view exists for as long as the view
exists. When a user deletes or drops a materialized view, the temporary
results table is deleted as well.
You must use the explicit
SQL pass-through facility to create a materialized view. Specify the keyword MATERIALIZED in the CREATE VIEW
syntax to identify the view as a materialized view. When you create a materialized
view, the CREATE VIEW operation does not complete until the temporary results table
is populated. This process can add substantial time to the execution of a CREATE VIEW
statement.
Each time you reference a materialized view in an SQL statement, a check determines
whether any of the input tables that are used to produce the temporary results table
have been modified. If none of the tables have been modified, the temporary table
is substituted in place of the view file in the SQL statement. If any of the input
tables have been modified, the SQL statement executes and uses the changed tables.
The statement functions like a standard SQL view reference. A background
thread is also launched. The background thread is independent of the SQL statement execution.
This thread refreshes the temporary results table. Until the refresh is completed,
any incoming references to the view are treated as standard view references.
When you create a materialized view, an additional server table is created in the
same
domain as a standard SQL view file.
You cannot view or access
the materialized view table by using PROC DATASETS or other SAS procedures.
If one or more simple indexes are defined on any of the input tables
that are used to create the results table, the indexes are also created
on the materialized view table, as long as the column that was indexed
in the input table also exists in the materialized view table.