From 6dd20db238b471083491fe3c080e69811d6a8026 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 22 Aug 2024 14:31:15 +0200 Subject: [PATCH] improved formatting --- ...e-cte-experiments-for-accessible-uuids.sql | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/sql/recursive-cte-experiments-for-accessible-uuids.sql b/sql/recursive-cte-experiments-for-accessible-uuids.sql index 62f88bc2..296fa71a 100644 --- a/sql/recursive-cte-experiments-for-accessible-uuids.sql +++ b/sql/recursive-cte-experiments-for-accessible-uuids.sql @@ -29,21 +29,23 @@ BEGIN -- 'hs_booking_project#D-1000300-mihdefaultproject:ADMIN'); SET TRANSACTION READ ONLY; - FOR i IN 0..25 LOOP + FOR i IN 0..0 LOOP letter := chr(i+ascii('a')); perform count(*) from ( + + -- start of VIEW hs_hosting_asset_rv: with accessible_hs_hosting_asset_uuids as ( with recursive - recursive_grants as - (select distinct rbacgrants.descendantuuid, + recursive_grants as ( + select distinct rbacgrants.descendantuuid, rbacgrants.ascendantuuid, 1 as level, true from rbacgrants - where rbacgrants.assumed - and (rbacgrants.ascendantuuid = any (currentsubjectsuuids())) + where (rbacgrants.ascendantuuid = any (currentsubjectsuuids())) + --and rbacgrants.assumed union all select distinct g.descendantuuid, g.ascendantuuid, @@ -51,44 +53,38 @@ BEGIN assertTrue(grants.level < 22, 'too many grant-levels: ' || grants.level) from rbacgrants g join recursive_grants grants on grants.descendantuuid = g.ascendantuuid - where g.assumed), - grant_count as (select count(*) as grant_count - from recursive_grants), - count_check as (select assertTrue((select grant_count from grant_count) < 600000, - 'too many grants for current subjects: ' || - (select grant_count from grant_count)) - as valid) + where g.assumed + ), + grant_count as ( + select count(*) as grant_count from recursive_grants + ), + count_check as ( + select assertTrue((select grant_count from grant_count) < 600000, + 'too many grants for current subjects: ' || (select grant_count from grant_count)) as valid + ) select distinct perm.objectuuid from recursive_grants join rbacpermission perm on recursive_grants.descendantuuid = perm.uuid join rbacobject obj on obj.uuid = perm.objectuuid join count_check cc on cc.valid where obj.objecttable::text = 'hs_hosting_asset'::text - and obj.type = 'EMAIL_ADDRESS'::hshostingassettype + and obj.type = 'EMAIL_ADDRESS'::hshostingassettype -- with/without this type condition ) + -- end of VIEW hs_hosting_asset_rv. + + -- start of business query, usually based on a view according to the above CTE query: select type, - -- count(*) as counter target.uuid, - -- target.version, - -- target.bookingitemuuid, - -- target.type, - -- target.parentassetuuid, - -- target.assignedtoassetuuid, target.identifier, target.caption - -- target.config, - -- target.alarmcontactuuid from hs_hosting_asset target where (target.uuid in (select accessible_hs_hosting_asset_uuids.objectuuid from accessible_hs_hosting_asset_uuids)) and target.type = 'EMAIL_ADDRESS' and identifier like letter || '%' - -- and target.type in ('EMAIL_ADDRESS', 'CLOUD_SERVER', 'MANAGED_SERVER', 'MANAGED_WEBSPACE') - -- order by target.identifier; - -- group by type - -- order by counter desc -) timed; -END LOOP; + -- end of business query. + ) timed; + END LOOP; end_time := clock_timestamp(); total_time := end_time - start_time;