Skip to content

Resolve cross-db queries for Runner scopes

Furkan Ayhan requested to merge 336433-342229-cross-db-queries into master

What does this MR do and why?

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.

Edited by Furkan Ayhan

Merge request reports