Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planner don't generate SubqueryAlias #4483

Closed
jackwener opened this issue Dec 2, 2022 · 2 comments · Fixed by #4484
Closed

Planner don't generate SubqueryAlias #4483

jackwener opened this issue Dec 2, 2022 · 2 comments · Fixed by #4484
Labels
bug Something isn't working

Comments

@jackwener
Copy link
Member

jackwener commented Dec 2, 2022

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.

@jackwener jackwener added the bug Something isn't working label Dec 2, 2022
@jackwener
Copy link
Member Author

jackwener commented Dec 2, 2022

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

@jackwener
Copy link
Member Author

same problem with #4454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant