hoist select queryAccessibleObjectUuidsOfSubjectIds(...) into WITH CTE for better performance

This commit is contained in:
Michael Hoennig 2022-10-17 12:18:12 +02:00
parent 368da1cc95
commit 63db939583

View File

@ -143,13 +143,15 @@ begin
/*
Creates a restricted view based on the 'view' permission of the current subject.
*/
-- TODO.refa: hoist `select queryAccessibleObjectUuidsOfSubjectIds(...)` into WITH CTE for performance
sql := format($sql$
set session session authorization default;
create view %1$s_rv as
with accessibleObjects as (
select queryAccessibleObjectUuidsOfSubjectIds('view', '%1$s', currentSubjectsUuids())
)
select target.*
from %1$s as target
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', '%1$s', currentSubjectsUuids()))
where target.uuid in (select * from accessibleObjects)
order by %2$s;
grant all privileges on %1$s_rv to restricted;
$sql$, targetTable, orderBy);