Skip to content

Display related merge requests in commit detail page

What does this MR do?

Display merge requests in the commit that was introduced in page.

Are there points in the code the reviewer needs to double check?

  • UX (Following to #2383 (moved))
  • SQL performance (Adding index on merge_request_diff_commits.sha)

The following is EXPLAIN ANALYSE output made by commit.merge_requests.

SELECT COUNT(*) FROM merge_requests;

SELECT COUNT(*) FROM merge_request_diffs; count


SELECT COUNT(*) FROM merge_request_diff_commits; count


SELECT "merge_requests".*
FROM "merge_requests"
WHERE "merge_requests"."deleted_at" IS NULL
  AND "merge_requests"."target_project_id" = 1
         (SELECT 1
          FROM "merge_request_diffs"
          INNER JOIN "merge_request_diff_commits" ON "merge_request_diff_commits"."merge_request_diff_id" = "merge_request_diffs"."id"
          WHERE ( = merge_request_diffs.merge_request_id)
            AND "merge_request_diff_commits"."sha" = '\xe7466ad6e6e024abc6d8442a5dfec822403a62d3'))
Query plan
                                                                                      QUERY PLAN
 Nested Loop  (cost=17.02..17.19 rows=1 width=326) (actual time=0.053..0.060 rows=1 loops=1)
   ->  HashAggregate  (cost=16.74..16.75 rows=1 width=4) (actual time=0.044..0.044 rows=2 loops=1)
         Group Key: merge_request_diffs.merge_request_id
         ->  Nested Loop  (cost=0.69..16.74 rows=1 width=4) (actual time=0.033..0.039 rows=2 loops=1)
               ->  Index Scan using index_merge_request_diff_commits_on_sha on merge_request_diff_commits  (cost=0.41..8.43 rows=1 width=4) (actual time=0.027..0.027 rows=2 loops=1)
                     Index Cond: (sha = '\xe7466ad6e6e024abc6d8442a5dfec822403a62d3'::bytea)
               ->  Index Scan using merge_request_diffs_pkey on merge_request_diffs  (cost=0.28..8.29 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=2)
                     Index Cond: (id = merge_request_diff_commits.merge_request_diff_id)
   ->  Index Scan using merge_requests_pkey on merge_requests  (cost=0.28..0.43 rows=1 width=326) (actual time=0.007..0.007 rows=0 loops=2)
         Index Cond: (id = merge_request_diffs.merge_request_id)
         Filter: ((deleted_at IS NULL) AND (target_project_id = 1))
         Rows Removed by Filter: 0
 Planning time: 8.262 ms
 Execution time: 0.194 ms

Why was this MR needed?

I use git blame to know why lines in source code have been changed.

I can know the commit that the lines changed in, but it is difficult to find merge requests from the commit.

Screenshots (if relevant)

  • MR exists


  • MR exists but that commit does not exist in latest diff


  • MR does not exist


Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes #2383 (moved)

Edited by username-removed-7736

Merge request reports