Subject | Re: "IN" and several "=" and "or" |
---|---|
Author | Svein Erling Tysvær |
Post date | 2005-05-25T07:52:16Z |
> Sorry I've made a mistake. I do mean the "where id = 1 or id = 2 orThe optimizer tries to use indexes to the best of its ability. Though
> id = 4 or id = 6 or id = 8 or id = 10". Thanks for making the point
> clear to me. My next question is that does this kind of query
> optimezed the uses of Index? What about its performance in non index
> columns?
with OR it at best has to use the index once for every value (in your
case six times). Normally, it won't be of much benefit, but in some
cases you may consider rewriting your statement like:
WHERE ID BETWEEN 1 AND 10 AND ID NOT IN (3,5,7,9)
I don't know the treshold for this to be worth while, I doubt being
interested in six out of ten values is enough.
For non indexed columns, the number of records in the table will be of
importance since it has to check the field in every record. In
general, for queries without any join I start to care about plans when
there are 100000+ records.
Set