Could you please remove this clause:
and (acs_permission__permission_p
(package_id, '2173', 'read')
= 't'
or acs_permission__permission_p(package_id,
acs__magic_object_id('the_public'), 'read') = 't'
)
and tell us how long it the query takes and also could you post the resulting plan?
Thanks ...