Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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);
Comment | File | Size | Author |
---|---|---|---|
#1 | devel_slow_query.patch | 1.5 KB | rares |
Comments
Comment #1
rares CreditAttribution: rares commentedComment #3
salvisInteresting 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.
Comment #4
pcambraComment #5
willzyx CreditAttribution: willzyx commentedClosing 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