Does the performance of an INNER JOIN depend on the order of the tables?

Suddenly, the question occurred to me when I was setting up one stored procedure. Let me ask you -

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

Query1:

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

Query2:

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

We are using Microsoft SQL Server 2005.

+8
performance sql sql-server sql-server-2005
source share
1 answer

The aliases and the order of the tables in the join (provided that it is an INNER JOIN ) do not affect the final result and, therefore, do not affect the performance, since the order is replaced (if necessary) when the query is executed.

Here you can read some more fundamental concepts about relational algebra: http://en.wikipedia.org/wiki/Relational_algebra#Joins_and_join-like_operators

+6
source share

All Articles