pub(super) fn subquery_alias_inner_query_and_columns(
subquery_alias: &SubqueryAlias,
) -> (&LogicalPlan, Vec<Ident>)Expand description
This logic is to work out the columns and inner query for SubqueryAlias plan for some types of subquery or unnest
(SELECT column_a as a from table) AS A(SELECT column_a from table) AS A (a)SELECT * FROM t1 CROSS JOIN UNNEST(t1.c1) AS u(c1)(see find_unnest_column_alias)
A roundtrip example for table alias with columns
query: SELECT id FROM (SELECT j1_id from j1) AS c (id)
LogicPlan: Projection: c.id SubqueryAlias: c Projection: j1.j1_id AS id Projection: j1.j1_id TableScan: j1
Before introducing this logic, the unparsed query would be SELECT c.id FROM (SELECT j1.j1_id AS id FROM (SELECT j1.j1_id FROM j1)) AS c.
The query is invalid as j1.j1_id is not a valid identifier in the derived table
(SELECT j1.j1_id FROM j1)
With this logic, the unparsed query will be:
SELECT c.id FROM (SELECT j1.j1_id FROM j1) AS c (id)
Caveat: this won’t handle the case like select * from (select 1, 2) AS a (b, c)
as the parser gives a wrong plan which has mismatch Int(1) types: Literal and
Column in the Projections. Once the parser side is fixed, this logic should work