summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-09-10 12:38:15 +0200
committerAndreas Brandl <abrandl@gitlab.com>2019-09-12 15:28:27 +0200
commitc98e5d920f453e8d2b22c2878d8dcd15dcd7cf36 (patch)
treef0354a9396567e86d11179fe515db875859b56eb
parent0844ec02f2a6dde9e7fdcf53f4f02cc3547ac960 (diff)
downloadgitlab-ce-ab/partial-events-index.tar.gz
Replace events index with partial oneab/partial-events-index
This improves the index size by removing all records with `group_id` from the index. On GitLab.com this means reducing the size from 9 GB to 8kb (as long as the column stays mostly null). Relates to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/32826#note_214690051
-rw-r--r--changelogs/unreleased/ab-partial-events-index.yml5
-rw-r--r--db/migrate/20190910103144_replace_events_index_on_group_id_with_partial_index.rb19
-rw-r--r--db/schema.rb2
3 files changed, 25 insertions, 1 deletions
diff --git a/changelogs/unreleased/ab-partial-events-index.yml b/changelogs/unreleased/ab-partial-events-index.yml
new file mode 100644
index 00000000000..f68b0862c6b
--- /dev/null
+++ b/changelogs/unreleased/ab-partial-events-index.yml
@@ -0,0 +1,5 @@
+---
+title: Replace events index with partial one
+merge_request: 32874
+author:
+type: performance
diff --git a/db/migrate/20190910103144_replace_events_index_on_group_id_with_partial_index.rb b/db/migrate/20190910103144_replace_events_index_on_group_id_with_partial_index.rb
new file mode 100644
index 00000000000..40a7454fd20
--- /dev/null
+++ b/db/migrate/20190910103144_replace_events_index_on_group_id_with_partial_index.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class ReplaceEventsIndexOnGroupIdWithPartialIndex < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(:events, :group_id, where: 'group_id IS NOT NULL', name: 'index_events_on_group_id_partial')
+ remove_concurrent_index_by_name(:events, 'index_events_on_group_id')
+ end
+
+ def down
+ add_concurrent_index(:events, :group_id, name: 'index_events_on_group_id')
+ remove_concurrent_index_by_name(:events, 'index_events_on_group_id_partial')
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 39faf1e651e..71249a1e56c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1321,7 +1321,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
t.index ["action"], name: "index_events_on_action"
t.index ["author_id", "project_id"], name: "index_events_on_author_id_and_project_id"
t.index ["created_at", "author_id"], name: "analytics_index_events_on_created_at_and_author_id"
- t.index ["group_id"], name: "index_events_on_group_id"
+ t.index ["group_id"], name: "index_events_on_group_id_partial", where: "(group_id IS NOT NULL)"
t.index ["project_id", "created_at"], name: "index_events_on_project_id_and_created_at"
t.index ["project_id", "id"], name: "index_events_on_project_id_and_id"
t.index ["target_type", "target_id"], name: "index_events_on_target_type_and_target_id"