WHERE Clause vs ON when using JOIN(使用 JOIN 时的 WHERE 子句与 ON)
问题描述
假设我有以下 T-SQL 代码:
Assuming that I have the following T-SQL code:
SELECT * FROM Foo f
INNER JOIN Bar b ON b.BarId = f.BarId;
WHERE b.IsApproved = 1;
下面的也返回相同的一组行:
The following one also returns the same set of rows:
SELECT * FROM Foo f
INNER JOIN Bar b ON (b.IsApproved = 1) AND (b.BarId = f.BarId);
这可能不是最好的例子,但这两者之间有什么性能差异吗?
This might not be the best case sample here but is there any performance difference between these two?
推荐答案
不,查询优化器足够聪明,可以为两个示例选择相同的执行计划.
No, the query optimizer is smart enough to choose the same execution plan for both examples.
您可以使用SHOWPLAN
来检查执行计划.
You can use SHOWPLAN
to check the execution plan.
尽管如此,您应该将所有连接连接放在 ON
子句上,并将所有限制放在 WHERE
子句上.
Nevertheless, you should put all join connection on the ON
clause and all the restrictions on the WHERE
clause.
这篇关于使用 JOIN 时的 WHERE 子句与 ON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 JOIN 时的 WHERE 子句与 ON


- 更改自动增量起始编号? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01