如何分析 WordPress 安装的慢查询日志?
Posted
技术标签:
【中文标题】如何分析 WordPress 安装的慢查询日志?【英文标题】:How can I analyze a Slow Query log for a WordPress install? 【发布时间】:2012-04-22 07:42:17 【问题描述】:我在安装 WordPress 时遇到了一些性能问题。我已经运行了多个慢查询测试,虽然我确实看到它们之间存在一些一致性,但我仍然无法查明问题所在。以下是我多次看到的一些查询:
SET timestamp=1333980631;
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (1442,4054) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 2;
和
### 1 Query
### Total time: 3.015405, Average time: 3.015405
### Taking 3.015405 seconds to complete
### Rows analyzed 60
SET timestamp=XXX;
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE XXX=XXX AND ( wp_term_relationships.term_taxonomy_id IN (XXX) ) AND wp_posts.post_type = 'XXX' AND (wp_posts.post_status = 'XXX') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT XXX, XXX;
SET timestamp=1334004964;
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (125) ) 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, 8;
和
### 1 Query
### Total time: 1.593301, Average time: 1.593301
### Taking 1.593301 seconds to complete
### Rows analyzed 19755
SET timestamp=XXX;
SELECT /*!XXX SQL_NO_CACHE */ * FROM `wp_posts`;
SET timestamp=1333978522;
SELECT /*!40001 SQL_NO_CACHE */ * FROM `wp_posts`;
我注意到wp_term_taxonomy
似乎出现了,还有wp_posts
和其他一些。我的问题是,如何缩小这些结果的范围并找出问题所在?
【问题讨论】:
【参考方案1】:你可以:
-
使用plugin performance profiler 对有问题的插件进行基准测试和查明
使用new relic 查找问题
使用Debug Objects 转储查询等数据。
您显示的查询看起来像通常的 wp-admin 查询,或用于定义要在列表中显示多少页的寻呼机查询。
您也可以尝试最简单的方法 - 一个一个地禁用插件,以确定是哪个插件生成了有问题的查询。
【讨论】:
谢谢!我今天会调查一下。以上是关于如何分析 WordPress 安装的慢查询日志?的主要内容,如果未能解决你的问题,请参考以下文章