This MySQL query works just fine
SELECT o.id
FROM descriptions_programs d, titles_programs t, programs o
WHERE (d.object_id=o.id
AND MATCH (d.text) AGAINST ('+china' IN BOOLEAN MODE)
AND d.current=1)
AND (t.object_id=o.id
AND MATCH (t.text) AGAINST ('+china' IN BOOLEAN MODE)
AND t.current=1)
But if I replace one AND with an OR, the query runs a very long time. (I have to kill it.):
SELECT o.id
FROM descriptions_programs d, titles_programs t, programs o
WHERE (d.object_id=o.id
AND MATCH (d.text) AGAINST ('+china' IN BOOLEAN MODE)
AND d.current=1)
OR (t.object_id=o.id
AND MATCH (t.text) AGAINST ('+china' IN BOOLEAN MODE)
AND t.current=1)
Why is this? Don't get hung up on the simplicity of +china. I've just simplified this for the sake of debugging. Also, if I run with just one of the MATCH AGAINST tests, it works fine, so both are okay by themselves. I get the sense that I'm inadvertently causing a huge join by USING OR, but I just don't get it. I was previously using a n IN test on a UNION of two subselects an that worked, but this should work, too. Right?
Update: per bobince's request. It's not super slow, but at ~500ms, it's not nearly as fast as using a UNION as discussed here.
mysql> explain SELECT o.id
-> FROM programs o
-> JOIN titles_programs t ON t.object_id=o.id
-> JOIN descriptions_programs d ON d.object_id=o.id
-> WHERE MATCH (d.text) AGAINST ('+china' IN BOOLEAN MODE) AND d.current=1
-> OR MATCH (t.text) AGAINST ('+china' IN BOOLEAN MODE) AND t.current=1
-> ;
+----+-------------+-------+-------+
----------------+----------------+---------+----------------------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+----------------+----------------+---------+----------------------+--------+-------------+
| 1 | SIMPLE | o | index | PRIMARY | PRIMARY | 4 | NULL | 148666 | Using index |
| 1 | SIMPLE | d | ref | object_current | object_current | 4 | haystack.o.id | 1 | |
| 1 | SIMPLE | t | ref | object_current | object_current | 4 | haystack.d.object_id | 1 | Using where |
+----+-------------+-------+-------+----------------+----------------+---------+----------------------+--------+-------------+