diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 21:09:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 21:09:17 +0300 |
commit | 2516f0d87bf4504cf0d626a0584b2eebe459749b (patch) | |
tree | 52d1188485f7362da9d87b526e14e49be00fa9a1 /db | |
parent | 10052df7536415c192788799b294c9a5ecf07ce7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20210127143025_add_oldest_merge_requests_index.rb | 32 | ||||
-rw-r--r-- | db/schema_migrations/20210127143025 | 1 | ||||
-rw-r--r-- | db/structure.sql | 4 |
3 files changed, 37 insertions, 0 deletions
diff --git a/db/migrate/20210127143025_add_oldest_merge_requests_index.rb b/db/migrate/20210127143025_add_oldest_merge_requests_index.rb new file mode 100644 index 00000000000..acd690a5cce --- /dev/null +++ b/db/migrate/20210127143025_add_oldest_merge_requests_index.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class AddOldestMergeRequestsIndex < ActiveRecord::Migration[6.0] + include Gitlab::Database::SchemaHelpers + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + INDEX = 'index_on_merge_requests_for_latest_diffs' + + def up + return if index_exists_by_name?('merge_requests', INDEX) + + execute "CREATE INDEX CONCURRENTLY #{INDEX} ON merge_requests " \ + 'USING btree (target_project_id) INCLUDE (id, latest_merge_request_diff_id)' + + create_comment( + 'INDEX', + INDEX, + 'Index used to efficiently obtain the oldest merge request for a commit SHA' + ) + end + + def down + return unless index_exists_by_name?('merge_requests', INDEX) + + execute "DROP INDEX CONCURRENTLY #{INDEX}" + end +end diff --git a/db/schema_migrations/20210127143025 b/db/schema_migrations/20210127143025 new file mode 100644 index 00000000000..a4875304c0b --- /dev/null +++ b/db/schema_migrations/20210127143025 @@ -0,0 +1 @@ +c173ba86340efe39977f1b319d1ebcead634e3bfe819a30e230fb4f81766f28a
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index c7c6fae7a10..9dfe8d480d9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -22487,6 +22487,10 @@ CREATE UNIQUE INDEX index_on_instance_statistics_recorded_at_and_identifier ON a CREATE INDEX index_on_label_links_all_columns ON label_links USING btree (target_id, label_id, target_type); +CREATE INDEX index_on_merge_requests_for_latest_diffs ON merge_requests USING btree (target_project_id) INCLUDE (id, latest_merge_request_diff_id); + +COMMENT ON INDEX index_on_merge_requests_for_latest_diffs IS 'Index used to efficiently obtain the oldest merge request for a commit SHA'; + CREATE INDEX index_on_namespaces_lower_name ON namespaces USING btree (lower((name)::text)); CREATE INDEX index_on_namespaces_lower_path ON namespaces USING btree (lower((path)::text)); |