MySQL查询语句执行过程及性能优化-查询过程及优化方法(JOIN/ORDER BY)(二)

2014-11-24 11:54:15 · 作者: · 浏览: 1
量使用第一张表所覆盖的索引进行排序,实在不行,可以把排序逻辑从MySQL中移到 PHP/ Java程序中执行
实施1、2、3的优化方法后,EXPLAIN结果如下:
[plain] 
mysql> explain select user.Username, user_profile.nickname, user_profile.gender, user_profile.meet_receive from user_profile join users on users.Id = user_profile.user_id where user_profile.`display` = '1' order by user_profile.fl_no limit 50;  
+----+-------------+---------------+--------+---------------+---------+---------+---------------------------------+------+--------------------------+  
| id | select_type | table         | type   | possible_keys | key     | key_len | ref                             | rows | Extra                    |  
+----+-------------+---------------+--------+---------------+---------+---------+---------------------------------+------+--------------------------+  
|  1 | SIMPLE      | user_profile1 | index  | NULL          | fl_no   | 4       | NULL                            |   50 | Using where              |  
|  1 | SIMPLE      | users         | eq_ref | PRIMARY       | PRIMARY | 8       | slowquery.user_profile1.user_id |    1 | Using where              |  
+----+-------------+---------------+--------+---------------+---------+---------+---------------------------------+------+--------------------------+  
2 rows in set (0.00 sec)  

备注:编写简单的PHP应用,用siege测试,查询效率提高>3倍。