diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-11-06 23:13:12 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-11-07 13:38:01 +0900 |
commit | 94a8d27eb3d0938517e2c520deab6f73b4033b5d (patch) | |
tree | bdd25043078effdd0deafd15d71438b7dcbad302 /db | |
parent | 12a73596cc0afe883cf983d675a2d9243253988f (diff) | |
download | gitlab-ce-94a8d27eb3d0938517e2c520deab6f73b4033b5d.tar.gz |
Optimize database index for id and iid
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20181106135939_add_index_to_deployments.rb | 20 | ||||
-rw-r--r-- | db/schema.rb | 7 |
2 files changed, 17 insertions, 10 deletions
diff --git a/db/migrate/20181106135939_add_index_to_deployments.rb b/db/migrate/20181106135939_add_index_to_deployments.rb index 41ea75f9d37..408ad64010e 100644 --- a/db/migrate/20181106135939_add_index_to_deployments.rb +++ b/db/migrate/20181106135939_add_index_to_deployments.rb @@ -4,21 +4,27 @@ class AddIndexToDeployments < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers DOWNTIME = false - SHORT_INDEX_NAME = 'index_deployments_on_deployed_for_finished_at' + SHORT_INDEX_NAME_FOR_ENVIRONMENT_ID = 'index_deployments_on_env_deployed_for_id' + SHORT_INDEX_NAME_FOR_ENVIRONMENT_IID = 'index_deployments_on_env_deployed_for_iid' + SHORT_INDEX_NAME_FOR_FINISHED_AT = 'index_deployments_on_deployed_for_finished_at' disable_ddl_transaction! def up - add_concurrent_index :deployments, [:project_id, :action, :status] - add_concurrent_index :deployments, [:environment_id, :action, :status] + add_concurrent_index :deployments, [:project_id, :action, :status, :id] + add_concurrent_index :deployments, [:project_id, :action, :status, :iid] + add_concurrent_index :deployments, [:project_id, :action, :status, :finished_at], name: SHORT_INDEX_NAME_FOR_FINISHED_AT + add_concurrent_index :deployments, [:environment_id, :action, :status, :id], name: SHORT_INDEX_NAME_FOR_ENVIRONMENT_ID + add_concurrent_index :deployments, [:environment_id, :action, :status, :iid], name: SHORT_INDEX_NAME_FOR_ENVIRONMENT_IID add_concurrent_index :deployments, [:environment_id, :action, :sha] - add_concurrent_index :deployments, [:project_id, :action, :status, :finished_at], name: SHORT_INDEX_NAME end def down - remove_concurrent_index :deployments, [:project_id, :action, :status] - remove_concurrent_index :deployments, [:environment_id, :action, :status] + remove_concurrent_index :deployments, [:project_id, :action, :status, :id] + remove_concurrent_index :deployments, [:project_id, :action, :status, :iid] + remove_concurrent_index_by_name(:deployments, SHORT_INDEX_NAME_FOR_FINISHED_AT) + remove_concurrent_index_by_name(:deployments, SHORT_INDEX_NAME_FOR_ENVIRONMENT_ID) + remove_concurrent_index_by_name(:deployments, SHORT_INDEX_NAME_FOR_ENVIRONMENT_IID) remove_concurrent_index :deployments, [:environment_id, :action, :sha] - remove_concurrent_index_by_name(:deployments, SHORT_INDEX_NAME) end end diff --git a/db/schema.rb b/db/schema.rb index 2c0aaffcb13..67b97a8d208 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -833,14 +833,15 @@ ActiveRecord::Schema.define(version: 20181106135939) do add_index "deployments", ["created_at"], name: "index_deployments_on_created_at", using: :btree add_index "deployments", ["deployable_type", "deployable_id"], name: "index_deployments_on_deployable_type_and_deployable_id", using: :btree add_index "deployments", ["environment_id", "action", "sha"], name: "index_deployments_on_environment_id_and_action_and_sha", using: :btree - add_index "deployments", ["environment_id", "action", "status"], name: "index_deployments_on_environment_id_and_action_and_status", using: :btree + add_index "deployments", ["environment_id", "action", "status", "id"], name: "index_deployments_on_env_deployed_for_id", using: :btree + add_index "deployments", ["environment_id", "action", "status", "iid"], name: "index_deployments_on_env_deployed_for_iid", using: :btree add_index "deployments", ["environment_id", "id"], name: "index_deployments_on_environment_id_and_id", using: :btree add_index "deployments", ["environment_id", "iid", "project_id"], name: "index_deployments_on_environment_id_and_iid_and_project_id", using: :btree add_index "deployments", ["environment_id", "status"], name: "index_deployments_on_environment_id_and_status", using: :btree - add_index "deployments", ["finished_at"], name: "index_deployments_on_finished_at", using: :btree add_index "deployments", ["id"], name: "partial_index_deployments_for_legacy_successful_deployments", where: "((finished_at IS NULL) AND (status = 2))", using: :btree add_index "deployments", ["project_id", "action", "status", "finished_at"], name: "index_deployments_on_deployed_for_finished_at", using: :btree - add_index "deployments", ["project_id", "action", "status"], name: "index_deployments_on_project_id_and_action_and_status", using: :btree + add_index "deployments", ["project_id", "action", "status", "id"], name: "index_deployments_on_project_id_and_action_and_status_and_id", using: :btree + add_index "deployments", ["project_id", "action", "status", "iid"], name: "index_deployments_on_project_id_and_action_and_status_and_iid", using: :btree add_index "deployments", ["project_id", "iid"], name: "index_deployments_on_project_id_and_iid", unique: true, using: :btree add_index "deployments", ["project_id", "status"], name: "index_deployments_on_project_id_and_status", using: :btree |