如何改进 MYSQL 全文搜索索引与 table 中的其他列?

How to improve MYSQL full text search index with other column in the table?

我的查询很慢(26 秒):

SELECT uniqueIDS FROM search_V2 WHERE siteID=1 AND status=1 AND (MATCH(data) AGAINST ('scale' IN BOOLEAN MODE));

我喜欢先查询 siteID_status 索引,然后再使用完整搜索索引。

有什么解决办法吗?

您可以告诉查询首先遵循哪个索引。请参阅 https://dev.mysql.com/doc/refman/8.0/en/index-hints.html 处的索引提示。如果不对其进行测试,您的查询将类似于

SELECT uniqueIDS FROM search_V2 WHERE siteID=1 AND status=1 AND (MATCH(data) AGAINST ('scale' IN BOOLEAN MODE)) USE INDEX(siteID_status,fulltext_index);

其中 fulltext_index 是您的全文索引的名称。希望它有效,但你很接近。

所以这是我找到的最佳解决方案:

SELECT uniqueIDS FROM
(
    SELECT * FROM search_V2 WHERE siteID=1 AND status=1
) A
WHERE MATCH(data) AGAINST ('scale' IN BOOLEAN MODE);

这个post真的帮了我:https://dba.stackexchange.com/questions/15214/why-is-like-more-than-4x-faster-than-match-against-on-a-fulltext-index-in-mysq/15218#15218?newreg=36837d8616984e289377475b27ee0758

我希望它也能帮助到其他人。