最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - Wordpress Query optimaization for slow query

programmeradmin0浏览0评论

I've WP installation with some 120K posts. One of the slow queries that frequently appear at @mysql-slow.log is below

 # Query_time: 1.744827  Lock_time: 0.000567 Rows_sent: 1  Rows_examined: 635732

 SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  LEFT JOIN wp_postmeta ON 
(wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = 'sort_order_' ) WHERE 1=1 
AND (wp_postmeta.post_id IS NULL) AND wp_posts.post_type IN ('post', 'photo', 'video')
AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10;

And that is caused by WP_Query with meta_query arguments

$args = array(
            'post_type' => array('post','photo','video'),
            'post_status'=> 'publish',
            'posts_per_page' => 10,
            'meta_query'  => array(
            'relation' => 'AND',
            array( 'key' => 'sort_order_', 'compare' => 'NOT EXISTS')
                ),
            );

Is there any way to speed up this query. May be like indexing. But how? Any help will be greatly appreciated . Thank you

发布评论

评论列表(0)

  1. 暂无评论