Skip to content

Optimize labels finder query

What does this MR do?

Optimize labels finder query when searching for a project with a group.

This query is being used when filtering labels in the search bar in issues/merge requests page.

original - https://explain.depesz.com/s/f5iI

SELECT "labels".*
FROM "labels"
WHERE (labels.id IN
         (SELECT "labels"."id"
          FROM "labels"
          WHERE "labels"."type" IN ('GroupLabel')
            AND "labels"."group_id" = 2
          UNION SELECT "labels"."id"
          FROM "labels"
          WHERE "labels"."type" IN ('ProjectLabel')
            AND "labels"."project_id" = 1))
ORDER BY "labels"."title" ASC

updated - https://explain.depesz.com/s/W5N

SELECT "labels".*
FROM "labels"
WHERE ("labels"."type" = 'GroupLabel'
       AND "labels"."group_id" = 2
       OR "labels"."type" = 'ProjectLabel'
       AND "labels"."project_id" = 1)
ORDER BY "labels"."title" ASC

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

Why was this MR needed?

Screenshots (if relevant)

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Merge request reports