[英]Order of operation Inner Join and Where clause performance in SQL Server?
[英]SQL join performance operation order
我正在尝试提出如何订购连接查询以提高其性能。
假设我们有两个要加入的表,必须对其应用一些过滤器。
是不是也一样:
table1_result = select * from table1 where field1 = 'A';
table2_result = select * from table2 where field1 = 'A';
result = select * from table1 as one inner join table2 as two on one.field1 = two.field1;
这样做:
result = select * from table1 as one inner join table2 as two on one.field1 = two.field1
where one.field1 = 'A' and two.field1 = 'A';
甚至这样做:
result = select * from table1 as one inner join table2 as two on one.field1 = two.field1 and one.field1 = 'A';
太感谢了!!
一些用于改进查询的常见优化技术如下:
foreign keys
,则Index
连接中使用的列,通常像MySql
这样的数据库已经索引它们。Index
conditions
或WHERE
子句中使用的columns
。*
并明确 select 您真正需要的列。DB-Engines
足够智能来决定这一点。所以最好分析你的两个连接表的结构,有索引。
如果有人更感兴趣,改变conditions
顺序如何有助于获得更好的性能。 我在这里有一个详细的答案mysql 慢查询问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.