I am seeing query execution times of 1.5 seconds on this query that is coming out of devel.module line 699, where it gets the list of users to switch:

SELECT DISTINCT u.uid, u.name, u.access FROM users u LEFT JOIN users_roles r ON u.uid = r.uid WHERE (u.uid = 1 OR r.rid IN (6)) AND u.status > 0 ORDER BY u.access

This probably appears with large users tables. Our users table has 200k + rows.
Changing to an INNER JOIN makes it fast again (0.032sec), but that can exclude uid=1 under certain circumstances.
I recommend using UNION to include uid 1. Does that sound good?

      $where = '';          
      if (count($roles)) {                                                           
        $where = 'r.rid IN ('. implode(',', array_keys($roles)) .')';              
      }                                                                              
      $accounts = db_query_range("(SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE ($where) AND u.status > 0) UNION (SELECT u.uid, u.name, u.access FROM {users} u WHERE uid = 1) ORDER BY access DESC", 0, $list_size);
CommentFileSizeAuthor
#1 devel_slow_query.patch1.5 KBrares
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rares’s picture

Status: Active » Needs review
FileSize
1.5 KB

Status: Needs review » Needs work

The last submitted patch, devel_slow_query.patch, failed testing.

salvis’s picture

Interesting observation...

Patches in contrib need to be relative to the contrib's directory.

All fixes (if this needs to be fixed) must go to D8 first and then be backported.

You have a huge number of trailing spaces in your patch. Please fix your editor settings.

pcambra’s picture

Version: 6.x-1.x-dev » 8.x-1.x-dev
willzyx’s picture

Issue summary: View changes
Status: Needs work » Closed (duplicate)

Closing as duplicated of #2624370: Increase query performance of devel_switch_user_list. Feel free to reopen if you think that this is a separate issue