新手问题 加 Index 对范围搜索有帮助吗?

cqcn1991 · 2015年05月23日 · 最后由 azhao 回复于 2015年05月23日 · 1298 次阅读

比如,我会用到这样的方法来提取内容

scope :best_of_the_week, ->(time) do
   start_time = time.beginning_of_week
   end_time = time.end_of_week
   where("created_at > ? AND created_at < ?", start_time, end_time).where('votes_count > ?', 300).order('votes_count DESC').first(8)
 end

不知道加 index 有没有帮助?

另外,想问下可以把两个where合并起来么?会不会好一点?

#1 楼 @hooooopo 我自己的试了下,效果是没有...

vote_count 经常变化吧,加 index 不划算

试一下 加一个 created_at 和 vote_count 的联合索引

需要 登录 后方可回复, 如果你还没有账号请 注册新账号