Skip to content

Convert migration to populate latest merge request ID into a background migration

Stan Hu requested to merge sh-background-migration-move-mr-diff-id into master

This is to smear updates over a few hours to avoid causing excessive replication lag as seen in https://gitlab.com/gitlab-com/infrastructure/issues/3235.

As a sanity check, the EXPLAIN ANALYZE output for this query appeared to be:

# explain analyze SELECT  "merge_requests"."id" FROM "merge_requests" WHERE "merge_requests"."latest_merge_request_diff_id" IS NULL AND ("merge_requests"."id" >= 1)  ORDER BY "merge_requests"."id" ASC LIMIT 1 OFFSET 50000;
                                                                         QUERY PLAN                                                                          
-------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=40973.23..40974.05 rows=1 width=4) (actual time=3014.802..3014.802 rows=1 loops=1)
   ->  Index Scan using merge_requests_pkey on merge_requests  (cost=0.43..1059692.17 rows=1293165 width=4) (actual time=6.328..3002.100 rows=50001 loops=1)
         Index Cond: (id >= 1)
         Filter: (latest_merge_request_diff_id IS NULL)
         Rows Removed by Filter: 3661384
 Planning time: 1.768 ms
 Execution time: 3014.850 ms
(7 rows)
Edited by Stan Hu

Merge request reports