Use linear version GroupsWithTemplatesFinder#extended_group_search
What does this MR do and why?
In this MR, we're switching the behavior of the GroupsWithTemplatesFinder#extended_group_search
method to use the linear version. The new behavior is behind the linear_groups_template_finder_extended_group_search_ancestors_scopes
feature flag.
How to set up and validate locally
-
Enable the setting
check_namespace_plan
Gitlab::CurrentSettings.update(check_namespace_plan: true)
-
Enable the new method behavior feature flag
Feature.enable(:linear_groups_template_finder_extended_group_search_ancestors_scopes)
-
Enable the feature flag for linear ancestors scopes
Feature.enable(:use_traversal_ids_for_ancestor_scopes)
-
In Rails console enable the traversal id feature flag
Feature.enable(:use_traversal_ids)
-
In Rails console, execute:
GroupsWithTemplatesFinder.new.execute
SQL Query
The former SQL query was:
WITH RECURSIVE "base_and_ancestors" AS (
(SELECT *
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."custom_project_templates_group_id" IS NOT NULL)
UNION
(SELECT *
FROM "namespaces",
"base_and_ancestors"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = "base_and_ancestors"."parent_id"))
SELECT *
FROM "base_and_ancestors" AS "namespaces"
WHERE (EXISTS
(SELECT 1
FROM "plans"
INNER JOIN "gitlab_subscriptions" ON "gitlab_subscriptions"."hosted_plan_id" = "plans"."id"
WHERE "plans"."name" IN ('silver',
'premium',
'premium_trial',
'gold',
'ultimate',
'ultimate_trial')
AND (gitlab_subscriptions.namespace_id = namespaces.id)))
This is the query plan and the times are:
Time: 42.387 ms
- planning: 1.335 ms
- execution: 41.052 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 16588 (~129.60 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
The new SQL query is:
SELECT *
FROM
(SELECT *
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" IN
(SELECT unnest(traversal_ids)
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."custom_project_templates_group_id" IS NOT NULL)) namespaces
WHERE "namespaces"."type" = 'Group'
AND (EXISTS
(SELECT 1
FROM "plans"
INNER JOIN "gitlab_subscriptions" ON "gitlab_subscriptions"."hosted_plan_id" = "plans"."id"
WHERE "plans"."name" IN ('silver',
'premium',
'premium_trial',
'gold',
'ultimate',
'ultimate_trial')
AND (gitlab_subscriptions.namespace_id = namespaces.id)))
This is the query plan and the times are:
Time: 40.253 ms
- planning: 1.268 ms
- execution: 38.985 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 21200 (~165.60 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
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 #345784 (closed)