以下SQL查询导致Wordpress站点上生产MySQL数据库的负载很重。
SELECT
lessons.ID AS lesson_id,
resultmeta.meta_value AS status,
lessons.post_title AS title,
lessons.post_name AS slug,
count(resultmeta.meta_value) AS nr_of_results
FROM
mv_posts AS lessons
LEFT JOIN
mv_posts AS results
ON
results.post_parent = lessons.ID AND
results.post_type = 'we_result' AND
results.post_author IN($students_string)
LEFT JOIN
mv_postmeta AS resultmeta
ON
results.ID = resultmeta.post_id AND
resultmeta.meta_key = 'we_result_status_code'AND
results.post_author IN($students_string)
WHERE
lessons.post_type = 'we_lesson' AND
lessons.post_status = 'publish' AND
lessons.ID IN($lessons_id)
GROUP BY
lessons.ID,
resultmeta.meta_value;
在测试环境中使用完全相同的DB,查询将在0.005秒内执行。 mv_postmeta表有超过300万行,mv_post有超过100万行。
可能并发INSERTS导致此问题,并且可能是数据库缓存过载。
我尝试通过wordpress wp_query做READ COMMITED但没有成功。
有人有这方面的提示吗?这些交易关闭了网站大约2分钟。