我在表ads
和make
之间有一个简单的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
答案 0 :(得分:0)
`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秒内运行