INNER JOIN 性能是否取决于表的顺序? [英] Does INNER JOIN performance depends on order of tables?

查看:75
本文介绍了INNER JOIN 性能是否取决于表的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调整一个存储过程时突然想到一个问题.我问问吧-

A question suddenly came to my mind while I was tuning one stored procedure. Let me ask it -

我有两个表,table1 和 table2.table1 包含大量数据,table2 包含较少数据.这两个查询在性能方面有什么区别(我正在更改表的顺序)?

I have two tables, table1 and table2. table1 contains huge data and table2 contains less data. Is there performance-wise any difference between these two queries(I am changing order of the tables)?

查询 1:

SELECT t1.col1, t2.col2
FROM table1 t1
INNER JOIN table2 t2
ON t1.col1=t2.col2

查询 2:

SELECT t1.col1, t2.col2
FROM table2 t2
INNER JOIN table1 t1
ON t1.col1=t2.col2

我们使用的是 Microsoft SQL Server 2005.

We are using Microsoft SQL server 2005.

推荐答案

别名,以及连接中表的顺序(假设它是 INNER JOIN)不会影响最终结果,因此不会影响性能,因为在执行查询时会替换订单(如果需要).

Aliases, and the order of the tables in the join (assuming it's INNER JOIN) doesn't affect the final outcome and thus doesn't affect performance since the order is replace (if needed) when the query is executed.

您可以在此处阅读有关关系代数的更多基本概念:http://en.wikipedia.org/wiki/Relational_algebra#Joins_and_join-like_operators

You can read some more basic concepts about relational algebra here: http://en.wikipedia.org/wiki/Relational_algebra#Joins_and_join-like_operators

这篇关于INNER JOIN 性能是否取决于表的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆