diff options
-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 7afab18df08..a82270390f1 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: 20171114162227) do +ActiveRecord::Schema.define(version: 20171121144800) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -382,7 +382,7 @@ ActiveRecord::Schema.define(version: 20171114162227) 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 |