2011-07-14 41 views
0

这里是我的查询:如何优化与多个全文MySQL查询匹配

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 

还有什么我可以做,以加快步伐?

解释我的表, 表-A是具有标题主表和内容领域, 表-B是我在表-A行属性表,使表-A行可以有额外的属性。

让我知道是否需要更好地解释这一点。

谢谢!这里

更新快速查询的解释:

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  

另一个更新 - 表定义: 表-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 

指标的内容表-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 

TABLE_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 
+0

显示第二个快速查询的解释 – Karolis

+0

刚刚做过,请告诉我是否需要任何其他信息。谢谢! – Gerry

+0

我认为表格定义也是有用的。 – Karolis

回答

0

好吧,我的第一个观点是改变的全文搜索一个LIKE条款。为此目的,在(webid,join_id)上有webid或甚至更好的复合索引的索引是很好的。这应该有助于更加一致的表格连接。

+0

好吧,我会试试这个,我想问题是应该是哪一个,哪个应该是全文? – Gerry

+0

@Gerry最好测试一下,因为我对数据了解不多。 – Karolis

+0

仅供参考 - 这将是我可以测试这个几个小时之前,我会尽快标记你的答案是否正确:) – Gerry