Skip to content

Prevent subquery on namespaces table

Heinrich Lee Yu requested to merge 436078-prevent-querying-namespaces into master

What does this MR do and why?

We already have the namespace object loaded so we can get the IDs via the traversal_ids column without an extra query. We can then pass these IDs directly to the where clause instead of building a namespace subquery.

This scope is used by Project#jira_subscription_exists?.

Query changes

Before:

SELECT 1 AS one
FROM "jira_connect_subscriptions"
WHERE "jira_connect_subscriptions"."namespace_id" IN (
  SELECT "namespaces"."id" FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" IN (107, 109)
)
LIMIT 1

After:

SELECT 1 AS one
FROM "jira_connect_subscriptions"
WHERE "jira_connect_subscriptions"."namespace_id" IN (109, 107)
LIMIT 1

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #436078 (closed)

Edited by Heinrich Lee Yu

Merge request reports