You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Stamatis Zampetakis (Jira)" <ji...@apache.org> on 2026/05/22 08:37:00 UTC

[jira] [Updated] (CALCITE-7378) RelToSqlConverter generates incorrect column reference when hasImplicitTableAlias is true

     [ https://issues.apache.org/jira/browse/CALCITE-7378?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stamatis Zampetakis updated CALCITE-7378:
-----------------------------------------
    Summary: RelToSqlConverter generates incorrect column reference when hasImplicitTableAlias is true  (was: Potential incorrect column attribution in RelToSqlConverter due to implicit table alias handling)

> RelToSqlConverter generates incorrect column reference when hasImplicitTableAlias is true
> -----------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7378
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7378
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: zzwqqq
>            Assignee: zzwqqq
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.42.0
>
>
> 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" not in (
>     select "product_id" 
>     from "product" t2 
>     where t2."product_id" = t1."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_id" = "product"."product_id" AND "product"."product_id" = 2 AND "product_id" = 1{code}
> *In the new expression, all the "product_id" come from the nearest table, but in the original SQL, it comes from t1 and t2 respectively.* And the new 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)