IF you have a version of MySQL that is recent enough (4.0+) you can merge 
your two queries *when you run them* by using the UNION predicate.

http://dev.mysql.com/doc/mysql/en/UNION.html

Much better than a client-side merge.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

"David Turner" <[EMAIL PROTECTED]> wrote on 10/04/2004 05:17:12 PM:

> Thanks for the suggestions over the weekend!  I will be looking in to
> this in a few days - for now I think I am just going to have to re-write
> my PHP script to make 2 separate queries and array_merge() them - which
> invariably seems to solve "OR" problems.  But there should be a better
> way, no?
> 
> -Dave
> 
> -----Original Message-----
> From: David Turner [mailto:[EMAIL PROTECTED] 
> Sent: October 1, 2004 4:04 PM
> To: [EMAIL PROTECTED]
> Subject: Indexing for OR clauses
> 
> 
> 
> Wondering if anyone can give me advice on indexing for OR clauses.
> 
> I have a table with a number of fields, two of which are sender_id and
> receiver_id.  I also have a query such as this:
> 
> SELECT ...
> WHERE (sender_id = 98765 OR reciever_id = 98765)
> 
> The query is OK for a limit of 10, but if I increase that to 25, it
> becomes inordinately slower (it is a large table).
> 
> Is it better for me to have two separate indexes, one for each of
> sender_id and receiver_id, or one index with both sender_id and
> receiver_id?  Or should I just avoid the use of OR?  Or am I simply
> missing something?
> 
> -Dave
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
> 
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> 

Reply via email to