zzwqqq created CALCITE-7378:
-------------------------------
Summary: 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
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:
```
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)
```
after rel-to-sql
```
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)
```
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)