MySQL:加速2个表的连接

时间:2015-01-09 09:56:50

标签: mysql

我在表adsmake之间有一个简单的JOIN ON查询,表ads有大约71k行,make只有80.

但是下面这个简单的查询平均需要0.98-1.1秒。反正有加速吗?

SELECT t2.*, COUNT(*) AS count
        FROM `ads` AS t
        JOIN (`make` AS t2)
        ON (t.make_id=t2.id)
        WHERE t.pending!=1
        GROUP BY t2.make
        ORDER BY `count` DESC
        LIMIT 24

更新

添加了EXPLAIN,我得到了这个

 id |   select_type  |  table | type    |   possible_keys | key    |    key_len |   ref      |  rows  | Extra   
 1  |   SIMPLE       | t2      |    ALL |   PRIMARY       | NULL   |    NULL    |   NULL     |  80     |    Using temporary; Using filesort

 1  |   SIMPLE       | t      | ref     |  pending,make_id| make_id|    1       |dev.t.make_id|     1010     |  Using where

1 个答案:

答案 0 :(得分:0)

好吧,我不知道为什么这比加入ON更好?

`SELECT t2.make, COUNT(t.make_id) AS Count
                                        FROM `ads` AS t, `make` AS t2
                                        WHERE t.make_id=t2.id AND t.pending!=1
                                        GROUP BY t.make_id
                                        ORDER BY Count DESC
                                        LIMIT 24`

但现在它在0.3秒内运行