Databases Reference
In-Depth Information
Alternatively, you can use the
EXPAND
VIEWS
hint, as in the following query, to avoid
matching the index view. You will get the plan seen in Figure 7-18.
SELECT
SalesOrderID
,
COUNT
(*)
FROM
Sales
.
SalesOrderDetail
GROUP
BY
SalesOrderID
OPTION
(
EXPAND
VIEWS
)
Listing 7-29.
Figure 7-18:
Plan using the
EXPAND VIEWS
hint.
Finally, drop the indexed view you just have created:
DROP
VIEW
v_test
Listing 7-30.
Plan Guides
There might be situations when you need to apply a hint to a query, but you are unable
or unwilling to change your query code or your application. As mentioned earlier, a
common situation where this occurs is if you are working with third-party code or
applications, which you cannot change.