I’ve heard that using an IN Clause can hurt performance because it doesn’t use Indexes properly. See example below:
SELECT ID, Name, Address
FROM people
WHERE id IN (SELECT ParsedValue FROM UDF_ParseListToTable(@IDList))
Is it better to use the form below to get these results?
SELECT ID,Name,Address
FROM People as p
INNER JOIN UDF_ParseListToTable(@IDList) as ids
ON p.ID = ids.ParsedValue
Does this depend on which version of SQL Server you are using? If so which ones are affected?
Yes, assuming relatively large data sets.
It’s considered better to use
EXISTSfor large data sets. I follow this and have noticed improvements in my code execution time.According to the article, it has to do with how the
INvs.EXISTSis internalized. Another article: http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx