Skip to content

Planner don't generate SubqueryAlias #4483

Closed

Description

@jackwener

Describe the bug

To Reproduce

CREATE TABLE IF NOT EXISTS t1 AS VALUES(1,'HELLO'),(12,'DATAFUSION');
CREATE TABLE IF NOT EXISTS t2 AS VALUES(1,'HELLO'),(12,'DATAFUSION');

explain select * from ((select column1 from t1) INNER JOIN (select column1 from t2) on t1.column1 = t2.column1) as f;
+---------------+----------------------------------------------------------------------------------------------------------------------------------------+
| plan_type     | plan                                                                                                                                   |
+---------------+----------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan  | Projection: t1.column1, t2.column1                                                                                                     |
|               |   Inner Join: t1.column1 = t2.column1                                                                                                  |
|               |     Projection: t1.column1                                                                                                             |
|               |       TableScan: t1 projection=[column1]                                                                                               |
|               |     Projection: t2.column1                                                                                                             |
|               |       TableScan: t2 projection=[column1]                                                                                               |

There isn't subquery f
When we select f.column1 from ((select column1 from t1) INNER JOIN (select column1 from t2) on t1.column1 = t2.column1) as f;

We can't find f.column1, just exist t1.column1.

BTW, this plan is wrong.
Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Activity

  1. jackwener commented on Dec 2, 2022

    @jackwener
    MemberAuthor

    Look like test nestedjoin_with_alias() also is wrong

     explain verbose select * from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;
    +------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
    | plan_type                                                  | plan                                                                                                                       |
    +------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
    | initial_logical_plan                                       | Projection: c.a, c.b, e.a, e.d                                                                                             |
    |                                                            |   Inner Join: c.a = e.a                                                                                                    |
    |                                                            |     SubqueryAlias: c                                                                                                       |
    |                                                            |       Projection: Int64(1) AS a, Int64(2) AS b                                                                             |
    |                                                            |         EmptyRelation                                                                                                      |
    |                                                            |     SubqueryAlias: e                                                                                                       |
    |                                                            |       Projection: Int64(1) AS a, Int64(3) AS d                                                                             |
    |                                                            |         EmptyRelation                                                                                                      |
    

    I think this sql should be wrong, when we select f.a from it, f.a exist two.

    pg
    select f.a from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;
    Help: db error: ERROR: column reference "a" is ambiguous
    sqlite
    select * from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;
    ambiguous column name: a
  2. jackwener commented on Dec 2, 2022

    @jackwener
    MemberAuthor

    same problem with #4454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions