Fix cross join when filtering by assignee
What does this MR do and why?
This changes filtering by assignee usernames, so that we pluck the user ids separately instead of using a subquery.
Query changes
Before
SELECT COUNT(*), COALESCE(SUM(weight), 0)
FROM "issues"
WHERE "issues"."id" IN (
SELECT "issues"."id"
FROM "issues"
INNER JOIN "work_item_types" ON "work_item_types"."id" = "issues"."work_item_type_id"
WHERE (NOT EXISTS (SELECT 1 FROM "banned_users" WHERE (issues.author_id = banned_users.user_id)))
AND "issues"."project_id" = 1
AND ("issues"."state_id" IN (1))
AND EXISTS (
SELECT "issue_assignees".* FROM "issue_assignees" WHERE "issue_assignees"."user_id" IN (
SELECT "users"."id" FROM "users" WHERE (LOWER("users"."username") IN (LOWER('user1'), LOWER('user3')))
)
AND (issue_id = issues.id)
)
AND "work_item_types"."base_type" IN (0, 1)
AND (EXISTS (SELECT "label_links".* FROM "label_links" WHERE "label_links"."target_type" = 'Issue' AND ("issues"."id" = "label_links"."target_id") AND "label_links"."label_id" = 1 LIMIT 1))
)
https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/20552/commands/67397
After
The users
query is now done separately so we'll have:
SELECT "users"."id" FROM "users" WHERE (LOWER("users"."username") IN (LOWER('user1'), LOWER('user3')))
https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/20552/commands/67399
And then the result of this inside the WHERE "issue_assignees"."user_id" IN (...)
clause:
https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/20552/commands/67401
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #417465 (closed)
Edited by Heinrich Lee Yu