Original query:

explain WITH RECURSIVE "base_and_descendants" AS (
    (SELECT "namespaces".*
    FROM "namespaces"
    WHERE "namespaces"."type" = 'Group'
            AND "namespaces"."id" = 9970)
    UNION
        (SELECT "namespaces".*
        FROM "namespaces", "base_and_descendants"
        WHERE "namespaces"."type" = 'Group'
                AND "namespaces"."parent_id" = "base_and_descendants"."id"))
    SELECT "id"
FROM "base_and_descendants" AS "namespaces"
WHERE "namespaces"."id" NOT IN
    (SELECT "namespaces"."id"
    FROM "namespaces"
    WHERE "namespaces"."type" = 'Group'
            AND "namespaces"."id" = 9970)