Hello Alexandr,
I agree with Anssi and you that adding a method to perform a subquery pushdown would be useful.
FWIW #24462 and #28333 are not the only tickets where that was proposed as a solution.
Searching for "subquery" and "pushdown" should bring a few other tickets.
There are also internal cases where the ORM performs automatically (e.g. in sql.Query.get_aggregation)
so it might be worth trying to refactor these to use a common Query.as_subquery (better name welcome) first.
There's an existing ticket to unify the handling of subqueries[0] that should be a good introduction to the
changes require to add this method[0].
Regarding 3. I think we should simple raise a FieldError in this particular case to require other_field to
be included in the .values(). We've tried automatically selecting fields in the past when they were missing
and it lead to unexpected behavior[1]. Since this would be a new API we'd have the luxury on being really
strict on supported use case at first at lax the requirements later on if we deem it appropriate.
I would assume a .subquery() that isn't preceded by a .values() would result in a SELECT * FROM (...)?
Cheers,
Simon