Featured post
mysql - How can I simplify this Wordpress query to increase performance? -
i have several boxes in wordpress site have show selection of posts belong categories , not belong several others. using native wordpress tools result query this:
select sql_calc_found_rows wp_posts.* wp_posts inner join wp_term_relationships on (wp_posts.id = wp_term_relationships.object_id) inner join wp_term_taxonomy on (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) 1=1 , wp_term_taxonomy.taxonomy = 'category' , wp_term_taxonomy.term_id in ('1', '49') , wp_posts.id not in ( select tr.object_id wp_term_relationships tr inner join wp_term_taxonomy tt on tr.term_taxonomy_id = tt.term_taxonomy_id tt.taxonomy = 'category' , tt.term_id in ('3394', '49', '794', '183') ) , wp_posts.post_type = 'post' , (wp_posts.post_status = 'publish') group wp_posts.id order wp_posts.post_date desc limit 0, 5;
now quite expensive , ends in slow queries log. i'll gladly drop wordpress way , build query manually. first thing can eliminate need wp_term_taxonomy
table (i can use term_taxonomy_id instead of term_id, never understood why wordpress needs both) still have not ( subquery )
problem due categories excluded.
so considering i'm free (like create other "service" tables if might help), what's best way speed search under these conditions?
i don't see need subquery, tables it's using in main query! exluding stuff should simple matter of adding more statements.
can't edit line
and wp_term_taxonomy.term_id in ('1', '49')
to
and wp_term_taxonomy.term_id in ('1', '49') , wp_term_taxonomy.term_id not in ('3394', '49', '794', '183')
..and removing subquery completely?
- Get link
- X
- Other Apps
Comments
Post a Comment