Sql Server predicates lazy?

后端 未结 4 1864
南旧
南旧 2021-01-17 21:01

I have a query:

SELECT 
    someFields 
FROM 
    someTable 
WHERE 
    cheapLookup=1 
    AND (CAST(someField as FLOAT)/otherField)<0.9

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 21:35

    It depends on how SQL Server optimizes the query, you could run the Query Analyzer to see for your particular case

    A sure fire way to optimize would to say

        WITH QueryResult AS (
        SELECT 
            someFields 
        FROM 
            someTable 
        WHERE 
            cheapLookup=1 
        )
    
    SELECT * FROM QueryResult WHERE (CAST(someField as FLOAT)/otherField)<0.9
    

提交回复
热议问题