[英]SQL Server : Multiple Where Clauses
Suppose I have a T-SQL command with multiple WHERE
conditions like this: 假设我有一个包含多个
WHERE
条件的T-SQL命令,如下所示:
SELECT *
FROM TableName
WHERE Column1 NOT LIKE '%exclude%'
AND Column2 > 10
Would the query exclude a row as soon as Column1
was not met or would it still go on to test the next condition for Column2
? 如果未满足
Column1
,查询是否会排除一行,还是会继续测试Column2
的下一个条件?
I am asking because I want to see if it would be more efficient to swap my conditions around to first test if Column2 > 10
before I run a more time-consuming condition. 我问,因为我想看看在我运行一个更耗时的条件之前交换我的条件是否更有效率首先测试
Column2 > 10
。
Edit: If it matters, Column1
is of type bigint
and Column2
is of type ntext
编辑:如果重要,
Column1
的类型为bigint
, Column2
的类型为ntext
Sql will devise a query plan based on available indexes and statistics. Sql将根据可用的索引和统计信息设计查询计划。 Sql doesn't necessarily have "short-circuit" expression evaluation per se because it is a procedural language but ultimately the query plan will perform short-circuit evaluation.
Sql本身不一定具有“短路”表达式评估,因为它是一种过程语言,但最终查询计划将执行短路评估。
Swapping the expressions should not affect performance. 交换表达式不应影响性能。
As Marc said, swapping columns in where clause will not make any change in performance. 正如Marc所说,在where子句中交换列不会对性能产生任何影响。 Instead, you could look for changing the data type NTEXT into nvarchar(X) where x represents some meaningful data length.
相反,您可以寻找将数据类型NTEXT更改为nvarchar(X),其中x表示一些有意义的数据长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.