mysql - 用其他索引帮助全文搜索的任何方法?

gge*_*z44 5 mysql full-text-search full-text-indexing

假设我有一个"文章"表,其中包含以下列:

article_text:  fulltext indexed
author_id:     indexed
Run Code Online (Sandbox Code Playgroud)

现在我想搜索一篇特定蒿动作文章中出现的术语.

像这样的东西:

select * from articles 
where author_id=54 
and match (article_text) against ('foo');
Run Code Online (Sandbox Code Playgroud)

这个查询的解释告诉我mysql只会使用全文索引.我相信mysql只能使用1个索引,但是在全文搜索术语之前,确定一个特定作者首先编写的所有文章似乎是一个明智的想法...所以无论如何都要帮助mysql?

例如..如果你做了自我加入?

select articles.* from articles as acopy 
                  join articles on acopy.author_id = articles.author_id 
where 
    articles.author_id = 54 
and match(article_text) against ('foo');
Run Code Online (Sandbox Code Playgroud)

对此的解释首先列出了author_id索引的使用,然后是全文搜索.

这是否意味着它实际上只在有限集上进行全文搜索,由author_id过滤?

附录

解释自我加入的计划如下:

*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: acopy
         type: ref
possible_keys: index_articles_on_author_id
          key: index_articles_on_author_id
      key_len: 5
          ref: const
         rows: 20
     filtered: 100.00
        Extra: Using where; Using index
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: articles
         type: fulltext
possible_keys: index_articles_on_author_id,fulltext_articles
          key: fulltext_articles
      key_len: 0
          ref: 
         rows: 1
     filtered: 100.00
        Extra: Using where
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

Seb*_*bas 0

好吧,所以,自从

索引合并不适用于全文索引

http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html

我会尝试这种方法:(author_id_index用您在author_id上的索引名称替换)

select * from articles use index (author_id_index)
where author_id=54 
and match (article_text) against ('foo');
Run Code Online (Sandbox Code Playgroud)

这里的问题如下:

  • 常规索引与全文索引结合使用确实是不可能的
  • 如果您将表与其自身连接,则您将使用连接两侧已有的索引(ON 子句将使用author_id 列,您在这里肯定需要索引)

最有效的方法必须由你自己决定,通过一些测试用例,使用作者索引是否比文本索引更好。