我有一个查询
SELECT DISTINCT t1.country
FROM table2 t2
JOIN table3 t3
ON t2.table3_id = t3.id
JOIN table4 t4
ON t3.table4_id = t4id
LEFT
JOIN table1 t1
ON t1.table2_id = t2.id
WHERE t2.type IN ('Some')
AND t4.locale_id = 11
AND t1.table2_id IS NOT NULL
AND t1.country IS NOT NULL
AND t1.country != ''
ORDER
BY t1.country ASC
当我删除Distinct并命令它在mysql控制台中运行得更快时,但是当我通过Rails ActiveRecord运行它时,它却同时工作:
ActiveRecord::Base.connection.execute(query)
所以我有两个问题。 首先也是主要的-为什么优化未在Rails Environment中产生? 第二-您知道如何进一步加快查询速度吗?