I am using Rails and postgres.
I have a couple of models using STI and i was wondering where i should put indexes on the tables and why?
For example lets say i have the following setup:
class Comment < AR; end
class MovieComment < Comment; end
class MagazineComment < Comment; end
# Fake Comment Table
id:integer
title:string
body:text
type:string
Thanks!
On the
typefield, if you want only one ofMovieCommentorMagazineComment. If you don’t do that, you won’t need the index here. I’m not sure if AR does usetypeevery time, but just to make sure.Because the
idfield is a primary key, an index should already be there.If you want to query by both
typeandidmake sure you have a combined index.On the other fields: Depends what you query on, but I suppose you want to retrieve these only.