summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-11-21 21:36:28 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-21 21:36:28 +0000
commit5a5bececbeabf6492d0e911c5bf09d14d060fdab (patch)
treec0fa627d98d1482093b8ceeef1062fd19783267b
parent7054a3cbed697d7a310a8cf6ffc9be22a58a61ad (diff)
parentaafe5c123ef2f64ddf44a5655a6fc63ec4e571da (diff)
downloadgitlab-ce-5a5bececbeabf6492d0e911c5bf09d14d060fdab.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.yml5
-rw-r--r--db/migrate/20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb35
-rw-r--r--db/schema.rb4
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