簡體   English   中英

如何使用多個全文匹配優化 mysql 查詢

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM