最近遇到这个问题:
- mysql> explain select * from tb_province where name='lucy' order by score ;
- +----+-------------+-------------+------------+------+---------------+------+---------+-------+-------+----------+---------------------------------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+-------------+-------------+------------+------+---------------+------+---------+-------+-------+----------+---------------------------------------+
- | 1 | SIMPLE | tb_province | NULL | ref | g | g | 34 | const | 54390 | 100.00 | Using index condition; Using filesort |
- +----+-------------+-------------+------------+------+---------------+------+---------+-------+-------+----------+---------------------------------------+
- 1 row in set, 1 warning (0.00 sec)
- ————————————————
查询性能不达标,一看就知道是没有联合索引,导致order by有了filesort
加上联合索引后,问题解决了。