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

后端 未结 8 1841
离开以前
离开以前 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:45

    This doesn't answer your question, but try using:

    SET ROWCOUNT 1
    SELECT     connectionid
     FROM         outgoing_messages WITH (NOLOCK)
     WHERE     (campaignid_int = 3835)
    

    I've seen top(x) perform very badly in certain situations as well. I'm sure it's doing a full table scan. Perhaps your index on that particular column needs to be rebuilt? The above is worth a try, however.

提交回复
热议问题