At 06:03 PM 10/1/2004, you wrote:
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
Dave,
If you do an Explain it will likely show it uses only 1 index. You need to break it into 2 queries and merge them together using Union. This shouldn't take long because it is only returning a few rows. See http://dev.mysql.com/doc/mysql/en/UNION.html.
Mike
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]