summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-11-24 10:11:37 +0000
committerSean McGivern <sean@gitlab.com>2017-11-28 16:13:57 +0000
commit484ae2ee2db58a641d3c3fff36f46b431ce450df (patch)
treec5124b9b841b0d0a649a1d6bc1c82d2bc9d200db
parent4ebbfe5d3e0dbe06346ee0c64a8f62ec11f9b6e8 (diff)
downloadgitlab-ce-484ae2ee2db58a641d3c3fff36f46b431ce450df.tar.gz
Improve indexes on merge_request_diffsremove-mr-diff-serialised-columns
For getting the SHAs from an MR to find pipelines, we get the last 100 MR diffs for the MR, and find commits from those. This was un-indexed before, because the index was not a composite index on merge_request_diff_id, id. Changing that means that this scope can exclusively use indexes.
-rw-r--r--db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb17
-rw-r--r--db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb17
-rw-r--r--db/schema.rb2
3 files changed, 35 insertions, 1 deletions
diff --git a/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb b/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb
new file mode 100644
index 00000000000..698df712c11
--- /dev/null
+++ b/db/post_migrate/20171124095655_add_index_on_merge_request_diffs_merge_request_id_and_id.rb
@@ -0,0 +1,17 @@
+class AddIndexOnMergeRequestDiffsMergeRequestIdAndId < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index(:merge_request_diffs, [:merge_request_id, :id])
+ end
+
+ def down
+ if index_exists?(:merge_request_diffs, [:merge_request_id, :id])
+ remove_concurrent_index(:merge_request_diffs, [:merge_request_id, :id])
+ end
+ end
+end
diff --git a/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb b/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb
new file mode 100644
index 00000000000..038e4807000
--- /dev/null
+++ b/db/post_migrate/20171124100152_remove_index_on_merge_request_diffs_merge_request_diff_id.rb
@@ -0,0 +1,17 @@
+class RemoveIndexOnMergeRequestDiffsMergeRequestDiffId < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ if index_exists?(:merge_request_diffs, :merge_request_id)
+ remove_concurrent_index(:merge_request_diffs, :merge_request_id)
+ end
+ end
+
+ def down
+ add_concurrent_index(:merge_request_diffs, :merge_request_id)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 292163ee9bf..339c98d7798 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1020,7 +1020,7 @@ ActiveRecord::Schema.define(version: 20171124132536) do
t.string "start_commit_sha"
end
- add_index "merge_request_diffs", ["merge_request_id"], name: "index_merge_request_diffs_on_merge_request_id", using: :btree
+ add_index "merge_request_diffs", ["merge_request_id", "id"], name: "index_merge_request_diffs_on_merge_request_id_and_id", using: :btree
create_table "merge_request_metrics", force: :cascade do |t|
t.integer "merge_request_id", null: false