[英]How to optimize mysql query with multiple fulltext matches
这是我的查询:
SELECT heading FROM table_a, table_b as m1, table_b as m2 WHERE (m1.join_id = '69' AND MATCH(m1.content) AGAINST('Harry' IN BOOLEAN MODE)) AND (m2.join_id = '71' AND MATCH(m2.content) AGAINST('+Highway +Design' IN BOOLEAN MODE)) AND m1.webid = table_a.id AND m2.webid = table_a.id
现在大约需要 3 秒。 如果我拿出这样的条件之一:
SELECT heading FROM table_a, table_b as m2 WHERE (m2.join_id = '71' AND MATCH(m2.content) AGAINST('+Highway +Design' IN BOOLEAN MODE)) AND m2.webid = table_a.id
大约需要 0.05 秒。
我在“内容”列上有一个全文索引。
此外,在第一个查询中,如果我要搜索“Highway Design”(没有 + 或“”之类的运算符),大约需要 30 秒。
这是我的解释查询:
d select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE m1 fulltext id_index,content_ft content_ft 0 1 Using where
1 SIMPLE table_a eq_ref PRIMARY PRIMARY 4 user.m1.id 1
1 SIMPLE m2 fulltext id_index,content_ft content_ft 0 1 Using where
我还能做些什么来加快速度吗?
为了解释我的表,table_a 是具有标题的主表,并且 table_b 是我的 table_a 中行的属性表,因此 table_a 中的行可以具有附加属性。
如果我需要更好地解释这一点,请告诉我。
谢谢!
UPDATE 这里是快速查询的解释:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE m2 fulltext id_index,content_ft content_ft 0 1 Using where
1 SIMPLE table_a eq_ref PRIMARY PRIMARY 4 user.m2.webid 1
另一个更新 - 表定义:Table_b
id int(11) No None AUTO_INCREMENT
join_id int(11) No None
webid int(11) No None
content text utf8_general_ci No None
内容 table_b 的索引
PRIMARY BTREE Yes No id 2723702 A
content BTREE No No content (333) 226975 A
id_index BTREE No No webid 151316 A
content_ft FULLTEXT No No content 118421
表_a
id int(11) No None AUTO_INCREMENT
heading text utf8_general_ci Yes NULL
表一索引
PRIMARY BTREE Yes No id 179154 A
heading BTREE No No heading (300) 89577 A YES
好的,我的第一个意见是将全文搜索更改为LIKE
子句。 为此,最好在webid上有一个索引,或者在 (webid, join_id) 上有一个复合索引更好。 这应该有助于更一致的表连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.