Performance of SQL Server 2005 Query

前端 未结 3 2024
余生分开走
余生分开走 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:57

    Add OPTION (RECOMPILE) to the end of the query.

    SQL Server doesn't "sniff" the values of the variables so you will be getting a plan based on guessed statistics rather than one tailored for the actual variable values.

提交回复
热议问题