开发者

Is there any performance difference between a SQL "IN" statement versus using "OR"?

开发者 https://www.devze.com 2022-12-28 21:06 出处:网络
Thought I would ask the knowledgeable StackOverflow community a question that was on my mind today and I can\'t s开发者_StackOverflow中文版eem to find an answer.

Thought I would ask the knowledgeable StackOverflow community a question that was on my mind today and I can't s开发者_StackOverflow中文版eem to find an answer.

Is there any performance difference or advantage between an "IN" or using "OR"?

Ie. Is

SELECT type FROM types WHERE typecat IN ('abc', 'def')

better than

SELECT type FROM types WHERE typecat = 'abc' OR typecat = 'def'

Adding: Using SQL Server 2008


This depends entirely on the SQL product you're using, which you haven't stated. One RDBMS that I use regularly cannot use indexes for the OR version.


If I recall correctly, SQL Server converts the IN statement you have into the OR statement.


No, there is no performance difference. The optimizer takes care of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消