Quote:>----------
>Sent: Thursday, February 26, 1998 10:43 AM
>>This is true because Informix doesn't use indexes in the presence of an OR operation.
>>So if table1 is big and you have an index on col the UNION example will work
>>much faster, because now you have 3 selects but no ORs.
>You know, I wonder if this is really true. Everyone says it, and yet my query
>select rev_ref_num
> from asap_rev_extract
> where ( ext_id = 3840000 or ext_id = 383000 )
>comes back instantly. 3.5M rows, index on ext_id...
>I'm using OnLine 7.3
There are two factors which affect whether the OR operation works with
indexes or not, and they're the usual culprits - the version of the engine
and the SQL statement.
Some versions of the engine didn't handle OR conditions very well; I don't
have the details available. You can find out whether your version does by
looking at the SET EXPLAIN output.
Some OR conditions are not readily handlable with indexes and others are.
Paul's example is one that can be dealt with because both clauses in the OR
are on the same column. The condition could also be written as:
ext_id IN (3840000,383000)
Other OR conditions cannot easily be handled with indexes: for example, a
OR condition referring to two different columns on either side is not so easily
handled:
(ext_id = 3840000) OR (other_column BETWEEN 37 and 92)
Even if there is an index on ext_id and a separate index on other_column,
it isn't clear how the optimizer will, or should, handle the query. If there isn't
much overlap between the sets of rows identified by the two conditions, then
it may be quicker to do a UNION because there won't be much to do in the
duplicate elimination phase of UNION. On the other hand, if there is a lot of
overlap (so many rows satisfy both conditions), then the single scan may be
quicker than the UNION with two separate indexed SELECT operations. It
also depends on the size of the table, of course.
Isn't life fun! The answer is 'it varies, and it depends'...
Yours,