summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-09-10 13:53:13 +0200
committerAndreas Brandl <abrandl@gitlab.com>2019-09-12 15:31:27 +0200
commit13837fb8df5a7fb7788487d471fb289618b23138 (patch)
treef48c91bd14db409dc409b6a7726944884abda38d
parent0844ec02f2a6dde9e7fdcf53f4f02cc3547ac960 (diff)
downloadgitlab-ce-ab/partial-index-for-namespaces-type.tar.gz
Partial index for namespaces.typeab/partial-index-for-namespaces-type
Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/66956
-rw-r--r--changelogs/unreleased/ab-partial-index-for-namespaces-type.yml5
-rw-r--r--db/migrate/20190910114843_exclude_nulls_from_index_on_namespaces_type.rb20
-rw-r--r--db/schema.rb2
3 files changed, 26 insertions, 1 deletions
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|