How can i speed up this Indexed View?

后端 未结 7 1872
难免孤独
难免孤独 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:12

    For some data access layers, such as EF Core it's difficult to add NOEXPAND - so instead you can create an additional view (not schema bound) and add it there. You can call it what you want, but I like to explicitly put NOEXPAND in the name as a reminder.

    CREATE VIEW [dbo].[DailySummary_NOEXPAND]
    AS
    SELECT Col1, Col2, Col3 FROM [dbo].[DailySummary] WITH (NOEXPAND)
    END
    

    Also tested on Azure SQL (standard tier)

    Important: You can use SELECT * but if the underlying view changes then the column indexes can get out of sync and you can actually get wrong data back. Much safer to specify columns by name.

提交回复
热议问题