問題描述
在 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.
這篇關于如果第一個條件為 FALSE,則在 SQL Server 中檢查第二個條件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!