summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolayS <nsamokhvalov@gitlab.com>2018-09-12 12:54:11 -0700
committerNikolayS <nsamokhvalov@gitlab.com>2018-09-12 12:54:11 -0700
commitc94242e23b563040a31523d18bffcab22028fe63 (patch)
tree025a16553260583f96eed01d5c7b3a6ed6908ba4
parent5a9be44869f94701c103e2220a6e1ae97375bff1 (diff)
downloadgitlab-ce-c94242e23b563040a31523d18bffcab22028fe63.tar.gz
Add 2 new indexes to speedup a query on ci_builds, ci_pipelines #50169
-rw-r--r--db/migrate/20180912181931_new_ci_indexes.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/db/migrate/20180912181931_new_ci_indexes.rb b/db/migrate/20180912181931_new_ci_indexes.rb
new file mode 100644
index 00000000000..1156b9b7e2c
--- /dev/null
+++ b/db/migrate/20180912181931_new_ci_indexes.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class NewCiIndexes < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ INDEX_NAME_1 = 'index_ci_pipelines_on_project_id_and_ref_and_id_desc'.freeze
+ INDEX_NAME_2 = 'partial_index_ci_builds_on_commit_id_and_artifacts_id_and_id_with_filter'.freeze
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :ci_pipelines, [:project_id, :ref, :id],
+ name: INDEX_NAME_1,
+ order: {project_id: :asc, ref: :asc, id: :desc}
+
+ add_concurrent_index :ci_builds, [:commit_id, :artifacts_id, :id],
+ name: INDEX_NAME_2,
+ where: <<-SQL_WHERE
+ type = 'Ci::Build'
+ and (retried = false or retried is null)
+ and name in ('sast', 'dependency_scanning', 'sast:container', 'container_scanning', 'dast')
+SQL_WHERE
+ end
+
+ def down
+ remove_concurrent_index_by_name(:ci_pipelines, INDEX_NAME_1)
+ remove_concurrent_index_by_name(:ci_builds, INDEX_NAME_2)
+ end
+end