postgresql7.1
select e.element_id, e.name, m.sort_key
from portal_elements e, portal_element_map m
where
e.element_id = m.element_id and
m.portal_id = :portal_id and
m.region = :region and
acs_permission__permission_p(e.element_id, :user_id, 'read') = 't'
order by m.sort_key
select count(*) as all_count
from portal_element_map
where portal_id = :portal_id and acs_permission__permission_p(element_id, :user_id, 'read') = 't'
select count(*) as all_count
from portal_element_map
where
portal_id = :portal_id and acs_permission__permission_p(element_id, :user_id, 'read') = 't'
and region not like 'i%'