开发者

Problem with MySQL full text search in combination with OR?

开发者 https://www.devze.com 2022-12-13 10:34 出处:网络
I have a table Document with a full text index headline_idx on two columns, headline and text where the text is a MEDIUMTEXT column, there is also some other fields, one of the named lang.

I have a table Document with a full text index headline_idx on two columns, headline and text where the text is a MEDIUMTEXT column, there is also some other fields, one of the named lang.

If I do the following select开发者_如何学编程:

select * from Document where lang= 'en' AND match(headLine,text) against ("test")

everything works OK, the fulltext index is used as expected, BUT if I change the AND to an OR like this:

select * from Document where lang= 'en' OR match(headLine,text) against ("test")

the full text index is NOT used, it's not even part of the possible_keys if I do an EXPLAIN EXTENDED which makes any index hints useless.

I would be perfectly happy to add the third column to the full text index, but in the real case that column is in another table. I run version 5.1.35 of MySQL.

Any ideas on what's going on?


Quote from MySql reference: Index Merge is not applicable to fulltext indexes. We plan to extend it to cover these in a future MySQL release.

This particular query can be rephrased with a union and then it will use indexes:

select * from Document where lang= 'en' UNION
select * from Document where match(headLine,text) against ("test")
0

精彩评论

暂无评论...
验证码 换一张
取 消