Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please clarify how to best add indexes #16

Open
TommyByrne opened this issue Mar 28, 2016 · 1 comment
Open

Please clarify how to best add indexes #16

TommyByrne opened this issue Mar 28, 2016 · 1 comment

Comments

@TommyByrne
Copy link

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
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants