Perhaps something to add to the Big, Bad Optimization thread:
I’ve tried searching for the answer, but can’t find a good way to give OR and IN enough weight and meaning.
In creating a query based on a user’s selections I end up with something with many, many “OR” clauses. Like so:
select * from my_table where
my_field = 'apple' or
my_field = 'bottle' or
my_field = 'cat' or
my_field = 'dog' or
my_field = 'elephant' or
my_field = 'fish'
;
But I wonder if using “IN” would be faster or more efficient.
select * from my_table where
my_field IN ('apple','bottle','cat','dog','elephant','fish')
;
I’ve tried using a bogus table filled with millions of records and got such a wide variance in response times that I doubt my results are meaningful; anywhere from 62 seconds to 130 seconds for both queries.
So one better than the other? Would it matter if searching for strings or numbers?
Thanks,
/Cyberfunkr