summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-02-22 12:09:27 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-02-22 12:09:27 +0000
commit011ddb51b40897bc13a75d78c9e992f559cbde48 (patch)
treed2f25aa76ab1466ecca82d2cf07e3594b8d7addc /db
parenta75cce1febf0403d66631841fff3bfbeefbfe6e3 (diff)
parenteb421c88ee2a57a437b9b14ba7447a04720354ac (diff)
downloadgitlab-ce-011ddb51b40897bc13a75d78c9e992f559cbde48.tar.gz
Merge branch 'master' into 'backstage/gb/build-stages-catch-up-migration'
# Conflicts: # db/schema.rb
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180213131630_add_partial_index_to_projects_for_index_only_scans.rb21
-rw-r--r--db/schema.rb3
2 files changed, 23 insertions, 1 deletions
diff --git a/db/migrate/20180213131630_add_partial_index_to_projects_for_index_only_scans.rb b/db/migrate/20180213131630_add_partial_index_to_projects_for_index_only_scans.rb
new file mode 100644
index 00000000000..cedf2510dda
--- /dev/null
+++ b/db/migrate/20180213131630_add_partial_index_to_projects_for_index_only_scans.rb
@@ -0,0 +1,21 @@
+class AddPartialIndexToProjectsForIndexOnlyScans < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME = 'index_projects_on_id_partial_for_visibility'
+
+ disable_ddl_transaction!
+
+ # Adds a partial index to leverage index-only scans when looking up project ids
+ def up
+ unless index_exists?(:projects, :id, name: INDEX_NAME)
+ add_concurrent_index :projects, :id, name: INDEX_NAME, unique: true, where: 'visibility_level IN (10,20)'
+ end
+ end
+
+ def down
+ if index_exists?(:projects, :id, name: INDEX_NAME)
+ remove_concurrent_index_by_name :projects, INDEX_NAME
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1f41b97041e..409d1ac7644 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180212102028) do
+ActiveRecord::Schema.define(version: 20180213131630) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1468,6 +1468,7 @@ ActiveRecord::Schema.define(version: 20180212102028) do
add_index "projects", ["created_at"], name: "index_projects_on_created_at", using: :btree
add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree
add_index "projects", ["description"], name: "index_projects_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"}
+ add_index "projects", ["id"], name: "index_projects_on_id_partial_for_visibility", unique: true, where: "(visibility_level = ANY (ARRAY[10, 20]))", using: :btree
add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree
add_index "projects", ["last_repository_check_failed"], name: "index_projects_on_last_repository_check_failed", using: :btree
add_index "projects", ["last_repository_updated_at"], name: "index_projects_on_last_repository_updated_at", using: :btree