Update EnqueuerWorker query to optimize the PostgreSQL planner
Problem
In #362544 (comment 948577878) we identified a strange performance bug in the EnqueuerWorker query that finds the next qualified container repository for import.
That same problem is occurring again now that we have modified the query to import from all tiers.
The query generated by ContainerRepository.ready_for_import.limit(2)[0] is using a Seq Scan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/10687/commands/38546.
Solution
The solution is the same solution we found in In #362544 (closed). We need to use an even higher limit on the query to force the postgres planner to use the index. Bumping to LIMIT 3
fixes the problem, but we would like to avoid it happening again for the duration of the Phase 2 container registry migration, so we are bumping it to LIMIT 10
.
While we cannot be 100% certain the LIMIT 10
will take us to the end of the migration, it is best to get the migration moving again so we can continue to look at other performance gains as needed.