Re: WHERE IN vs. WHERE OR OR OR
Posted in 1998
Art S. Kagel — — source: Informix-list mailing list archive (1991-1998)
Daniel Kirkdorffer wrote:
>
> Hi,
>
> Using JDBC against and Informix database I was wondering if anyone
> knew which WHERE clause would be more efficient:
>
> SELECT x FROM y WHERE x IN (1, 2, 3,..., n)>
> or
>
> SELECT x FROM y WHERE x = 1 OR x = 2 OR x = 3 OR ... OR x = n>
> (Where x is a primary key)
>
> Would the choice be the same if n > 100, or even n > 1000?
>
> Any suggestions would be greatly appreciated.
In general an IN clause is more efficient than a set of OR conditions.
The kicker is that if the table is fragmented, and in a few other
esotheric circumstances the optimizer will expand either into a set of
UNIONs.
Art S. Kagel