600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > mysql like 全文索引_mysql like%query是慢全文索引

mysql like 全文索引_mysql like%query是慢全文索引

时间:2019-03-22 12:10:27

相关推荐

mysql like 全文索引_mysql like%query是慢全文索引

I'm using a simple mysql LIKE query like this:

SELECT * FROM myTable WHERE field LIKE 'aaa%' ORDER BY field2

I have a full-text index on "field", and still it is very slow.

I understood there is an option to use match. What is the difference? How? What is the best approach for my usage?

Notice I'm using the "%" for everything that starts with "aaa"

UPDATE:

I've ended up using something like this:

SELECT

*, MATCH (name) AGAINST ('a*' IN BOOLEAN MODE) AS SCORE

FROM

users

WHERE

MATCH (name) AGAINST ('a*' IN BOOLEAN MODE)

ORDER BY SCORE, popularity DESC LIMIT 4

One thing I would like to change, is not due the order by firstly by SCORE and then by my field popularity, and instead order by a simple weight function, something like 0.5*SCORE + 0.5*popularity. How?

解决方案

LIKE does not use the full-text index. To make use of the fulltext index, you have to use match (as you said):

SELECT *

FROM myTable

WHERE MATCH(field) AGAINST ('aaa*' IN BOOLEAN MODE)

ORDER BY field2

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。