summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2019-08-16 20:02:19 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-08-16 20:02:19 +0000
commit504ed1c4a44f3b86ce2ce1a545236c8c0f84c17f (patch)
treeceff26a333dfa7c4c8481781adbc4190143909d6
parentb0a230daedd99b5a7b41ddf544c66a6ed57adefc (diff)
parenta3e716104a3d1189de8a22a8a3ea9a67d66baea2 (diff)
downloadgitlab-ce-504ed1c4a44f3b86ce2ce1a545236c8c0f84c17f.tar.gz
Merge branch 'optimize-note-indexes' into 'master'
Optimize DB indexes for ES indexing of notes See merge request gitlab-org/gitlab-ce!31846
-rw-r--r--changelogs/unreleased/optimize-note-indexes.yml5
-rw-r--r--db/migrate/20190815093936_add_index_notes_on_project_id_and_id_and_system_false.rb30
-rw-r--r--db/migrate/20190815093949_remove_index_notes_on_noteable_type.rb29
-rw-r--r--db/schema.rb4
4 files changed, 66 insertions, 2 deletions
diff --git a/changelogs/unreleased/optimize-note-indexes.yml b/changelogs/unreleased/optimize-note-indexes.yml
new file mode 100644
index 00000000000..bfb84779abf
--- /dev/null
+++ b/changelogs/unreleased/optimize-note-indexes.yml
@@ -0,0 +1,5 @@
+---
+title: Optimize DB indexes for ES indexing of notes
+merge_request: 31846
+author:
+type: performance
diff --git a/db/migrate/20190815093936_add_index_notes_on_project_id_and_id_and_system_false.rb b/db/migrate/20190815093936_add_index_notes_on_project_id_and_id_and_system_false.rb
new file mode 100644
index 00000000000..cbbece35901
--- /dev/null
+++ b/db/migrate/20190815093936_add_index_notes_on_project_id_and_id_and_system_false.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class AddIndexNotesOnProjectIdAndIdAndSystemFalse < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(*index_arguments)
+ end
+
+ def down
+ remove_concurrent_index(*index_arguments)
+ end
+
+ private
+
+ def index_arguments
+ [
+ :notes,
+ [:project_id, :id],
+ {
+ name: 'index_notes_on_project_id_and_id_and_system_false',
+ where: 'NOT system'
+ }
+ ]
+ end
+end
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
diff --git a/db/schema.rb b/db/schema.rb
index cf7f0fc0a3d..fafaec3fb51 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_12_070645) do
+ActiveRecord::Schema.define(version: 2019_08_15_093949) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -2279,7 +2279,7 @@ ActiveRecord::Schema.define(version: 2019_08_12_070645) do
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 ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type"
- t.index ["noteable_type"], name: "index_notes_on_noteable_type"
+ t.index ["project_id", "id"], name: "index_notes_on_project_id_and_id_and_system_false", where: "(NOT system)"
t.index ["project_id", "noteable_type"], name: "index_notes_on_project_id_and_noteable_type"
t.index ["review_id"], name: "index_notes_on_review_id"
end