Resolve cross-db queries for Runner scopes
What does this MR do and why?
This MR is based on !74900 (merged).- This MR resolves cross-db queries for Runner scopes. #336433 (closed) and #342229 (closed).
- The changes are behind a feature flag
ci_find_runners_by_ci_mirrors
#347226 (closed).
Database
Ci::Runner.belonging_to_group_and_ancestors
New SQL queries
SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 14525430
LIMIT 1;
-- https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7920/commands/28360
SELECT "ci_runners".*
FROM "ci_runners"
INNER JOIN "ci_runner_namespaces" ON "ci_runner_namespaces"."runner_id" = "ci_runners"."id"
WHERE "ci_runner_namespaces"."namespace_id" IN (4249178,6751949,7963968,14240053,14525430);
-- https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7920/commands/28362
previous query:
SELECT "ci_runners".*
FROM "ci_runners"
INNER JOIN "ci_runner_namespaces" ON "ci_runner_namespaces"."runner_id" = "ci_runners"."id"
WHERE "ci_runner_namespaces"."namespace_id" IN (
WITH
"base_ancestors_cte" AS MATERIALIZED (SELECT "namespaces"."id", "namespaces"."traversal_ids" FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 14525430),
"ancestors_cte" AS MATERIALIZED (SELECT id as base_id, unnest(traversal_ids) as ancestor_id FROM "base_ancestors_cte")
SELECT DISTINCT "namespaces"."id" FROM "ancestors_cte", "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "ancestors_cte"."ancestor_id"
);
-- https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7920/commands/28364
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.
Edited by Furkan Ayhan