假设我有一个“文章”表,其中包含以下列:
article_text: fulltext indexed
author_id: indexed
现在我想搜索一个出现在某个作者写的文章中的词。
所以像:
select * from articles
where author_id=54
and match (article_text) against ('foo');
这个查询的解释告诉我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');
对此的解释首先列出了 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)