<span class="resolved" aria-label="Resolved" title="Topic is resolved."></span>Slow queries

[ad_1]

Replies: 1

New Relic has reported the slowest query on our platform to be:

SELECT wp_users.ID,wp_users.display_name FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) WHERE ?=? AND ( ( ( wp_usermeta.meta_key = ? AND wp_usermeta.meta_value LIKE ? ) OR ( wp_usermeta.meta_key = ? AND wp_usermeta.meta_value LIKE ? ) OR ( wp_usermeta.meta_key = ? AND wp_usermeta.meta_value LIKE ? ) OR ( wp_usermeta.meta_key = ? AND wp_usermeta.meta_value LIKE ? ) ) ) ORDER BY user_login ASC

This is the stack trace that they have reported:

in mysqli_query called at ./wp-includes/wp-db.php (2162)
in wpdb::_do_query called at ./wp-includes/wp-db.php (2051)
in wpdb::query called at ./wp-includes/wp-db.php (2829)
in wpdb::get_results called at ./wp-includes/class-wp-user-query.php (776)
in WP_User_Query::query called at ./wp-includes/class-wp-user-query.php (78)
in WP_User_Query::__construct called at ./wp-includes/user.php (763)
in get_users called at ./wp-content/plugins/simple-author-box/inc/class-simple-author-box-block.php (54)
in Simple_Author_Box_Block::generate_js_vars called at ./wp-includes/class-wp-hook.php (307)
in WP_Hook::apply_filters called at ./wp-includes/class-wp-hook.php (331)
in WP_Hook::do_action called at ./wp-includes/plugin.php (474)
in do_action called at ./wp-settings.php (587)
in require_once called at ./wp-config.php (126)
in require_once called at ./wp-load.php (50)
in require_once called at ./wp-blog-header.php (13)
in require called at ./index.php (17)

They have also provided the query analysis:

user_meta

  • The table was retrieved with this index: meta_key
  • A temporary table was created to access this part of the query, which can cause poor performance. This typically happens if the query contains GROUP BY and ORDER BY clauses that list columns differently.
  • MySQL had to do an extra pass to retrieve the rows in sorted order, which is a cause of poor performance but sometimes unavoidable.
  • You can speed up this query by querying only fields that are within the index. Or you can create an index that includes every field in your query, including the primary key.
  • Approximately 82530 rows of this table were scanned.

users

  • The table was retrieved with this index: PRIMARY
  • You can speed up this query by querying only fields that are within the index. Or you can create an index that includes every field in your query, including the primary key.
  • Approximately 1 row of this table was scanned.

Can this be improved?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer