In general, you need indices in the columns that you will use when performing queries.
If you do MovieComment.find(10)
, the database will use the index in the id
field that Rails will add automatically for you. Same if you do Comment.find(30)
: Rails will retrieve the commend with id
30 using the index, then it will read the type
column and it will return a MovieComment
or a MagazineComment
.
If you are going to add a feature to search by title, for instance, you will have to create an index in this column as well. In this case, probably a :fulltext index.
An Index in the type
column would make a query like MagazineComment.all
faster because it is equivalent to Comment.where(type: 'MagazineComment').all
, but it is probably not worth it.