At the moment the alias registry is global for the whole query. I propose
that we should scope this by "query spec" (combined with parent). The
reason being that reusing the same alias in unrelated subqueries is
perfectly fine.
select ...
from Customer c
where c.id in (
select o.customer.id
from Order o
...
)
or c.id in (
select c1.id
from Outstanding o
...
)
Here the aliases `o` don't ever infringe on each other. So imo we should
allow that.
The piece about checking the parent is for a case like:
select ...
from Customer c
where c.id in (
select c.id
from Order o
join o.customer c
...
)
Here the aliases `c` do infringe. In the subquery, we don't really know
which reference the `c` alias should resolve to. We *could* here assuming
that the subquery is uncorrelated. Bu without this rule we really would
not know that the subquery is correlated. Hopefully that makes sense, what
I am getting at.
WDYT?