WordPress.org

Ready to get started?Download WordPress

Forums

Slow queries possibly slowing down the site. (5 posts)

  1. ballhogjoni
    Member
    Posted 2 years ago #

    I have a site with 10,000+ posts and probably 10 times that in comments. I see this query over and over in my slow query log.

    # Time: 111003 15:20:48
    # User@Host: user[user] @ localhost []
    # Query_time: 3 Lock_time: 0 Rows_sent: 1 Rows_examined: 52156
    SELECT count(*) as c FROM wp_posts WHERE ID IN (SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id = 18562) AND ID IN (SELECT post_id FROM wp_postmeta WHERE meta_key = '_menu_item_menu_item_parent' AND meta_value = '40158') ORDER BY menu_order;

    It appears that this is part of wordpress and not a plugin. How can I speed this up and fix this issue?

    Thanks

    P.S. this is not the only slow query but its the one that shows up the most.

  2. ballhogjoni
    Member
    Posted 2 years ago #

    Well I ended up doing a search through all the files and I found this sql in plugins only. So I guess its not part of wordpress. The plugin was the redirection plugin. Site is still slow and it still shows in the slow query log.

    Still need help/ideas.

  3. ballhogjoni
    Member
    Posted 2 years ago #

    I ran an explain on this query and it seems that mysql isn't using a primary key index to search so it has to do a complete table scan. I made sure that all the indices are there. This explain showed that it was scanning 52,000 records, I installed wp optimize and removed my post revisions. It seemed to speed up a little.

    Still unsure were this query is being called, but it seems to be called on every page load. If its wordpress, can you fix this query by joining the tables instead of running multiple inner queries?

  4. ballhogjoni
    Member
    Posted 2 years ago #

    bump!

  5. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    This query looks like the one from WPtouch Pro plugin, see wptouch_wordpress_menu_has_children() function in wptouch-pro/include/template-tags/wordpress-menu.php:

    $sql = $wpdb->prepare( "SELECT count(*) as c FROM {$wpdb->base_prefix}posts WHERE ID IN (SELECT object_id FROM {$wpdb->base_prefix}term_relationships WHERE term_taxonomy_id = %d) AND ID IN (SELECT post_id FROM {$wpdb->base_prefix}postmeta WHERE meta_key = '_menu_item_menu_item_parent' AND meta_value = '%d') ORDER BY menu_order", $settings->custom_menu_name, $parent );

    It's a premium plugin, not available in WP.org directory.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags