Use GroupPlansPreloader linear ancestor scopes
What does this MR do and why?
In this MR, we're switching the behavior of the method GroupPlansPreloader#groups_and_ancestors_for
to use the linear version. The new behavior is behind the linear_group_plans_preloaded_ancestor_scopes
feature flag.
Database queries
The queries have been tested using the most expensive groups with 21 parents (5 groups at the moment).
The original query was:
WITH RECURSIVE "base_and_ancestors" AS (
(SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" IN (1,2))
UNION
(SELECT "namespaces".*
FROM "namespaces",
"base_and_ancestors"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = "base_and_ancestors"."parent_id"))
SELECT "namespaces"."id",
"namespaces"."parent_id",
"gitlab_subscriptions"."hosted_plan_id"
FROM "base_and_ancestors" AS "namespaces"
LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id
This is the query plan and the times are:
Time: 6.501 ms
- planning: 2.708 ms
- execution: 3.793 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 740 (~5.80 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
The new query is:
SELECT "namespaces"."id",
"namespaces"."parent_id",
"gitlab_subscriptions"."hosted_plan_id"
FROM
(SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."id" IN
(SELECT unnest(traversal_ids)
FROM "namespaces"
WHERE "namespaces"."id" IN (1,2))) namespaces
LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id
This is the query plan and the times are:
Time: 2.699 ms
- planning: 0.815 ms
- execution: 1.884 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 763 (~6.00 MiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
How to set up and validate locally
-
Enable the feature flag for linear scopes
Feature.enable(:use_traversal_ids)
-
Enable the feature flag for linear ancestors scopes
Feature.enable(:use_traversal_ids_for_ancestor_scopes)
-
Enable the feature flag for
GroupPlansPreloader
linear ancestors scopesFeature.enable(:linear_group_plans_preloaded_ancestor_scopes)
-
Execute the following in the Rails console with the proper id depending on the scope testing:
Gitlab::GroupPlansPreloader.new.send(:groups_and_ancestors_for, Group.where(id: [1, 2]))
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 #339458 (closed)
Merge request reports
Activity
changed milestone to %14.4
added Linear queries auto updated backend bugperformance devopsmanage groupauthentication and authorization [DEPRECATED] sectiondev + 1 deleted label
- A deleted user
added feature flag label
1 Warning Please add a merge request type to this merge request. Reviewer roulette
Changes that require review have been detected!
Please refer to the table below for assigning reviewers and maintainers suggested by Danger in the specified category:
Category Reviewer Maintainer backend Furkan Ayhan ( @furkanayhan
) (UTC+3, 1 hour ahead of@fjsanpedro
)Dmitry Gruzd ( @dgruzd
) (UTC+3, 1 hour ahead of@fjsanpedro
)To spread load more evenly across eligible reviewers, Danger has picked a candidate for each review slot, based on their timezone. Feel free to override these selections if you think someone else would be better-suited or use the GitLab Review Workload Dashboard to find other available reviewers.
To read more on how to use the reviewer roulette, please take a look at the Engineering workflow and code review guidelines. Please consider assigning a reviewer or maintainer who is a domain expert in the area of the merge request.
Once you've decided who will review this merge request, assign them as a reviewer! Danger does not automatically notify them for you.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
Danger @fjsanpedro, please can you answer the question: Should this have a feature flag? to help with code review for the Access group.This nudge was added by this triage-ops policy.
added 189 commits
-
61887831...092cd22f - 187 commits from branch
master
- 136c2cd1 - Use GroupPlansPreloader linear ancestor scopes
- 5072934d - Add merge request url
-
61887831...092cd22f - 187 commits from branch
mentioned in epic &6738 (closed)
assigned to @fjsanpedro
added 180 commits
-
e0c85434...91ab9f2a - 177 commits from branch
master
- 31824325 - Use GroupPlansPreloader linear ancestor scopes
- a46f18d8 - Add merge request url
- dbbe1d1b - Add roll out issue
Toggle commit list-
e0c85434...91ab9f2a - 177 commits from branch
added 195 commits
-
dbbe1d1b...89d2d950 - 192 commits from branch
master
- ba90e028 - Use GroupPlansPreloader linear ancestor scopes
- 890027dd - Add merge request url
- 8d11bb97 - Add roll out issue
Toggle commit list-
dbbe1d1b...89d2d950 - 192 commits from branch
added 163 commits
-
8d11bb97...da3058d5 - 160 commits from branch
master
- 437f828d - Use GroupPlansPreloader linear ancestor scopes
- aefbfba5 - Add merge request url
- 373d01f6 - Add roll out issue
Toggle commit list-
8d11bb97...da3058d5 - 160 commits from branch
added 43 commits
-
373d01f6...52e0b948 - 40 commits from branch
master
- b7f7802a - Use GroupPlansPreloader linear ancestor scopes
- d9a22317 - Add merge request url
- dc00eb24 - Add roll out issue
Toggle commit list-
373d01f6...52e0b948 - 40 commits from branch
added 131 commits
-
dc00eb24...0a2d5dc3 - 128 commits from branch
master
- f23c3d70 - Use GroupPlansPreloader linear ancestor scopes
- b1b436cc - Add merge request url
- a9de3ba6 - Add roll out issue
Toggle commit list-
dc00eb24...0a2d5dc3 - 128 commits from branch
added 174 commits
-
a9de3ba6...8d3b531a - 171 commits from branch
master
- 1b5ea4d4 - Use GroupPlansPreloader linear ancestor scopes
- 212940ee - Add merge request url
- c7845d87 - Add roll out issue
Toggle commit list-
a9de3ba6...8d3b531a - 171 commits from branch
added 180 commits
-
c7845d87...47132616 - 177 commits from branch
master
- dedefab8 - Use GroupPlansPreloader linear ancestor scopes
- 20ec28e5 - Add merge request url
- 9b58f908 - Add roll out issue
Toggle commit list-
c7845d87...47132616 - 177 commits from branch
added 272 commits
-
9b58f908...9f661a90 - 269 commits from branch
master
- d86464a1 - Use GroupPlansPreloader linear ancestor scopes
- 36b95b87 - Add merge request url
- 7c443c21 - Add roll out issue
Toggle commit list-
9b58f908...9f661a90 - 269 commits from branch
- Resolved by Francisco Javier López
- Resolved by Francisco Javier López
- Resolved by Francisco Javier López
added 160 commits
-
12f8406a...c77e8c13 - 156 commits from branch
master
- f3e4ff26 - Use GroupPlansPreloader linear ancestor scopes
- 6b9f2d15 - Add merge request url
- 322075d5 - Add roll out issue
- 85e3a7ef - Fix Rubocop offense
Toggle commit list-
12f8406a...c77e8c13 - 156 commits from branch
added 1 commit
- adf3c545 - Use GroupPlansPreloader linear ancestor scopes
- Resolved by Dmitry Gruzd
requested review from @ahegyi
added 5 commits
-
adf3c545...b52f21df - 4 commits from branch
master
- 5bffbad5 - Use GroupPlansPreloader linear ancestor scopes
-
adf3c545...b52f21df - 4 commits from branch
@ahegyi
, thanks for approving this merge request.This is the first time the merge request is approved. To ensure full test coverage, a new pipeline has been started.
For more info, please refer to the following links:
requested review from @alexpooley
requested review from @dgruzd
enabled an automatic merge when the pipeline for e2eff822 succeeds
mentioned in commit b2e8bd91
added workflowstaging-canary label
added workflowstaging label and removed workflowstaging-canary label
added workflowcanary label and removed workflowstaging label
added workflowproduction label and removed workflowcanary label
added releasedcandidate label
mentioned in merge request kubitus-project/kubitus-installer!306 (merged)
added releasedpublished label and removed releasedcandidate label