Optimize select query

Created on 7 September 2017, about 8 years ago
Updated 20 October 2025, 2 days ago

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 |
📌 Task
Status

Closed: outdated

Version

2.0

Component

Code

Created by

🇨🇦Canada karolinam

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024