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?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added - Tests
-
Added for this feature/bug -
All builds are passing
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Branch has no merge conflicts with master
(if it does - rebase it please) -
Squashed related commits together