I would like to suggest improving the indices on the follow_links table.

Currently, the indices on the table are:

 'primary key' => array('lid'),
    'unique keys' => array(
      'uid_name' => array('uid', 'name'),
    ),

With the current indices, mysql has to do a filesort:
mysql> explain SELECT * FROM follow_links WHERE uid = 0 ORDER BY weight ASC;

| id | select_type | table        | partitions | type | possible_keys | key      | key_len | ref   | rows | filtered | Extra                                 |
|  1 | SIMPLE      | follow_links | NULL       | ref  | uid_name      | uid_name | 4       | const |   10 |   100.00 | Using index condition; Using filesort |

The select query on follow_links table can be optimized by adding a new index.

mysql> ALTER TABLE `follow_links` ADD INDEX `uid_weight` (`uid`, `weight`);
mysql> explain SELECT * FROM follow_links WHERE uid = 0 ORDER BY weight ASC;
| id | select_type | table        | partitions | type | possible_keys       | key        | key_len | ref   | rows | filtered | Extra                 |
|  1 | SIMPLE      | follow_links | NULL       | ref  | uid_name,uid_weight | uid_weight | 4       | const |   10 |   100.00 | Using index condition |
CommentFileSizeAuthor
#2 optimizeSelectQuery-2907184-1.patch763 byteskarolinam

Comments

karolinam created an issue. See original summary.

karolinam’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new763 bytes

Here is the patch which adds the uid_weight index.

karolinam’s picture

Assigned: karolinam » Unassigned
karolinam’s picture

Issue tags: +Performance, +db
fengtan’s picture

+1, patch looks good

astonvictor’s picture

Status: Needs review » Closed (outdated)

D7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.