masciugo / genealogy

Make ActiveRecord model act as a pedigree
MIT License
30 stars 17 forks source link

Please clarify how to best add indexes #16

Open TommyByrne opened 8 years ago

TommyByrne commented 8 years ago

Hi there!

Thanks for this gem. I'm a bit confused how to best add indexes to my project though. Specifically how to do the "in combination" part. You say:

Add indexes, separately and in combination, to parents columns

And I have this so far:

class AddIndexToPeople < ActiveRecord::Migration
  def change
    add_index :people, :father_id
    add_index :people, :mother_id
    add_index :people, :current_spouse_id
    add_index :people, [:father_id, :mother_id]
  end
end

I'm not sure about that last one though. Can you help fill in the missing blanks for me? Thanks!

masciugo commented 8 years ago

Hi

if you plan to look for both parents your last index is a good idea. If I don't go worng, consider that, for mysql, if you add your last composite index you get your first index for free, so there should be no need to define it again:

http://dev.mysql.com/doc/refman/5.7/en/multiple-column-indexes.html (third paragraph)