alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.98k stars 8.59k forks source link

[BUG] 对于子查询join的SQL解析出的字段所属表问题 #6209

Open jianglianggithub opened 3 weeks ago

jianglianggithub commented 3 weeks ago

Database Type

MYSQL

Database Version

5.7

Druid Version

1.2.24

JDK Version

OPENjdk 8

Error SQL

select a.name1, b.* from (select id , name1 from a) a join (select b.id , name2 from b) b on a.id = b.id 对于该SQL使用如下代码把b.*进行处理的时候出现解析结果不符合实际情况

SQLStatement stmt = SQLUtils.parseSingleStatement(sql, DbType.mysql); repository.resolve(stmt, ResolveAllColumn, ResolveIdentifierAlias); System.out.println(stmt.toString());

控制台输出的结果为

SELECT a.name1, a.id, b.name2
FROM (
    SELECT id, name1
    FROM a
) a
    JOIN (
        SELECT b.id, name2
        FROM b
    ) b
    ON a.id = b.id

正确的结果应该是

SELECT a.name1, b.id, b.name2
FROM (
    SELECT id, name1
    FROM a
) a
    JOIN (
        SELECT b.id, name2
        FROM b
    ) b
    ON a.id = b.id

我认为这是一个SQL解析的BUG

Testcase Code

No response

Stacktrace Info

No response

Error Info

No response