Hello for one of my models photos I have:
default_scope :order => 'photos.created_at DESC, photos.version DESC'
Given that I'm ordering by CREATED_AT and Version... Should I have a DB index on CREATED_AT?
Thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With