Monday, February 20, 2012

Join order considerations in SQL Server (2005)

I'm doing a bit of research on join order in terms of how it affects performance in SQL Server (specifically 2005).

Can someone point me to some sites that do a good job of explaining this, or, can you give me a good overview of the topic?

As far as performance goes, I think you will be fine regardless of your join order for the most part. In outer joins (think of a LEFT OUTER JOIN) the order of your tables will matter because the result set would be different depending on which table is the outer and which table is the inner. That is not so much a performance consideration as it is a results consideration.

One motto I always live by is to try it and see. So you can get a lot of replies with links, but I say look at the query plans (You can choose display estimated query plan or if you have a test system you can display the actual execution plan when the query finishes) and play with different join orders.

If you are relatively new to query plans there are a ton of great books. I would highly reccomend Itzik Ben Gan's Inside SQL Server: T-SQL Programming book for his treatment of this topic.

|||

Justin:

If you are wanting to enforce the join order and go rules based you need to SET FORCEPLAN ON; however, this is not something that should normally be practiced. Our standards here pretty much forbid this use of this setting.


Dave

No comments:

Post a Comment