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

same table alias is allowed in MySQL when tables come from different database #25364

Open
longfeiss opened this issue Jun 11, 2021 · 4 comments
Assignees

Comments

@longfeiss
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create database test;
create database other_db;
use test
create table a(id int, name varchar(255));
create table other_db.a(id int, name varchar(255));
select * from a as foo, other_db.a as foo;

2. What did you expect to see? (Required)

no error

3. What did you see instead (Required)

ERROR 1066 (42000): Not unique table/alias: 'foo'

4. What is your TiDB version? (Required)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: None
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
@yudongusa
Copy link

seems a similar issue: #24663

@winoros
Copy link
Member

winoros commented Nov 22, 2021

@oops-lgtm Hi, may i ask that where do you meet this problem?

@winoros
Copy link
Member

winoros commented Nov 23, 2021

mysql> select * from a as foo, other_db.a as foo;
Field   1:  `id`
Catalog:    `def`
Database:   `test`
Table:      `foo`
Org_table:  `a`
Type:       LONG
Collation:  binary (63)
Length:     11
Max_length: 0
Decimals:   0
Flags:      NUM

Field   2:  `name`
Catalog:    `def`
Database:   `test`
Table:      `foo`
Org_table:  `a`
Type:       VAR_STRING
Collation:  utf8mb4_0900_ai_ci (255)
Length:     1020
Max_length: 0
Decimals:   0
Flags:

Field   3:  `id`
Catalog:    `def`
Database:   `other_db`
Table:      `foo`
Org_table:  `a`
Type:       LONG
Collation:  binary (63)
Length:     11
Max_length: 0
Decimals:   0
Flags:      NUM

Field   4:  `name`
Catalog:    `def`
Database:   `other_db`
Table:      `foo`
Org_table:  `a`
Type:       VAR_STRING
Collation:  utf8mb4_0900_ai_ci (255)
Length:     1020
Max_length: 0
Decimals:   0
Flags:


0 rows in set (0.00 sec)

When you create the table alias, MySQL holds the database name unchanged. It's against other databases like PostgreSQL, Oracle, and SQL Server. (They all throw out errors).
Maybe we don't need to be compatible with it.

@winoros
Copy link
Member

winoros commented Nov 23, 2021

For me, clearing the database name when you set an alias is a more comfortable behavior. And this can make our codes cleaner than be compatible with the MySQL.

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

Successfully merging a pull request may close this issue.

6 participants