From bc2e342837863b191ef334d5405a005ed82865b0 Mon Sep 17 00:00:00 2001
From: Yannis Roussos <iroussos@gitlab.com>
Date: Tue, 13 Apr 2021 15:42:23 +0300
Subject: [PATCH] Add index on web_hook_id to partitioned web_hook_logs

---
 ...b-hook-id-to-partitioned-web-hook-logs.yml |  5 +++++
 ...web_hook_id_to_partitioned_web_hook_log.rb | 21 +++++++++++++++++++
 db/schema_migrations/20210413123832           |  1 +
 db/structure.sql                              |  2 ++
 4 files changed, 29 insertions(+)
 create mode 100644 changelogs/unreleased/323676-add-index-on-web-hook-id-to-partitioned-web-hook-logs.yml
 create mode 100644 db/migrate/20210413123832_add_index_on_web_hook_id_to_partitioned_web_hook_log.rb
 create mode 100644 db/schema_migrations/20210413123832

diff --git a/changelogs/unreleased/323676-add-index-on-web-hook-id-to-partitioned-web-hook-logs.yml b/changelogs/unreleased/323676-add-index-on-web-hook-id-to-partitioned-web-hook-logs.yml
new file mode 100644
index 0000000000000..eb9b3dbf088bf
--- /dev/null
+++ b/changelogs/unreleased/323676-add-index-on-web-hook-id-to-partitioned-web-hook-logs.yml
@@ -0,0 +1,5 @@
+---
+title: Add index on web_hook_id to partitioned web_hook_logs
+merge_request: 59266
+author:
+type: other
diff --git a/db/migrate/20210413123832_add_index_on_web_hook_id_to_partitioned_web_hook_log.rb b/db/migrate/20210413123832_add_index_on_web_hook_id_to_partitioned_web_hook_log.rb
new file mode 100644
index 0000000000000..300c19d3e51fd
--- /dev/null
+++ b/db/migrate/20210413123832_add_index_on_web_hook_id_to_partitioned_web_hook_log.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddIndexOnWebHookIdToPartitionedWebHookLog < ActiveRecord::Migration[6.0]
+  include Gitlab::Database::PartitioningMigrationHelpers
+
+  DOWNTIME = false
+
+  WEB_HOOK_ID_INDEX_NAME = 'index_web_hook_logs_part_on_web_hook_id'
+
+  disable_ddl_transaction!
+
+  def up
+    add_concurrent_partitioned_index :web_hook_logs_part_0c5294f417,
+      :web_hook_id,
+      name: WEB_HOOK_ID_INDEX_NAME
+  end
+
+  def down
+    remove_concurrent_partitioned_index_by_name :web_hook_logs_part_0c5294f417, WEB_HOOK_ID_INDEX_NAME
+  end
+end
diff --git a/db/schema_migrations/20210413123832 b/db/schema_migrations/20210413123832
new file mode 100644
index 0000000000000..4a8af15f33654
--- /dev/null
+++ b/db/schema_migrations/20210413123832
@@ -0,0 +1 @@
+d166250305c2939bea8cc1970faf50d86776d32270a80a429cce668a97280aad
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 5d0ca31e91f58..947f0e649e110 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -24258,6 +24258,8 @@ CREATE INDEX index_web_hook_logs_on_created_at_and_web_hook_id ON web_hook_logs
 
 CREATE INDEX index_web_hook_logs_on_web_hook_id ON web_hook_logs USING btree (web_hook_id);
 
+CREATE INDEX index_web_hook_logs_part_on_web_hook_id ON ONLY web_hook_logs_part_0c5294f417 USING btree (web_hook_id);
+
 CREATE INDEX index_web_hooks_on_group_id ON web_hooks USING btree (group_id) WHERE ((type)::text = 'GroupHook'::text);
 
 CREATE INDEX index_web_hooks_on_project_id ON web_hooks USING btree (project_id);
-- 
GitLab