Commit d5d86e4d authored by Toon Claes's avatar Toon Claes

Merge branch 'create_single_temporary_index_for_notes_mentions' into 'master'

Create a single temporary index for note mentions migration

See merge request gitlab-org/gitlab!26307
parents 0b3b4a59 b6620986
---
title: Replace several temporary indexes with a single one to save time when running mentions migration
merge_request:
author:
type: performance
# frozen_string_literal: true
class AddTemporaryIndexForNotesWithMentions < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
INDEX_CONDITION = "note LIKE '%@%'::text"
INDEX_NAME = 'note_mentions_temp_index'
EPIC_MENTIONS_INDEX_NAME = 'epic_mentions_temp_index'
DESIGN_MENTIONS_INDEX_NAME = 'design_mentions_temp_index'
def up
# create temporary index for notes with mentions, may take well over 1h
add_concurrent_index(:notes, [:id, :noteable_type], where: INDEX_CONDITION, name: INDEX_NAME)
# cleanup previous temporary indexes, as we'll be usig the single one
remove_concurrent_index(:notes, :id, name: EPIC_MENTIONS_INDEX_NAME)
remove_concurrent_index(:notes, :id, name: DESIGN_MENTIONS_INDEX_NAME)
end
def down
remove_concurrent_index(:notes, :id, name: INDEX_NAME)
add_concurrent_index(:notes, :id, where: "#{INDEX_CONDITION} AND noteable_type='Epic'", name: EPIC_MENTIONS_INDEX_NAME)
add_concurrent_index(:notes, :id, where: "#{INDEX_CONDITION} AND noteable_type='DesignManagement::Design'", name: DESIGN_MENTIONS_INDEX_NAME)
end
end
......@@ -2840,8 +2840,7 @@ ActiveRecord::Schema.define(version: 2020_03_10_135823) do
t.index ["commit_id"], name: "index_notes_on_commit_id"
t.index ["created_at"], name: "index_notes_on_created_at"
t.index ["discussion_id"], name: "index_notes_on_discussion_id"
t.index ["id"], name: "design_mentions_temp_index", where: "((note ~~ '%@%'::text) AND ((noteable_type)::text = 'DesignManagement::Design'::text))"
t.index ["id"], name: "epic_mentions_temp_index", where: "((note ~~ '%@%'::text) AND ((noteable_type)::text = 'Epic'::text))"
t.index ["id", "noteable_type"], name: "note_mentions_temp_index", where: "(note ~~ '%@%'::text)"
t.index ["line_code"], name: "index_notes_on_line_code"
t.index ["note"], name: "index_notes_on_note_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["note"], name: "tmp_idx_on_promoted_notes", where: "(((noteable_type)::text = 'Issue'::text) AND (system IS TRUE) AND (note ~~ 'promoted to epic%'::text))"
......
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