gpt4 book ai didi

ruby-on-rails - Rails 排序或排序查询很慢

转载 作者:行者123 更新时间:2023-12-02 04:49:32 24 4
gpt4 key购买 nike

使用 Rails 3.2、Ruby 1.9、will_paginate。我有 100,000 条记录,并测试了以下查询:

# 1000+ms to load
@shops = Shop.where(:shop_type => @type).paginate(:include => :photos, :page => params[:page], :per_page => 25, :order => 'created_at DESC')

# 1000+ms to load
@shops = Shop.paginate(:include => :photos, :page => params[:page], :per_page => 25, :order => 'created_at DESC')

# 1000+ms to load
@shops = Shop.order('created_at DESC').limit(25)

# 1+ms to load
@shops = Shop.paginate(:include => :photos, :page => params[:page], :per_page => 25)

我注意到 order 选项非常慢。测试结果表明will_paginate没有问题。

我应该如何更改它,以便可以加快使用 order 的查询。

最佳答案

是的,尝试在订单列上创建索引。它会加快速度。

关于ruby-on-rails - Rails 排序或排序查询很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com