So as I was following the Ruby on Rails Tutorial by Michael Hartl I noticed that in the users table we added a unique index for the :email
attribute to improve the efficiency of the find
method so it doesn't search row by row. So far we have been searching using both find_by_email
and find_by_id
depending on the case. Yet we never set up an index for the :id
attribute. Is :id
automatically indexed because it is by default unique and sequential in nature? Or is this not the case and should I add an index for :id
searching?
Asked
Active
Viewed 2,069 times
5

Kvass
- 8,294
- 12
- 65
- 108
1 Answers
10
Most databases (sqlite included, which is the default db in RoR) automatically index the primary key, which with Rails Migrations is :id
by default.

smcphill
- 816
- 5
- 13