我们的主要网站是运行WordPress 6.0.3在PHP 8.0与MariaDB 10.x数据库。
我们正在使用New Relic(NR)作为系统和应用程序指标,并注意到NR“慢速SQL跟踪”表中始终显示一个特定的SQL查询。进一步缩小范围后,这些慢速查询来自WP RSS源。
以下是一些例子:
- https://www.example.org/search/results/feed/rss
- https://www.example.org/search/results/feed/rss2
- https://www.example.org/category/tech-news-post/feed
我们几乎可以点击任何RSS提要URL,并在大约10到30秒内显示在NR“Slow SQL traces”表中。
查询看起来像这样的庞然大物:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE ?=? AND
(((wp_posts.post_title LIKE ?) OR (wp_posts.post_excerpt LIKE ?) OR
(wp_posts.post_content LIKE ?))) AND (wp_posts.post_password = ?) AND
((wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)) OR
(wp_posts.post_type = ? AND (wp_posts.post_status = ? OR wp_posts.post_status = ?)))
ORDER BY wp_posts.post_title LIKE ? DESC, wp_posts.post_date DESC LIMIT ?, ?
您知道如何优化此RSS查询,或者缓存它吗?
谢谢
乔恩
1条答案
按热度按时间eh57zj3b1#
索引数据库表字段:
在查询中使用。请执行以下步骤:https://dev.mysql.com/doc/refman/8.0/en/mysql-indexes.html