最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

mysql - Wordpress Query optimaization for slow query

matteradmin8PV0评论

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

Post a comment

comment list (0)

  1. No comments so far