如果第一个条件为 FALSE,则在 SQL Server 中检查第二个条件?

2021-09-24 00:00:00 where-clause sql-server

where 子句中,如果第一个条件为 FALSE,那么在 SQL Server 中检查第二个条件?

In a where clause, if the first condition is FALSE, then the second condition is checked in SQL Server?

例如

select * 
from users
where (condition 1) AND (condition 2)

如果条件 1 为 False,是否会检查条件 2?

If condition 1 is False, will condition 2 be checked?

推荐答案

它是不确定的.您不能依赖评估顺序.

It is non-deterministic. You cannot rely on order of evaluation.

SQL Server 查询优化器负责解析 T-SQL 查询并根据表大小、索引等创建执行计划.因此,针对相同数据库架构的相同 T-SQL 语句可能会根据数据库内容、配置等执行不同的操作.

SQL Server query optimizer is responsible for parsing T-SQL query and creating execution plan based on table sizes, indexes, etc. So same T-SQL statement against same database schema might be executed differently depending on database content, configuration, etc.

查询优化器优先考虑执行速度,并能够并行执行单个 T-SQL 语句.过滤子句的执行最终一个接一个执行的可能性很小.

Query optimizer prioritizes speed of execution and is able to parallelise execution of a single T-SQL statement. It is highly unlikely that execution of filter clauses ends up being executed one after another.

相关文章