On Tuesday 18 March 2003 02:47, dreq jkj wrote:

> I have trouble figuring out how the indices are used when making a query
> that uses OR-operator.
>
> If I have the following table:
>
> create table testing(
> id int unsigned not null primary key auto_increment,
> idx1 int unsigned not null,
> idx2 int unsigned not null,
> index(idx1),
> index(idx2));
>
> In this query i expect mySQL to use one of the two indices to speed up the
> query, but It doesn't.. :(
> select * from testing where idx1=0 or idx2=1;

Yes, MySQL doesn't use indexes in this way:
        http://www.mysql.com/doc/en/Searching_on_two_keys.html

> The thing I'm thinking about instead is the following query:
> select * from testing where idx1=0
> UNION
> select * from testing where idx2=1;
>
> It looks like this does speed up the query, but is this the way to go???
> Is this a weaknes in mySQL or have I forgotten something?





-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Egor Egorov
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to