我一直在使用以下查询一段时间,但随着结果数据库的增长,它变得缓慢到无法使用的程度。任何人都可以提出另一种方法吗?
我在 c.name 和 r.scope 上有全文索引
SELECT * FROM results r
INNER JOIN categories c on r.id = c.result_id
INNER JOIN tags t on r.id = t.result_id
WHERE c.name in ('purchase', 'single_family', 'other')
AND ( r.scope = 'all' OR r.scope = 'hi' )
AND published = 1
GROUP BY r.id
HAVING COUNT(c.c_id) >= 3
ORDER BY r.usefulness DESC
LIMIT 8 OFFSET 0
任何帮助将非常感激。谢谢!
编辑:这是解释的结果
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE c range nameindex,name nameindex 767 NULL 10036 Using where; Using temporary; Using filesort
1 SIMPLE t ALL NULL NULL NULL NULL 10229 Using where; Using join buffer
1 SIMPLE r eq_ref PRIMARY,scope PRIMARY 4 rfw.t.result_id 1 Using where