From 13837fb8df5a7fb7788487d471fb289618b23138 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Tue, 10 Sep 2019 13:53:13 +0200 Subject: [PATCH] Partial index for namespaces.type Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/66956 --- .../ab-partial-index-for-namespaces-type.yml | 5 +++++ ...ude_nulls_from_index_on_namespaces_type.rb | 20 +++++++++++++++++++ db/schema.rb | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/ab-partial-index-for-namespaces-type.yml create mode 100644 db/migrate/20190910114843_exclude_nulls_from_index_on_namespaces_type.rb diff --git a/changelogs/unreleased/ab-partial-index-for-namespaces-type.yml b/changelogs/unreleased/ab-partial-index-for-namespaces-type.yml new file mode 100644 index 00000000000..ad1802d5dce --- /dev/null +++ b/changelogs/unreleased/ab-partial-index-for-namespaces-type.yml @@ -0,0 +1,5 @@ +--- +title: Partial index for namespaces.type +merge_request: 32876 +author: +type: performance diff --git a/db/migrate/20190910114843_exclude_nulls_from_index_on_namespaces_type.rb b/db/migrate/20190910114843_exclude_nulls_from_index_on_namespaces_type.rb new file mode 100644 index 00000000000..5645e3be5d9 --- /dev/null +++ b/db/migrate/20190910114843_exclude_nulls_from_index_on_namespaces_type.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class ExcludeNullsFromIndexOnNamespacesType < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index(:namespaces, :type, where: 'type is not null', name: 'index_namespaces_on_type_partial') + remove_concurrent_index_by_name(:namespaces, 'index_namespaces_on_type') + end + + def down + add_concurrent_index(:namespaces, :type, name: 'index_namespaces_on_type') + remove_concurrent_index_by_name(:namespaces, 'index_namespaces_on_type_partial') + end +end diff --git a/db/schema.rb b/db/schema.rb index 39faf1e651e..cb124f7deb4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2291,7 +2291,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do t.index ["runners_token_encrypted"], name: "index_namespaces_on_runners_token_encrypted", unique: true t.index ["shared_runners_minutes_limit", "extra_shared_runners_minutes_limit"], name: "index_namespaces_on_shared_and_extra_runners_minutes_limit" t.index ["trial_ends_on"], name: "index_namespaces_on_trial_ends_on", where: "(trial_ends_on IS NOT NULL)" - t.index ["type"], name: "index_namespaces_on_type" + t.index ["type"], name: "index_namespaces_on_type_partial", where: "(type IS NOT NULL)" end create_table "note_diff_files", id: :serial, force: :cascade do |t| -- GitLab