         UNION ALL
 
         SELECT
-            "locations_sqllocation"."id",
-            "locations_sqllocation"."parent_id",
-            array_append("fixture_ids"."path", "locations_sqllocation"."id") AS "path",
+            loc."id",
+            loc."parent_id",
+            array_append("fixture_ids"."path", loc."id") AS "path",
             "fixture_ids"."depth" + 1 AS "depth"
-        FROM "locations_sqllocation", "fixture_ids"
+        FROM "locations_sqllocation" loc
+        INNER JOIN "fixture_ids" ON loc."parent_id" = "fixture_ids"."id"
         WHERE
-            "locations_sqllocation"."is_archived" = FALSE
-            AND "locations_sqllocation"."domain" = domain_name
-            AND "locations_sqllocation"."parent_id" = "fixture_ids"."id"
+            loc."is_archived" = FALSE
+            AND loc."domain" = domain_name
             AND EXISTS (
                 SELECT 1
                 FROM "expand_from" U0

                            OR U0."depth" = -2
                            OR U0."depth" >= "fixture_ids"."depth" + 1
                        )
                        AND U0."loc_id" = "locations_sqllocation"."id"
                    ) OR (
                        (
                            U0."depth" = -2

    WITH RECURSIVE expand_to AS (
        WITH RECURSIVE cte AS (
            SELECT
                expand_to_type."parent_type_id",
                0 AS "depth",
                expand_to_type."id" AS "expand_to_type"
            FROM "locations_sqllocation" loc
            INNER JOIN "locations_locationtype" loc_type
                ON loc."location_type_id" = loc_type."id"
            INNER JOIN "locations_locationtype" expand_to_type
                ON expand_to_type."id" = loc_type."expand_to_id"
            WHERE
                loc."id" = ANY(user_location_ids_array)
                AND loc_type."expand_to_id" IS NOT NULL

            UNION ALL

            SELECT
                iwe_type."parent_type_id",
                0 AS "depth",
                -1 AS "expand_to_type"
            FROM "locations_sqllocation" loc
            INNER JOIN "locations_locationtype" loc_type
                ON loc."location_type_id" = loc_type."id"
            INNER JOIN "locations_locationtype" iwe_type
                ON loc_type."include_without_expanding_id" = iwe_type."id"
            WHERE
                loc."id" = ANY(user_location_ids_array)
                AND loc_type."include_without_expanding_id" IS NOT NULL

            UNION ALL

            SELECT
                loc_type."parent_type_id",
                "cte"."depth" + 1 AS "depth",
                "cte"."expand_to_type" AS "expand_to_type"
            FROM "locations_locationtype" loc_type
            INNER JOIN "cte" ON loc_type."id" = "cte"."parent_type_id"
        )

        SELECT
