SQL Statement - How can Improve speed with indexing

后端 未结 4 1871
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 05:01

I have a script that has to look throught over 2.5 million records to find if a member that has an unread email. I want to know what can be done to improve its speed. Curr

4条回答
  •  离开以前
    2021-01-15 05:30

    Looks like a good candidate for a filtered index.

    A filtered index is an optimized nonclustered index, especially suited to cover queries that select from a well-defined subset of data. It uses a filter predicate to index a portion of rows in the table. A well-designed filtered index can improve query performance, reduce index maintenance costs, and reduce index storage costs compared with full-table indexes.

    Something along these lines:

    CREATE NONCLUSTERED INDEX IX_MemberMail_ToMemberId_Unread
    ON dbo.MemberMail (ToMemberId ASC)
    WHERE ToReadFlag = 0
    AND ToDeletedFlag = 0
    AND FromDeletedFlag = 0
    AND OnHold = 0
    AND ToArchivedFlag = 0;
    

提交回复
热议问题