我的 WordPress 网站上有 103775 个帖子。以下查询不断使我的 MySQL 数据库服务器超载。我怎样才能永久修复它?

发布于 2025-01-12 16:05:02 字数 1345 浏览 1 评论 0原文

我的 WordPress 网站上有 103775 个帖子,以下查询不断使我的 MySQL 数据库服务器超载。我怎样才能永久修复它?

第一个:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
   INNER JOIN wp_postmeta 
      ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 
      AND (wp_postmeta.meta_key = 'post_views_count') 
      AND wp_posts.post_type = 'post' 
      AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_postmeta.meta_value+0 DESC 
LIMIT 0, 3

第二个:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
  LEFT JOIN wp_term_relationships 
     ON (wp_posts.ID = wp_term_relationships.object_id) 
  WHERE 1=1 
    AND (wp_term_relationships.term_taxonomy_id IN (127,188,190)) 
    AND wp_posts.post_type = 'post' 
    AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 4

第三个:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
  LEFT JOIN wp_term_relationships 
     ON (wp_posts.ID = wp_term_relationships.object_id) 
  WHERE 1=1 
    AND (wp_term_relationships.term_taxonomy_id IN (127,188,190)) 
    AND wp_posts.post_type = 'post' 
    AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 4

这些查询的作用是什么?如何避免因 MySQL 数据库服务器超载而生成这些查询?

I have 103775 posts on my WordPress site and the following queries constantly overloading my MySQL database server. How can I permanently fix it?

First one:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
   INNER JOIN wp_postmeta 
      ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 
      AND (wp_postmeta.meta_key = 'post_views_count') 
      AND wp_posts.post_type = 'post' 
      AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_postmeta.meta_value+0 DESC 
LIMIT 0, 3

Second:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
  LEFT JOIN wp_term_relationships 
     ON (wp_posts.ID = wp_term_relationships.object_id) 
  WHERE 1=1 
    AND (wp_term_relationships.term_taxonomy_id IN (127,188,190)) 
    AND wp_posts.post_type = 'post' 
    AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 4

Third:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
  FROM wp_posts 
  LEFT JOIN wp_term_relationships 
     ON (wp_posts.ID = wp_term_relationships.object_id) 
  WHERE 1=1 
    AND (wp_term_relationships.term_taxonomy_id IN (127,188,190)) 
    AND wp_posts.post_type = 'post' 
    AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC 
LIMIT 0, 4

What does these queries do & how can I avoid generating these queries from overloading my MySQL database server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请叫√我孤独 2025-01-19 16:05:02

我首先验证 where 语句索引中使用的所有字段(应该是这种情况)。
SQL_CALC_FOUND_ROWS也存在性能问题
正如你在这里看到的:
wordpress 生成缓慢的 mysql 查询 - 是索引问题吗?
在这里
https://core.trac.wordpress.org/ticket/10964

然后我会检查mysql_cache是​​否启用并添加缓存插件。

i would start by verifying all fields used in where statements are indexed (chich should be the case).
There is also performance problems with SQL_CALC_FOUND_ROWS
as you can see here :
wordpress generating slow mysql queries - is it index problem?
and here
https://core.trac.wordpress.org/ticket/10964

Then i would check if mysql_cache is enabled and add a cache plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文