Fix drifted hosted_plan_name_uid in subscription histories

What does this MR do and why?

2,665 rows in gitlab_subscription_histories have a hosted_plan_name_uid that disagrees with the plan their hosted_plan_id points at. This MR queues a batched background migration to re-sync those values from plans.plan_name_uid.

The same deploy gap hit gitlab_subscriptions, and !234704 (merged) fixed it there. The histories table never got the equivalent fix.

Nothing in master reads hosted_plan_name_uid on this table yet, since reads still go through hosted_plan_id, so the wrong values are inert today. They start to matter when !242975 (merged) switches those reads to the uid, which is why this MR gates that one and #596995 (closed).

Issue: #606694 (closed)

Database review

Data-only, no schema change. Each sub-batch runs:

UPDATE gitlab_subscription_histories
SET hosted_plan_name_uid = plans.plan_name_uid
FROM plans
WHERE gitlab_subscription_histories.hosted_plan_id = plans.id
  AND gitlab_subscription_histories.id IN (<sub_batch>)
  AND gitlab_subscription_histories.hosted_plan_name_uid IS DISTINCT FROM plans.plan_name_uid

Database Lab session

 Update on public.gitlab_subscription_histories  (cost=4.70..47.22 rows=0 width=0) (actual time=8.123..8.124 rows=0 loops=1)
   Buffers: shared hit=3 read=8
   I/O Timings: read=7.989 write=0.000
   ->  Hash Join  (cost=4.70..47.22 rows=109 width=14) (actual time=8.121..8.123 rows=0 loops=1)
         Hash Cond: (gitlab_subscription_histories.hosted_plan_id = plans.id)
         Join Filter: (gitlab_subscription_histories.hosted_plan_name_uid IS DISTINCT FROM plans.plan_name_uid)
         Rows Removed by Join Filter: 101
         Buffers: shared hit=3 read=8
         I/O Timings: read=7.989 write=0.000
         ->  Index Scan using gitlab_subscription_histories_pkey on public.gitlab_subscription_histories  (cost=0.43..42.51 rows=119 width=12) (actual time=5.182..7.550 rows=101 loops=1)
               Index Cond: ((gitlab_subscription_histories.id >= 1000000) AND (gitlab_subscription_histories.id <= 1000100))
               Buffers: shared hit=3 read=7
               I/O Timings: read=7.468 write=0.000
         ->  Hash  (cost=4.12..4.12 rows=12 width=12) (actual time=0.541..0.542 rows=12 loops=1)
               Buckets: 1024  Batches: 1  Memory Usage: 9kB
               Buffers: shared read=1
               I/O Timings: read=0.521 write=0.000
               ->  Seq Scan on public.plans  (cost=0.00..4.12 rows=12 width=12) (actual time=0.533..0.535 rows=12 loops=1)
                     Buffers: shared read=1
                     I/O Timings: read=0.521 write=0.000
 Settings: seq_page_cost = '4', effective_cache_size = '472585MB', jit = 'off', random_page_cost = '1.5', work_mem = '230MB'

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Ryan Cobb

Merge request reports

Loading
Loading