diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-11-21 21:36:28 +0000 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-11-22 23:53:13 -0200 |
commit | beb132d96bbc866dc9984c7ea9577e7a13d2297b (patch) | |
tree | f7e417f450d32f023d62ab6bc5e16ed66333ea4c | |
parent | 400e3ddc3561ac97875013dc4d7ca84c53731501 (diff) | |
download | gitlab-ce-beb132d96bbc866dc9984c7ea9577e7a13d2297b.tar.gz |
Merge branch 'fix-ci-pipelines-index' into 'master'
Update composite pipelines index to include "id"
See merge request gitlab-org/gitlab-ce!15519
-rw-r--r-- | changelogs/unreleased/fix-ci-pipelines-index.yml | 5 | ||||
-rw-r--r-- | db/migrate/20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb | 35 | ||||
-rw-r--r-- | db/schema.rb | 4 |
3 files changed, 42 insertions, 2 deletions
diff --git a/changelogs/unreleased/fix-ci-pipelines-index.yml b/changelogs/unreleased/fix-ci-pipelines-index.yml new file mode 100644 index 00000000000..772093fbef0 --- /dev/null +++ b/changelogs/unreleased/fix-ci-pipelines-index.yml @@ -0,0 +1,5 @@ +--- +title: Update composite pipelines index to include "id" +merge_request: +author: +type: performance diff --git a/db/migrate/20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb b/db/migrate/20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb new file mode 100644 index 00000000000..5a8ae6e4b57 --- /dev/null +++ b/db/migrate/20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb @@ -0,0 +1,35 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class CiPipelinesIndexOnProjectIdRefStatusId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + TABLE = :ci_pipelines + OLD_COLUMNS = %i[project_id ref status].freeze + NEW_COLUMNS = %i[project_id ref status id].freeze + + def up + unless index_exists?(TABLE, NEW_COLUMNS) + add_concurrent_index(TABLE, NEW_COLUMNS) + end + + if index_exists?(TABLE, OLD_COLUMNS) + remove_concurrent_index(TABLE, OLD_COLUMNS) + end + end + + def down + unless index_exists?(TABLE, OLD_COLUMNS) + add_concurrent_index(TABLE, OLD_COLUMNS) + end + + if index_exists?(TABLE, NEW_COLUMNS) + remove_concurrent_index(TABLE, NEW_COLUMNS) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c60cb729b75..66aa505bb04 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: 20171106101200) do +ActiveRecord::Schema.define(version: 20171121144800) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -373,7 +373,7 @@ ActiveRecord::Schema.define(version: 20171106101200) do add_index "ci_pipelines", ["auto_canceled_by_id"], name: "index_ci_pipelines_on_auto_canceled_by_id", using: :btree add_index "ci_pipelines", ["pipeline_schedule_id"], name: "index_ci_pipelines_on_pipeline_schedule_id", using: :btree - add_index "ci_pipelines", ["project_id", "ref", "status"], name: "index_ci_pipelines_on_project_id_and_ref_and_status", using: :btree + add_index "ci_pipelines", ["project_id", "ref", "status", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_status_and_id", using: :btree add_index "ci_pipelines", ["project_id", "sha"], name: "index_ci_pipelines_on_project_id_and_sha", using: :btree add_index "ci_pipelines", ["project_id"], name: "index_ci_pipelines_on_project_id", using: :btree add_index "ci_pipelines", ["status"], name: "index_ci_pipelines_on_status", using: :btree |