You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "xiong duan (Jira)" <ji...@apache.org> on 2026/01/15 10:44:00 UTC

[jira] [Commented] (CALCITE-7378) Potential incorrect column attribution in RelToSqlConverter due to implicit table alias handling

    [ https://issues.apache.org/jira/browse/CALCITE-7378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18052052#comment-18052052 ] 

xiong duan commented on CALCITE-7378:
-------------------------------------

The reproducible example SQL is invalid. The a and b are undefined.

> Potential incorrect column attribution in RelToSqlConverter due to implicit table alias handling
> ------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7378
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7378
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: zzwqqq
>            Priority: Major
>
> In dialects where `{{{}hasImplicitTableAlias{}}}is` true, even if a table is explicitly assigned an alias in the original SQL, the `RelToSqlConverter` will strip it away during the conversion. In scenarios like self-joins, if no explicit alias is provided, column references will be incorrectly attributed to the nearest table in the generated SQL structure.
> This issue also occurs when handle TPC-H Query 21.
> A minimal reproducible example:
> {code:java}
> select "product_name" 
> from "product" t1 
> where "product_id" in (select "product_id" 
> from "product" t2 
> where b."product_id" = a."product_id" and t1."product_id" = 2 and t2."product_id" = 1){code}
> after rel-to-sql
> {code:java}
> SELECT "product_name"
> FROM "foodmart"."product"
> WHERE "product_id" IN (SELECT "product_id"
> FROM "foodmart"."product"
> WHERE "product_id" = "product"."product_id" AND "product"."product_id" = 2 AND "product_id" = 1){code}
> {code:java}
> "product"."product_id" = 2 AND "product_id" = 1{code}
> The expression always evaluates to false.
> I suggest that when a correlated table alias shares the same name as the current table identifier, the table alias should be required.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)