我正在使用此查询对 MySQL 数据库执行全文搜索:
SELECT DISTINCT
questions.id,
questions.uniquecode,
questions.spam,
questions.questiondate,
questions.userid,
questions.description,
users.login AS username,
questions.questiontext,
questions.totalvotes,
MATCH(questions.questiontext, questions.uniquecode)
AGAINST ('rock guitarist chick*' IN BOOLEAN MODE) AS relevance
FROM questions
LEFT JOIN users ON questions.userid = users.id
LEFT JOIN answer_mapping ON questions.id = answer_mapping.questionid
LEFT JOIN answers ON answer_mapping.answerid = answers.id
LEFT JOIN tagmapping ON questions.id = tagmapping.questionid
LEFT JOIN tags ON tagmapping.tagid = tags.id
WHERE questions.spam < 10
AND
(
MATCH(questions.questiontext, questions.uniquecode)
AGAINST ('rock guitarist chick*' IN BOOLEAN MODE)
OR MATCH(answers.answertext) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE)
OR MATCH (tags.tag) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE)
) GROUP BY questions.id ORDER BY relevance DESC
结果非常相关,但是搜索确实很慢,并且随着表格的增长而变得越来越慢。
表格统计:
问题- 400 条记录
索引
- 主要 BTREE - id
- BTREE - 唯一代码
- BTREE - 问题日期
- BTREE - 用户标识
- FULLTEXT - 问题文本
- FULLTEXT - 唯一代码
答案- 3,635 条记录
索引
- 初级 - BTREE - id
- BTREE - 回答日期
- BTREE - questionid
- FULLTEXT - 答案文本
answer_mapping - 4,228 条记录
索引
- 初级 - BTREE - id
- BTREE - 回答ID
- BTREE - questionid
- BTREE - 用户标识
标签- 1,847 条记录
索引
- 初级 - BTREE - id
- BTREE - 标记
- 全文 - 标记
标记映射- 3,389 条记录
索引
- 初级 - BTREE - id
- BTREE - 标记
- BTREE - questionid
无论出于何种原因,当我删除标记映射和标记JOINS 时,搜索速度都会大大加快。
您对如何加快此查询有任何提示吗?
提前致谢!