Can default_scope
when used to not order records by ID significantly slow down a Rails application?
For example, I have a Rails (currently 3.1) app using PostgreSQL where nearly every Model has a default_scope
ordering records by their name:
default_scope order('users.name')
Right now because the default_scope
's order records by name
rather by ID
, I am worried I might be incurring a significant performance penalty when normal queries are run. For example with:
User.find(5563401)
or
@User.where('created_at = ?', 2.weeks.ago)
or
User.some_scope_sorted_best_by_id.all
In the above examples, what performance penalty might I incur by having a default_scope
by name
on my Model? Should I be concerned about this default_scope
affecting application performance?