default_scope习惯于不按 ID 排序记录会显着降低 Rails 应用程序的速度吗?
例如,我有一个使用 PostgreSQL 的 Rails(当前为 3.1)应用程序,其中几乎每个模型都有一个default_scope按其名称命名的排序记录:
default_scope order('users.name')
现在因为default_scope's order records by namerather by ID,我担心在运行正常查询时我可能会招致显着的性能损失。 例如:
User.find(5563401)
或者
@User.where('created_at = ?', 2.weeks.ago)
或者
User.some_scope_sorted_best_by_id.all
default_scope在上面的示例中,在我的模型上使用by可能会导致什么性能损失name?我应该担心这会default_scope影响应用程序性能吗?