我有两张桌子 -comments
和votes
:
comments(id, text, user_id, page_id)
votes(id, value)
Run Code Online (Sandbox Code Playgroud)
表中有 2,000,000 行votes
。
我创建了以下查询:
SELECT SUM(votes.value),
comments.text,
comments.comment_id
FROM comments, votes
WHERE comments.comment_id = votes.comment_id AND comments.page_id = $page_id
GROUP BY comment_id;
Run Code Online (Sandbox Code Playgroud)
查询运行了大约 12 秒,这正常吗?
SHOW PROCESSLIST
说它复制到临时表。这看起来很慢,是否需要使用临时表?