Commit 484ae2ee authored by Sean McGivern's avatar Sean McGivern

Improve indexes on merge_request_diffs

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.
parent 4ebbfe5d
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
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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment