I have a basic query that goes from 6 seconds to 1 second just by changing one join from LEFT JOIN
to LEFT HASH JOIN
or 'LEFT LOOP JOIN'. Can anyone explain why this would cause such a large increase in performance and why SQL's optimizer isn't figuring it out on it's own?
Here is roughly what the SQL looks like:
SELECT
a.[ID]
FROM
[TableA] a
LEFT HASH JOIN
[TableB] b
ON b.[ID] = a.[TableB_ID]
JOIN
[TableC] c
ON c.[ID] = a.[TableC_ID]
WHERE
a.[SomeDate] IS NULL AND
a.[SomeStatus] IN ('X', 'Y', 'Z') AND
c.[SomethingElse] = 'ABC'
Table A and B have millions of records and indexes on all the ID fields. Using SQL Server 2005.
Edit: A collegue suggested a LEFT LOOP JOIN and it seems to have made it even faster... SQL is not one of my strengths so I am trying to understand how these 'hints' are helping.