I run a Rails app with postgresql as a database. I do a lot of joined searches and the queries tend to be quite slow. I don't quite understand if it just the nature of joined searches that makes the queries slow or if I have failed to make an accurate index for them.
Example (my queries are usually more complex but this shows what I mean):
Product belongs_to :store
Store has_many :products
Store.is_open :boolean
Product.has_image :boolean
I make queries like:
Store.where(:is_open => true).products.where(:has_image => true)
Do I:
Make indexes only Store and Product exclusively like:
add_index :stores, :is_open add_index :products, :has_image
This is what I do now.
OR
- Can I make a joined index that includes both tables?