MySQL:加速两个表的连接

MySQL:加速两个表的连接,mysql,Mysql,我有一个简单的查询连接,在表ads和make之间,表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

我有一个简单的查询连接,在表
ads
make
之间,表
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

好吧,我不知道为什么这比加入更有效

`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秒

是的。清空桌子!这会加快行动,但更重要的是。你应该检查
explain
你有没有试着把
explain
放在它前面,看看什么东西慢?是否为
t2。是否为
编制索引?
t.make\u id
索引了吗?
t2.id
索引了吗?
t.pending
索引了吗?另外,您是按计数排序的,因此如果您有很多结果(您需要在执行限制之前进行排序),这也会很昂贵。@Nanne一个包含
80
行的文件/内存排序不应该是问题(他是按
t2.make
进行分组的)。OP:关于您的解释,您可以看到它对
t
使用了什么文件排序,因为您的列没有索引。索引
t.pending
t.make\u id
@h2oooooo更新的问题,包括
解释
结果