Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Create the the index on all four used fields for better performance #294

Closed
wants to merge 1 commit into from

5 participants

@tanelsuurhans

Related to issue #293 - creates the index on all use fields instead of three. This improves the joins tremendously.

@bf4
Collaborator

The unique indices migration change from the generated migration should be

def self.up
  add_index :tags, :name, unique: true
  add_index :taggings, [:tag_id, :taggable_type, :taggable_id, :context, :tagger_id, :tagger_type], unique: true, name: 'tagging_idx'
end

def self.down
  remove_index :tags, :name
  remove_index :taggings, name: 'tagging_idx'
end

see https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/tag.rb#L14 and https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/tagging.rb#L20

@artemk
Collaborator

you can add indexes if you need it. Some would prefere to not have ones.

@artemk artemk closed this
@bf4
Collaborator

I'm curious why? Since the app enforces uniquness, shouldn't the database as well?

@tilsammans
Collaborator

@bf4 yes, I think so. Care to submit a pull request?

@bf4 bf4 referenced this pull request
Merged

Add missing unique indices #343

@engunneer

At a minimum, please bring the :name portion over from this pull request. I have to use a table prefix, so the current index name that is auto generated in the migration is over 64 chars. The :name field in the migration mitigates this issue.

thanks Tanel for this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 8, 2012
This page is out of date. Refresh to see the latest.
View
2  lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
@@ -20,7 +20,7 @@ def self.up
end
add_index :taggings, :tag_id
- add_index :taggings, [:taggable_id, :taggable_type, :context]
+ add_index :taggings, [:taggable_id, :taggable_type, :tag_id, :context], :name => "index_taggings_on_keys"
end
def self.down
Something went wrong with that request. Please try again.