Hi Scott,
Yes, I've updated CVS - both the stable branch and HEAD now have the fix. There's a time delay between anonymous CVS and developer CVS of about 8 hours, I think (why I didn't post immediately), so it should be good to go.
Basically, when you present a database with a query, it decides how it's going to execute it, based on what indexes there are, etc. What you see when you do EXPLAIN or EXPLAIN ANALYZE is the output of what the query planner plans to do - how it's going to run the query to get the results for you.
Now, a problem like this can be approached a number of different ways. Perhaps it would help if I explain what the query does. It wants to get a list of particpants in the messaging system. So, there are 3 relevant tables (and the user table, which isn't actually relevant for the problem, but needed for the glue of the query). The tables are: message, message_read and message_contact. Message is the 'queue' of incoming messages, message_read is the history of messages, and message_contact is the contact list. So each of those tables has two relevant fields, userto and userfrom, and for the contact list, user (owner of contact list) and contact (person on contact list). That makes 6 possible fields where any given userid can be, and we want to get a (distinct) list of them all.
The way the query was written joined all the tables on to user, joining each field (userfrom, userto) onto the user.id field. Which works, and gives us the answer, but is an approach to the problem that basically caused the query planner to explode. It's probably fine with small databases, but not all of us are so lucky as to support small databases
The rewrite does a UNION select - that is, it gets a list of userids from each of the 6 fields, and returns a distinct list of them. It's an approach that I know makes postgres much happier, and from everyone's posting, mysql as well
The problem is mysql 3.23. Originally, I didn't know how to deal with that, so I left it as it was, hoping to at least alleviate the problem for the mysql 4 and postgres users, but Eloy has a good idea over in that bug report, which is basically to replicate the UNION part of the query in php. So we do 6 queries, and then use php to do the merging and distinct part. I guess I should probably write that and check it in to CVS as well, but it's Saturday morning and I'm off to my jewellery workshop.
Hope that helps to clear this all up a bit!
Penny