Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Koller <mkoller@gitlab.com>2019-08-15 12:56:54 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2019-08-16 21:57:25 +0300
commita3e716104a3d1189de8a22a8a3ea9a67d66baea2 (patch)
treec42729435a8dfe3cab4cb1dbbbf0d24dd1e4475a /db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb
parentb7f191c5d025f95f5f343f43b24878c68b5c72b3 (diff)
Optimize DB indexes for ES indexing of notes
To index notes, we exclude system notes and use `find_in_batches` to load them in batches for submission to the ES bulk import API. These queries often result in DB timeouts because the usage of `ORDER BY id` results in the `notes_pkey` index being used. This adds an optimized partial index, and removes the unused index `index_notes_on_noteable_type` which is already covered for our usage by the existing `index_notes_on_noteable_id_and_noteable_type`. Newer versions of PostgreSQL (at least 11) are smarter about this and use `index_notes_on_project_id_and_noteable_type` instead, so we might be able to remove the partial index again in the future.
Diffstat (limited to 'db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb')
-rw-r--r--db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb b/db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb
new file mode 100644
index 00000000000..158c88e6258
--- /dev/null
+++ b/db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class RemoveIndexNotesOnNoteableType < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index(*index_arguments)
+ end
+
+ def down
+ add_concurrent_index(*index_arguments)
+ end
+
+ private
+
+ def index_arguments
+ [
+ :notes,
+ [:noteable_type],
+ {
+ name: 'index_notes_on_noteable_type'
+ }
+ ]
+ end
+end