I've been investigating making performance improvements on a series of procedures, and recently a colleague mentioned that he had achieved significant performance improvements when utilising an INNER JOIN in place of EXISTS.
As part of the investigation as to why this might be I thought I would ask the question here.
So:
And really, any other experience people can bring to bear on this question.
I would appreciate if any answers could address this question specifically without any suggestion of other possible performance improvements. We've had quite a degree of success already, and I was just interested in this one item.
Any help would be much appreciated.
Basically, join order DOES matter because if we can join two tables that will reduce the number of rows needed to be processed by subsequent steps, then our performance will improve.
A LEFT JOIN is absolutely not faster than an INNER JOIN . In fact, it's slower; by definition, an outer join ( LEFT JOIN or RIGHT JOIN ) has to do all the work of an INNER JOIN plus the extra work of null-extending the results.
In cases like above the Exists statement works faster than that of Joins. Exists will give you a single record and will save the time also. In case of joins the number of records will be more and all the records must be used.
If all you need is to check for matching rows in the other table but don't need any columns from that table, use IN. If you do need columns from the second table, use Inner Join.
Generally speaking, INNER JOIN
and EXISTS
are different things.
The former returns duplicates and columns from both tables, the latter returns one record and, being a predicate, returns records from only one table.
If you do an inner join on a UNIQUE
column, they exhibit same performance.
If you do an inner join on a recordset with DISTINCT
applied (to get rid of the duplicates), EXISTS
is usually faster.
IN
and EXISTS
clauses (with an equijoin correlation) usually employ one of the several SEMI JOIN
algorithms which are usually more efficient than a DISTINCT
on one of the tables.
See this article in my blog:
Maybe, maybe not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With