1

t1让我们假设我们在and之间有一个连接t2,如下所示:

select c1, ..., cn
from t1 join t2
on t1.fk = t2.k
join t3
on t2.fk = t3.k
where (some condition independent from t3)

哪里(some condition independent from t3)可能有任何东西。现在,考虑这个查询:

select c1, ..., cn
from t1 join t2
on t1.fk = t2.k and (some condition independent from t3)
join t3
on t2.fk = t3.k

让我们假设t1x t2xt3join条件一起产生 count1 行,而如果我们也按where条件过滤,那么我们将有 count2 个记录,其中 count2 <= count1。

我想知道where条件是针对所有 count1 行执行,还是仅针对 count2 行的子集执行?尽快将条件包含在 on 条件中而不是在查询末尾附加它们在性能方面更好吗?

4

1 回答 1

0

没什么区别。查看实际的执行计划。你会看到他们是平等的。

在 SQL Server Management Studio 中:查询 -> 包括实际执行计划

于 2016-08-06T14:03:38.777 回答