Why is doing a top(1) on an indexed column in SQL Server slow?

后端 未结 8 1790
离开以前
离开以前 2021-01-03 22:13

I\'m puzzled by the following. I have a DB with around 10 million rows, and (among other indices) on 1 column (campaignid_int) is an index.

Now I have 700k rows wher

8条回答
  •  不知归路
    2021-01-03 22:46

    Due to the statistics, you should explicitly ask the optimizer to use the index you've created instead of the clustered one.

    SELECT  TOP (1) connectionid
    FROM    outgoing_messages WITH (NOLOCK, index(idx_connectionid))
    WHERE  (campaignid_int = 3835)
    

    I hope it will solve the issue.

    Regards, Enrique

提交回复
热议问题