Skip to content

Improve rake elastic:projects_not_indexed query

Dmitry Gruzd requested to merge improve-projects-not-indexed-query into master

What does this MR do and why?

This MR speeds up the SQL query from the gitlab:elastic:projects_not_indexed rake task (2.7s to 5ms).

Previous query:

SELECT "projects".* FROM "projects" WHERE "projects"."id" NOT IN (SELECT DISTINCT "index_statuses"."project_id" FROM "index_statuses") LIMIT 1000

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20449/commands/66933

New query:

SELECT "projects".* FROM "projects" LEFT JOIN index_statuses ON projects.id = index_statuses.project_id WHERE (index_statuses.project_id IS NULL) LIMIT 1000

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/20449/commands/66932

Screenshots or screen recordings

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

Before After

How to set up and validate locally

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

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Dmitry Gruzd

Merge request reports