rails - created_at when user for ordering, Should you add an Index to the table?

前端 未结 3 1225
萌比男神i
萌比男神i 2021-02-01 21:24

Hello for one of my models photos I have:

default_scope :order => \'photos.created_at DESC, photos.version DESC\'

Given that I\'m ordering b

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 21:50

    One trick that may be helpful: in typical MySql/ActiveRecord models, you will have id as a numeric primary key (hence implicitly indexed), which should be in the same order of created_at - which means you could order by id instead and get the fast performance, without the write cost for an extra index.

提交回复
热议问题