假设我有一个"文章"表,其中包含以下列:
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 …Run Code Online (Sandbox Code Playgroud)