STRAIGHT_JOIN优化坑爹SQL(二)

2015-07-24 10:17:18 · 作者: · 浏览: 15
2', '2.1.1', '2.1', '1.7.1', '1.6.4.1', '1.6.3', '1.6.2', '1.6.1.1', '1.6.1', '1.5.4', '1.5.3', '1.5.2', '1.5.1'
)order by d.device_id limit 0, 30000;

+----+-------------+-------+------+--------------------------------------------------------------------+---------------------+---------+----------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+--------------------------------------------------------------------+---------------------+---------+----------------+-------+----------------------------------------------+
| 1 | SIMPLE | u | ref | user_group_id | user_group_id | 4 | const | 188 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | d | ref | idx_userid,idx_app_status,idx_appname_deviceid,idx_encrypt_user_id | idx_encrypt_user_id | 303 | mpms.u.user_id | 72489 | Using where |
+----+-------------+-------+------+--------------------------------------------------------------------+---------------------+---------+----------------+-------+----------------------------------------------+

执行计划看似 STRAIGHT_JOIN要慢N个数量级.

但实际执行起来.

第一条SQL需要十多秒.

第二条STRAIGHT_JOIN仅0.01秒 就飞出来了.

当然,,要先确保驱动表的数据趋势..