using OR in an index

  • Is there a performance problem if I use an OR in my query, example:

    (a bit simplified, but actually my query is MUCH MUCH more complicated)

    select * from T1, T2  where (T1.F1 = T2.F1 AND T2.F2 = XXX)

                                      OR (T1.F1 = T2.F2 AND T2.F3 = yyy)

    Knowing that T1.F1 is indexed, but does it work when using OR?

     

    Thanks!!!

     

     

  • Best way I know to get performance out of this (assuming that the scans are unacceptable for you), is to create 2 different queries, optimize them separatly, then run them with a union all (or just union) to get the results.

     

    The or will always, in my experience, kill any chance of index seeks in a query like this.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply