I have also observed that breaking a query with subqueries into two or
more steps with tables for the interfaces can outperform subqueries by
a substantial amount. Apparently the query planner has much better
knowledge of the scope of the queries. Having discrete tables also
allows building indexes (effectively cross-table indexes) specially
tailored for the final query.