参见英文答案 >
Is a join optimized to a where clause at runtime?4个
查看Kalen Delaney在第13页上的“sql Server 2008 Internals”1,它说明了以下内容:
查看Kalen Delaney在第13页上的“sql Server 2008 Internals”1,它说明了以下内容:
“The first step in producing such a plan is to normalize each query,which potentially breaks down a single query into multiple,fine-grained queries. After the Query Optimizer normalizes a query,it optimizes it,which means that it determines a plan for executing that query.”
另一位DBA向我建议,可以通过将WHERE子句谓词移入FROM子句来改进某些查询的性能,这样:
SELECT * FROM dbo.table1 t1 INNER JOIN dbo.table3 t3 ON t1.ID = t3.ID LEFT OUTER JOIN dbo.table2 t2 ON t1.ID = t2.ID WHERE t1.CreateDate >= '2015-07-31 00:00:00';
会成为:
SELECT * FROM dbo.table1 t1 INNER JOIN dbo.table3 t3 ON t1.ID = t3.ID AND t1.CreateDate >= '2015-07-31 00:00:00' LEFT OUTER JOIN dbo.table2 t2 ON t1.ID = t2.ID;
显然,第一个示例的含义是查询优化器将首先执行JOIN,然后应用WHERE子句,对于具有大型表的复杂查询,该子句的执行效果不如我们手动将查询重新写入表中所示的表单.第二个例子.显然这仅适用于外连接,即如果这是一个内连接,则规范化器实际上会将WHERE谓词移动到FROM子句中.
有人可以证实这种行为吗?在某处我可以看一些文档吗?我能在执行计划中看到这个吗?
1 – 是的,我知道这很古老.