Commit 609a434c authored by Stan Hu's avatar Stan Hu

Adding missing indexes on taggings table

API requests were timing out because `tag_id` was missing an index. These
migrations were imported by running https://github.com/mbleigh/acts-as-taggable-on#post-installation:

```
bundle exec rake acts_as_taggable_on_engine:install:migrations
```

It looks like the `acts-as-tagglable` gem added the indexes in v4.0.0, but
when we upgraded from v3.5.0 (back in 2016 via
f571aeb5) we did not add them.

On staging, there are about 10.7 million rows on the `taggings` table. It took about 30 seconds for each index to be created.

On production, there are about 17.4 million rows, so I suspect the time to be about a minute per index.

Closes #43927
parent 7734e85b
---
title: Adding missing indexes on taggings table
merge_request:
author:
type: performance
# This migration comes from acts_as_taggable_on_engine (originally 6)
#
# It has been modified to handle no-downtime GitLab migrations. Several
# indexes have been removed since they are not needed for GitLab.
class AddMissingIndexesActsAsTaggableOnEngine < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :taggings, :tag_id unless index_exists? :taggings, :tag_id
add_concurrent_index :taggings, [:taggable_id, :taggable_type] unless index_exists? :taggings, [:taggable_id, :taggable_type]
end
def down
remove_concurrent_index :taggings, :tag_id
remove_concurrent_index :taggings, [:taggable_id, :taggable_type]
end
end
...@@ -1733,7 +1733,9 @@ ActiveRecord::Schema.define(version: 20180307012445) do ...@@ -1733,7 +1733,9 @@ ActiveRecord::Schema.define(version: 20180307012445) do
end end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id", using: :btree
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
add_index "taggings", ["taggable_id", "taggable_type"], name: "index_taggings_on_taggable_id_and_taggable_type", using: :btree
create_table "tags", force: :cascade do |t| create_table "tags", force: :cascade do |t|
t.string "name" t.string "name"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment