Commit 9de2dd41 authored by Andreas Brandl's avatar Andreas Brandl

Extend index on ci_builds_metadata

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/296755
parent 83ca61fc
---
title: Extend index on ci_builds_metadata
merge_request: 52123
author:
type: performance
# frozen_string_literal: true
class ExtendIndexOnCiBuildsMetadata < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
OLD_INDEX = :index_ci_builds_metadata_on_build_id_and_interruptible
NEW_INDEX = :index_ci_builds_metadata_on_build_id_and_id_and_interruptible
TABLE = :ci_builds_metadata
def up
create_covering_index(TABLE, NEW_INDEX)
remove_concurrent_index_by_name TABLE, OLD_INDEX
end
def down
add_concurrent_index TABLE, :build_id, where: 'interruptible = true', name: OLD_INDEX
remove_concurrent_index_by_name TABLE, NEW_INDEX
end
private
def create_covering_index(table, name)
return if index_exists_by_name?(table, name)
disable_statement_timeout do
execute <<~SQL
CREATE INDEX CONCURRENTLY #{name}
ON #{table} (build_id) INCLUDE (id)
WHERE interruptible = true
SQL
end
end
end
897815c347f04093da5eba420e95b6310454bd493412914e60a296bd710ebde1
\ No newline at end of file
......@@ -21622,7 +21622,7 @@ CREATE UNIQUE INDEX index_ci_builds_metadata_on_build_id ON ci_builds_metadata U
CREATE INDEX index_ci_builds_metadata_on_build_id_and_has_exposed_artifacts ON ci_builds_metadata USING btree (build_id) WHERE (has_exposed_artifacts IS TRUE);
CREATE INDEX index_ci_builds_metadata_on_build_id_and_interruptible ON ci_builds_metadata USING btree (build_id) WHERE (interruptible = true);
CREATE INDEX index_ci_builds_metadata_on_build_id_and_id_and_interruptible ON ci_builds_metadata USING btree (build_id) INCLUDE (id) WHERE (interruptible = true);
CREATE INDEX index_ci_builds_metadata_on_project_id ON ci_builds_metadata USING btree (project_id);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment