Optimize get_ascending using unnest
The Postgres database function unnest
lets us get items from an array as separate rows. We can use this to fetch all the parent elements from an element in a single query instead of loading paths in RAM as get_ascending
, get_ascendings
, get_ascending_paths
, get_ascendings_paths
currently do; here is an SQL query I tested in pgAdmin:
select * from documents_element where id in (
select unnest(path) from documents_elementpath where element_id = '000c1179-1026-427f-bcbc-dfb3a2dfe8ac'::uuid
);