HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

The order of INNER JOIN's

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
innerthejoinorder

Problem

I would like to know if there are any rules about the order of INNER JOIN's in T-SQL 2000.

I had 62x the performance on my query when my INNER JOIN that act like a filter is placed at first instead of the end.

In reference of http://sql-4-life.blogspot.com/2009/03/order-of-inner-joins.html

Solution

The optimal sequence (the query plan) is determined by the query executor, based on the SQL code (operators you use), data statistics (statistical distribution of values in columns, data volume, etc.) and database structure (availability of indexes, datatypes, etc.).
So, there are rules, but first not all of them are under your total control and second the result is detemined by a combination of many factors.

To evaluate performance, you should always take a look at the estimated query plan and compare the changes to the plan caused by the changes in your SQL code, to undertand why a query run faster or slower than another.

Context

StackExchange Database Administrators Q#12110, answer score: 7

Revisions (0)

No revisions yet.