Skip to content

Add new index for merge_request_diffs

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

What does this MR do and why?

Issue: #440185 (comment 1896868413)

In order to improve the query performance, adjust the index of merge_request_diffs table.

  • Create new [project_id, base_commit_sha] index
  • In addition, update the query statement of the Ci::Pipeline#merge_requests_as_base_pipeline : !152602 (comment 1901975373)

Database migration changes:

main: == [advisory_lock_connection] object_id: 125140, pg_backend_pid: 62500
main: == 20240515160624 AddMergeRequestDiffsProjectIdBaseCommitShaIndex: migrating ==
main: -- index_exists?(:merge_request_diffs, [:project_id, :base_commit_sha], {:name=>"index_merge_request_diffs_on_project_id_base_commit_sha", :algorithm=>:concurrently})
main:    -> 0.0041s
main: -- add_index_options(:merge_request_diffs, [:project_id, :base_commit_sha], {:name=>"index_merge_request_diffs_on_project_id_base_commit_sha", :algorithm=>:concurrently})
main:    -> 0.0003s
main: == 20240515160624 AddMergeRequestDiffsProjectIdBaseCommitShaIndex: migrated (0.0333s) 

BEFORE INDEX:

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/28268/commands/88225

AFTER INDEX:

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/28268/commands/88229

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

No UI changes.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Zhiyuan Lu

Merge request reports