Commit e722ab18 authored by Marc Shaw's avatar Marc Shaw Committed by Andreas Brandl

Add duplicated gin trigram index on notes note

We identified that the gin trigram index on notes (note)
can lead to very slow insert times on notes. It appears that
reindexing the index solves the problem. We have decided to
reindex it through migrations, first by creating a duplicate
index, then by dropping the old index.

Original MR thread: gitlab.com/gitlab-org/gitlab/-/issues/218410#note_565624409
Change MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/61430
parent fbc099e2
---
title: Add duplicated gin trigram index on notes table (note) to replace existing
merge_request: 61430
author:
type: performance
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class CreateIndexOnNotesNote < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DUPLICATE_INDEX_NAME = 'index_notes_on_note_gin_trigram'
CURRENT_INDEX_NAME = 'index_notes_on_note_trigram'
disable_ddl_transaction!
# https://gitlab.com/gitlab-org/gitlab/-/issues/218410#note_565624409
# We are having troubles with the index, and some inserts are taking a long time
# so in this migration we are recreating the index
def up
add_concurrent_index :notes, :note, name: DUPLICATE_INDEX_NAME, using: :gin, opclass: :gin_trgm_ops
remove_concurrent_index_by_name :notes, CURRENT_INDEX_NAME
end
def down
remove_concurrent_index_by_name :notes, DUPLICATE_INDEX_NAME
add_concurrent_index :notes, :note, name: CURRENT_INDEX_NAME, using: :gin, opclass: :gin_trgm_ops
end
end
2d11da499f49964f37cc0a2c541cf58182416ae7b6b0e762a135b327099de1a4
\ No newline at end of file
...@@ -23667,7 +23667,7 @@ CREATE INDEX index_notes_on_discussion_id ON notes USING btree (discussion_id); ...@@ -23667,7 +23667,7 @@ CREATE INDEX index_notes_on_discussion_id ON notes USING btree (discussion_id);
CREATE INDEX index_notes_on_line_code ON notes USING btree (line_code); CREATE INDEX index_notes_on_line_code ON notes USING btree (line_code);
CREATE INDEX index_notes_on_note_trigram ON notes USING gin (note gin_trgm_ops); CREATE INDEX index_notes_on_note_gin_trigram ON notes USING gin (note gin_trgm_ops);
CREATE INDEX index_notes_on_noteable_id_and_noteable_type_and_system ON notes USING btree (noteable_id, noteable_type, system); CREATE INDEX index_notes_on_noteable_id_and_noteable_type_and_system ON notes USING btree (noteable_id, noteable_type, system);
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