Does using WHERE IN hurt query performance?

sql-server

Solution

Yes, assuming relatively large data sets.

It's considered better to use `EXISTS` for 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 `IN` vs. `EXISTS` is internalized. Another article: http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx

Problem

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?

Original source

Related problems