Skip to content

[CALCITE-7505] RelToSqlConverter produces duplicate FROM aliases for correlated subqueries when hasImplicitTableAlias() is true#5036

Open
Dwrite wants to merge 1 commit into
apache:mainfrom
Dwrite:CALCITE-7505
Open

[CALCITE-7505] RelToSqlConverter produces duplicate FROM aliases for correlated subqueries when hasImplicitTableAlias() is true#5036
Dwrite wants to merge 1 commit into
apache:mainfrom
Dwrite:CALCITE-7505

Conversation

@Dwrite

@Dwrite Dwrite commented Jun 21, 2026

Copy link
Copy Markdown

Jira Link
CALCITE-7505

This PR fixes incorrect SQL generation for correlated sub-queries in a Filter's WHERE clause when SqlDialect#hasImplicitTableAlias() is true.

The issue was that Filter did not preserve correlation variables, so RelToSqlConverter could not identify when the current node was the binding point of a correlation variable. As a result, required aliases could be omitted or duplicated, causing correlated references to resolve against the wrong scope.

The fix adds variablesSet to Filter/LogicalFilter and only applies correlation alias reset when the current Filter/Project actually binds the variable, the input row type matches, and the input is not a BiRel.

A follow-up change will cover similar correlated cases in Join conditions.

…correlated subqueries when hasImplicitTableAlias() is true
@sonarqubecloud

Copy link
Copy Markdown

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7505">[CALCITE-7505]
* RelToSqlConverter produces duplicate FROM aliases for correlated subqueries</a>. */
@Test void testExistsSubQueryAliasConflict() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this using hasImplicitTableAlias()?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants