summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-11-19 15:39:15 +0100
committerAndreas Brandl <abrandl@gitlab.com>2019-01-03 15:12:49 +0100
commit50f9817afb3d6cc599c499abf1536215eada5600 (patch)
treeb5b8aafba9c086e514d873ff15de7f7146725a82 /db
parenta39cddf7b78f71006c7b8884432efe41220becb6 (diff)
downloadgitlab-ce-50f9817afb3d6cc599c499abf1536215eada5600.tar.gz
Add specific indexes for CI
This adds specific indexes to speed up the query mentioned in https://gitlab.com/gitlab-org/gitlab-ce/issues/50763 and to avoid statement timeouts. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50763.
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb19
-rw-r--r--db/schema.rb2
2 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb b/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
new file mode 100644
index 00000000000..2134131b28f
--- /dev/null
+++ b/db/migrate/20181119132520_add_indexes_to_ci_builds_and_pipelines.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddIndexesToCiBuildsAndPipelines < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :ci_pipelines, [:project_id, :ref, :id], order: { id: :desc }
+ add_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], where: "type = 'Ci::Build' AND (retried = false OR retried IS NULL) AND name IN ('sast', 'dependency_scanning', 'sast:container', 'container_scanning', 'dast')"
+ end
+
+ def down
+ remove_concurrent_index :ci_pipelines, [:project_id, :ref, :id], order: { id: :desc }
+ remove_concurrent_index :ci_builds, [:commit_id, :artifacts_expire_at, :id], where: "type = 'Ci::Build' AND (retried = false OR retried IS NULL) AND name IN ('sast', 'dependency_scanning', 'sast:container', 'container_scanning', 'dast')"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0af185409a9..e6be4b20c86 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -349,6 +349,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.string "token_encrypted"
t.index ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
t.index ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
+ t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expire_at_and_id", where: "(((type)::text = 'Ci::Build'::text) AND ((retried = false) OR (retried IS NULL)) AND ((name)::text = ANY ((ARRAY['sast'::character varying, 'dependency_scanning'::character varying, 'sast:container'::character varying, 'container_scanning'::character varying, 'dast'::character varying])::text[])))", using: :btree
t.index ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree
t.index ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree
t.index ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree
@@ -483,6 +484,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.index ["merge_request_id"], name: "index_ci_pipelines_on_merge_request_id", where: "(merge_request_id IS NOT NULL)", using: :btree
t.index ["pipeline_schedule_id"], name: "index_ci_pipelines_on_pipeline_schedule_id", using: :btree
t.index ["project_id", "iid"], name: "index_ci_pipelines_on_project_id_and_iid", unique: true, where: "(iid IS NOT NULL)", using: :btree
+ t.index ["project_id", "ref", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_id", order: { id: :desc }, using: :btree
t.index ["project_id", "ref", "status", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_status_and_id", using: :btree
t.index ["project_id", "sha"], name: "index_ci_pipelines_on_project_id_and_sha", using: :btree
t.index ["project_id", "source"], name: "index_ci_pipelines_on_project_id_and_source", using: :btree