Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-09-02 18:26:15 +0300
committerAndreas Brandl <abrandl@gitlab.com>2019-09-04 14:43:51 +0300
commitbd56acd37814933e5fb51f1fe1adce6171532979 (patch)
treef78652385a4e35ec8aaac80ceb893a46a2bc514d /db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb
parentf8f8ed471f6ce62b7198d49170845f7f5a09cf64 (diff)
Create partial index for gitlab-monitor CI metrics
This creates a partial index intended to speed up queries on `ci_builds`. Particularly, `gitlab-monitor` has rather heavy queries. Those have been changed to only look back 7 days and benefit from this index tremendously. Relates to https://gitlab.com/gitlab-org/gitlab-exporter/merge_requests/101.
Diffstat (limited to 'db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb')
-rw-r--r--db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb b/db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb
new file mode 100644
index 00000000000..b755d60e311
--- /dev/null
+++ b/db/migrate/20190902152329_add_index_for_ci_builds_metrics.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class AddIndexForCiBuildsMetrics < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ INDEX_NAME = 'ci_builds_gitlab_monitor_metrics'
+
+ def up
+ add_concurrent_index(:ci_builds, [:status, :created_at, :project_id], where: "type = 'Ci::Build'", name: INDEX_NAME)
+ end
+
+ def down
+ remove_concurrent_index_by_name(:ci_builds, INDEX_NAME)
+ end
+end