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

are the fk_follows and fk_followables indexes needed? #97

Open
clairity opened this issue May 18, 2017 · 0 comments
Open

are the fk_follows and fk_followables indexes needed? #97

clairity opened this issue May 18, 2017 · 0 comments

Comments

@clairity
Copy link

clairity commented May 18, 2017

i am going through my codebase and cleaning up extraneous indexes and wondered if the fk_follows and fk_followables indexes are needed? i ask because the migration already creates two indexes

  1. index_follows_on_followable_type_and_followable_id
  2. index_follows_on_follower_type_and_follower_id

as defined implicitly by these polymorphic references:

class ActsAsFollowerMigration < ActiveRecord::Migration
  def self.up
    create_table :follows, force: true do |t|
      t.references  :followable,  polymorphic: true,  null: false
      t.references  :follower,    polymorphic: true,  null: false
     
      ...

    end
  end

  ...
     
end

so are these two additional indexes required?

class ActsAsFollowerMigration < ActiveRecord::Migration
  def self.up
    create_table :follows, force: true do |t|
      ...
    end

    add_index :follows, ["follower_id", "follower_type"],     name: "fk_follows"
    add_index :follows, ["followable_id", "followable_type"], name: "fk_followables"
  end

  ...

end

the main difference is the order of the index elements:

  1. [:follower_type, :follower_id] rather than [:follower_id, :follower_type]
  2. [:followable_type, :followable_id] rather than [:followable_id, :followable_type]

if these two defined indexes are indeed required, then are the implicitly created ones needed? not a huge deal, but i'd thought i'd ask since i couldn't find an answer elsewhere. thanks!

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

1 participant