Why do multiple WHERE conditions slow query rather than speed it up?

前端 未结 8 1084
轮回少年
轮回少年 2021-02-04 04:35

The problem is that the query in question runs very slow when compared to the query run with one or two, rather than all three of its conditions.

Now the query.

8条回答
  •  天命终不由人
    2021-02-04 05:18

    • String operation such as FreeText are expensive
    • The ZipCodesForRadius function can be expensive too depending of how it is coded and if the necessary indexes are present or not

    If ordering the WHERE clauses do not speed things up, having a select around your select may do the trick (It sped things up on some occasions with DB2/400, not sure about how SqlServer optimizes):

    Select Count(*)
    From
    (
        Select [Description]
        From 
            SearchTable 
        Where 
            [Date] >= '8/1/2009' 
            AND 
            [Zip] In (Select ZipCode from dbo.ZipCodesForRadius('30348', 150))
    
    ) as t1
    Where FreeText([Description], 'keyword list here')  
    

提交回复
热议问题