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

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

    If the campaignid_int column is not indexed, add an index to it. That should speed up the query. Right now I presume that you need to do a full table scan to find the matches for campaignid_int = 3835 before the top(1) row is returned (filtering occurs before results are returned).

    EDIT: An index is already in place, but since SQL Server does a clustered index scan, the optimizer has ignored the index. This is probably due to (many) duplicate rows with the same campaignid_int value. You should consider indexing differently or query on a different column to get the connectionid you want.

提交回复
热议问题