开发者社区> 问答> 正文

如何建立该语句的索引方可以避免UsingtemporaryUsingfilesort

问题语句如下

mysql> explain SELECT b.brand_id, b.brand_name, COUNT(*) AS goods_num FROM `hcsyw`.`ecs_brand`AS b, `hcsyw`.`ecs_goods` AS g   WHERE g.brand_id = b.brand_id AND g.cat_id='1671'  AND b.is_show = 1  AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY b.sort_order, b.brand_id ASC;
+----+-------------+-------+--------+-------------------------------------------------------+---------+---------+------------------+------+----------------------------------------------+
| id | select_type | table | type   | possible_keys                                         | key     | key_len | ref              | rows | Extra                                        |
+----+-------------+-------+--------+-------------------------------------------------------+---------+---------+------------------+------+----------------------------------------------+
|  1 | SIMPLE      | g     | ref    | cat_id,brand_id,idx_catid_isdel_ison,idx_sal_sort_gid | cat_id  | 2       | const            | 1826 | Using where; Using temporary; Using filesort |
|  1 | SIMPLE      | b     | eq_ref | PRIMARY,is_show                                       | PRIMARY | 2       | hcsyw.g.brand_id |    1 | Using where                                  |
+----+-------------+-------+--------+-------------------------------------------------------+---------+---------+------------------+------+----------------------------------------------+
2 rows in set (0.00 sec)

展开
收起
yuantel 2014-12-23 17:52:17 7856 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
RowKey与索引设计:技巧与案例分析 立即下载
Phoenix 全局索引原理与实践 立即下载
低代码开发师(初级)实战教程 立即下载