提高mysql查询性能,全文搜索

时间:2015-04-15 09:17:41

标签: mysql sql full-text-search

我有两张桌子 - postscomments。使用 MySQL全文搜索我需要查找与某些输入文本匹配的帖子和评论。对于每个帖子,我还需要找到0-3(3可以更改为5或更多)评论。另外,我希望通过帖子进行分页。

现在我有以下查询:

SELECT score_comment + score_post AS score_sum, temp.* FROM (
SELECT t_1.*,
      @num := IF(@post_id = post_id, @num + 1, 1) AS row_number,
      @post_id := post_id AS dummy
FROM (SELECT * FROM (SELECT MATCH (comm.content) AGAINST ("standart server web detected") AS score_comment, paged_post.*,
  comm.comment_id, comm.last_edited AS c_last_edited, comm.content FROM comments AS comm
INNER JOIN
(SELECT *,
 MATCH (description) AGAINST ("standart server web detected") AS score_post
    FROM posts
    WHERE MATCH (description) AGAINST ("standart server web detected") > 0
    LIMIT 0, 10) AS paged_post 
ON comm.post_id = paged_post.post_id
WHERE MATCH (comm.content) AGAINST ("standart server web detected") > 0) AS comm_view ORDER BY post_id, c_last_edited DESC) AS t_1
) AS temp WHERE temp.row_number <=3
ORDER BY score_comment + score_post DESC;

看起来这个查询做得很对,但我担心性能问题。现在在我的家用机器上获得10k帖子和500k评论它的工作时间约为2.1-2.2秒

有没有办法改进此查询以减少执行时间?

0 个答案:

没有答案