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

Add ambiguous check when generate selection plan #4196

Closed
ygf11 opened this issue Nov 14, 2022 · 0 comments · Fixed by #5153
Closed

Add ambiguous check when generate selection plan #4196

ygf11 opened this issue Nov 14, 2022 · 0 comments · Fixed by #5153
Labels
bug Something isn't working

Comments

@ygf11
Copy link
Contributor

ygf11 commented Nov 14, 2022

Describe the bug
Datafusion will try to generate inner join plan for selection, but it does not do ambiguous check.
For example:

❯ explain select * from test0, test1 where c0 = c0 + 1;
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type     | plan                                                                                                                                                                    |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan  | Projection: test0.c0, test0.c1, test0.c2, test0.c3, test0.c4, test0.c5, test1.c0, test1.c1, test1.c2, test1.c3, test1.c4, test1.c5                                      |
|               |   CrossJoin:                                                                                                                                                            |
|               |     Projection: test0.c0, test0.c1, test0.c2, test0.c3, test0.c4, test0.c5                                                                                              |
|               |       Filter: CAST(test0.c0 AS Int64)test0.c0 = CAST(test0.c0 AS Int64)test0.c0 + Int64(1)                                                                              |
|               |         Projection: CAST(test0.c0 AS Int64) AS CAST(test0.c0 AS Int64)test0.c0, test0.c0, test0.c1, test0.c2, test0.c3, test0.c4, test0.c5                              |
|               |           TableScan: test0 projection=[c0, c1, c2, c3, c4, c5], partial_filters=[CAST(test0.c0 AS Int64) = CAST(test0.c0 AS Int64) + Int64(1)]                          |
|               |     TableScan: test1 projection=[c0, c1, c2, c3, c4, c5]        

In PostgreSQL, this will throw an error:

psql -d "$POSTGRES_DB" -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -c "explain select * from test0 as t0 inner join test0 as t1 on c0 = c0;"
ERROR:  column reference "c0" is ambiguous
LINE 1: ...select * from test0 as t0 inner join test0 as t1 on c0 = c0;
                                                               ^

The semantics of this sql is not clear, we need throw exception like PostgreSQL do.

To Reproduce
Create two tables -- test0 and test1, which has same schema.

run sql explain select * from test0, test1 where c0 = c0 + 1.

Expected behavior

Additional context

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
Development

Successfully merging a pull request may close this issue.

1 participant