Added external_aliases set to db.models.sql.Query

Sometimes a subquery can refer to outer query's alias. The inner query
must not quote the outer query's alias (PostgreSQL doesn't work with
quoted aliases). The external_aliases set adds information which aliases
are from the outer query.