【问题标题】:Does it make sense to add index for created_at column when it's used by scopes?在作用域使用时为 created_at 列添加索引是否有意义?
【发布时间】:2019-01-12 17:54:36
【问题描述】:

范围:

scope :last_ten_minutes, -> { where('created_at > ?', Time.current - 10.minutes) }
scope :last_week, -> { where('created_at > ?', Time.current - 7.days) }
scope :last_hundred_days, -> { where('created_at > ?', Time.current - 100.days) }

该模型在数据库中大约有 500 000 条记录。它们经常与分页结合使用,但只能从管理面板使用。

【问题讨论】:

标签: ruby-on-rails indexing


【解决方案1】:

当然,这是减少时间的最佳方式。还有更多,如果你有很多记录并且会定期使用,所以,你的问题的答案是肯定的,这是有道理的,是要走的路。

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多