Remove temporary table usage for read-only queries
Read-only queries make use of temporary tables. This means we cannot do them on a physical replica, such as the azure replica, as it's impossible to use temporary tables there.
We need to refactor most of our read-only queries to avoid temporary tables. This should also reduce the churn on the PostgreSQL catalog tables.
Migrated from T1073 (view on Phabricator)