Database Reference
In-Depth Information
An indexed view can be used in two ways: when a query explicitly
references the indexed view and when the view is not referenced in a query
but the query optimizer determines that the view can be used to generate a
lower-cost query plan.
In the first case, when a query refers to a view, the definition of the view
is expanded until it refers only to base tables. This process is called view
expansion. If we do not want this to happen, we can use the NOEXPAND
hint, which forces the query optimizer to treat the view like an ordinary
table with a clustered index, preventing view expansion. The syntax is as
follows:
SELECT EmployeeKey, EmployeeName, . . .
FROM Employee, EmployeeSales WITH (NOEXPAND)
WHERE . . .
In the second case, when the view is not referenced in a query, the query
optimizer determines when an indexed view can be used in a given query
execution. Thus, existing applications can benefit from newly created indexed
views without changing those applications. Several conditions are checked to
determine if an indexed view can cover the entire query or a part of it, for
example, (a) the tables in the FROM clause of the query must be a superset
of the tables in the FROM clause of the indexed view; (b) the join conditions
in the query must be a superset of the join conditions in the view; and (c)
the aggregate columns in the query must be derivable from a subset of the
aggregate columns in the view.
7.8.2 Partition-Aligned Indexed Views
If a partitioned table is created in SQL Server and indexed views are built
on this table, SQL Server automatically partitions the indexed view by using
the same partition scheme as the table. An indexed view built in this way
is called a partition-aligned indexed view. The main feature of such a view
is that the database query processor automatically maintains it when a new
partition of the table is created, without the need of dropping and recreating
the view. This improves the manageability of indexed views.
We show next how we can create a partition-aligned indexed view on the
Sales fact table of the Northwind data warehouse. To facilitate maintenance
and for eciency reasons, we decide to partition this fact table by year. This
is done as follows.
To create a partition scheme, we need first to define the partition function.
We want to define a scheme that partitions the table by year, from 1996
through 1998. The partition function is called PartByYear and takes as input
Search WWH ::




Custom Search