开发者

Strange Sql Server Query Slow

开发者 https://www.devze.com 2023-01-21 10:53 出处:网络
i have a query like this SELECT TOP 10 * FROM N开发者_运维百科EWS WHERE newsid > AAA ORDER BY newsid desc;

i have a query like this

  SELECT TOP 10 
         * 
    FROM N开发者_运维百科EWS 
   WHERE newsid > AAA 
ORDER BY newsid desc;

this query is very slow for some values of AAA

for example it is fast for 1,000,000 and 1,400,000 but it is slow for 1,355,316

I am confused!!!


My first thought is that it is doing a lot of string comparison, and that maybe in your case where there are 1,355,316 records, either the string values are long, or the table is fragmented.

Is there an index on the table?

To start reading about query optimization, read this and this.


If in Sql Server 2008 try with FORCESEEK hint. You will get predictable results.

0

精彩评论

暂无评论...
验证码 换一张
取 消