Skip to content
This repository

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

wants to merge 1 commit into from

5 participants

Tanel Suurhans Benjamin Fleischer Artem Kramarenko Joost Baaij Branden Gunn
Tanel Suurhans

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

Benjamin Fleischer
bf4 commented

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'

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

see and

Artem Kramarenko artemk closed this
Artem Kramarenko

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

Benjamin Fleischer
bf4 commented

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

Joost Baaij

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

Benjamin Fleischer bf4 referenced this pull request

Add missing unique indices #343

Branden Gunn

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

Showing 1 unique commit by 1 author.

Oct 08, 2012
Tanel Suurhans Create the the index on all four used fields for better performance bfe33a3
This page is out of date. Refresh to see the latest.
2  lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
@@ -20,7 +20,7 @@ def self.up
20 20 end
21 21
22 22 add_index :taggings, :tag_id
23   - add_index :taggings, [:taggable_id, :taggable_type, :context]
  23 + add_index :taggings, [:taggable_id, :taggable_type, :tag_id, :context], :name => "index_taggings_on_keys"
24 24 end
25 25
26 26 def self.down

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.