• Resolved letutudanza

    (@letutudanza)


    Hi,

    I’m experiencing a severe performance problem caused by a query generated by Ultimate Member. It takes 60–67 seconds to run and examines over 33 million rows in wp_usermeta, even though my database is small and clean.

    Environment / data context:

    • About 8,000 users
    • wp_usermeta has only ~400,000 rows
    • 0 orphaned usermeta rows
    • The standard indexes on user_id and meta_key are present and used
    • Site also runs WooCommerce (HPOS enabled). Many users are WooCommerce customers with an empty account_status.

    The problem seems structural rather than data-related: the query uses SELECT DISTINCT SQL_CALC_FOUND_ROWS and multiple LEFT JOINs on the same wp_usermeta table where some joins (mt1, mt3) have no meta_key condition in the JOIN clause. This produces a combinatorial explosion (≈50 meta × 50 meta per user × thousands of users), which is what drives the 33M examined rows.

    Here are two entries from my slow query log:

    # Query_time: 60.907194  Rows_sent: 1  Rows_examined: 33880686
    SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_users.ID
    FROM wp_users
    LEFT JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id AND wp_usermeta.meta_key = '_um_registration_in_progress' )
    LEFT JOIN wp_usermeta AS mt1 ON ( wp_users.ID = mt1.user_id )
    LEFT JOIN wp_usermeta AS mt2 ON ( wp_users.ID = mt2.user_id AND mt2.meta_key = 'account_status' )
    LEFT JOIN wp_usermeta AS mt3 ON ( wp_users.ID = mt3.user_id )
    WHERE 1=1 AND (
      ( wp_usermeta.user_id IS NULL OR ( mt1.meta_key = '_um_registration_in_progress' AND mt1.meta_value != '1' ) )
      AND
      ( mt2.user_id IS NULL OR ( mt3.meta_key = 'account_status' AND mt3.meta_value = '' ) )
    )
    ORDER BY user_login ASC
    LIMIT 0, 50;
    
    # Query_time: 67.558859  Rows_sent: 0  Rows_examined: 33886516
    (identical query)

    Questions:

    1. What page/function in UM triggers this query? It appears related to counting/listing users by account status.
    2. Is there a way to make the mt1 and mt3 joins include the meta_key in the JOIN condition (or otherwise avoid the unindexed self-joins) so MySQL doesn’t explode the row count?
    3. Is SELECT DISTINCT SQL_CALC_FOUND_ROWS still required here, given it’s a known performance bottleneck?
    4. Is there a recommended setting or workaround (e.g. user cache) to prevent this query from running on admin pages?

    I’m running the latest version of Ultimate Member. Any guidance would be appreciated. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • missveronica

    (@missveronicatv)

    @letutudanza

    You can try the “Index WP MySQL For Speed” plugin.

    https://wordpress.org/plugins/index-wp-mysql-for-speed/

    Have you enabled the “Custom usermeta table” to remove Directory searches from the default WP metadata table?

    https://docs.ultimatemember.com/article/1541-meta-table-for-member-directories

    Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @letutudanza

    The plugin uses this query to search users with incorrect data (empty account status) and then fix (approve) them. The plugin runs this task asynchronously via the action scheduler so as not to affect the site’s performance.

    There is no way to change the SELECT and JOIN statements in this query because it is built via the native WP_User_Query class.

    You can disable the status check tool if you are confident that all users on your website have correct statuses. The plugin automatically sets a user status on registration. This tool is needed for a case of user importing or using third-party plugins for registration.

    If you want to disable this tool, use the code snippet below. Add this code snippet to the functions.php file in the child theme directory.

    // disable status check.
    if ( function_exists( 'UM' ) ) {
    remove_action( 'init', array( UM()->classes['um\common\actions\users'], 'add_recurring_action' ) );
    }

    You may need to remove scheduled actions um_schedule_empty_account_status_check and um_set_default_account_status on wp-admin > Tools > Scheduled Actions.

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @letutudanza

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.