Performance of SQL Server 2005 Query

前端 未结 3 2018
余生分开走
余生分开走 2020-11-30 14:35

-------------------- this takes 4 secs to execute (with 2000 000 rows) WHY?---------------------

DECLARE @AccountId INT 
DECLARE @Max INT 
DECLARE @MailingLi         


        
3条回答
  •  無奈伤痛
    2020-11-30 14:51

    The second query has to process ONLY 2000 records. Point.

    The first has to process ALL records to find the maximum.

    Top 2000 does not get you the highest 2000, it gets you the first 2000 of the result set - in any order.

    if yo uwant to change them to be identical, the second should read

    TOP 1

    and then order by anp_Subscriber.Id descending (plus fast first option).

提交回复
热议问题