There are 2 queries:
select a,b,c,d from test where a=1 or a=2 or a=3
and
select a,b,c,d from test where a in (1,2,3)
Which one performs better? In the table there is an index on column a.
this should depend.
as you said in your comment, there are many variables.
the best way is to run some kind of explain plan for each specific query and see the difference (if there is any) on the specific database with the specific data loaded and the specific query.
stylistically, which is not the question, I personally prefer the IN clause in these cases.
Most - if not all - query optimizers will rewrite one form to the other before choosing an execution plan. So these two will have the same performance.
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