How can i speed up this Indexed View?

后端 未结 7 1876
难免孤独
难免孤独 2020-12-15 23:34

I have a simple Indexed View. When I query against it, it\'s pretty slow. First I show you the schema\'s and indexes. Then the simple queries. Finally a query plan screnie.

7条回答
  •  遥遥无期
    2020-12-16 00:22

    What edition of SQL Server? I believe that only Enterprise and Developer Edition will use indexed views automatically, while the others support it using query hints.

    SELECT a.PostId
    FROM PostsCleanSubjectView a WITH (NOEXPAND)
    WHERE a.CleanedSubject = 'Just-out-of-town' AND a.PostTypeId = 1
    

    From Query Hints (Transact SQL) on MSDN:

    The indexed view is not expanded only if the view is directly referenced in the SELECT part of the query and WITH (NOEXPAND) or WITH (NOEXPAND, INDEX( index_value [ ,...n ] ) ) is specified.

提交回复
热议问题