mysql查询需要1天以上,如何加快速度:
update posts set category_id = (
SELECT keyword_id
FROM post_keywords
where keyword_id IN (
SELECT keyword_id
FROM post_keywords
where id_post = posts.id_post)
group by keyword_id
order by count(keyword_id) DESC
limit 0,1
);
任何解决方案?
答案 0 :(得分:2)
这不完全是一回事,但结果仍然是你想要的结果。我很好奇(IF!?)这可能会影响性能。
UPDATE posts
SET category_id = (
SELECT pkw.keyword_id
FROM post_keywords pkw
JOIN (
SELECT keyword_id, cnt = COUNT(*)
FROM post_keywords
GROUP BY keyword_id ) cnts
ON cnts.keyword_id = pkw.keyword_id
WHERE pkw.id_post = posts.id_post
ORDER BY cnt DESC
LIMIT 0,1
)