You can create an SQL
view as a materialized view. For a materialized view, the results
of the view statement are computed and saved in a temporary SPD Server
table when the view is created. For a standard SQL view, the results
are computed each time the view is referenced in a subsequent SQL
statement. 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 comprise 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 view, the temporary results
table is also deleted.
You can create a materialized
view only when you create an SQL view. You must use the SPD Server
SQL pass-through facility. The keyword Materialized in the Create
View syntax identifies 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 SPD 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.