Skip to content

Fix correlated subquery in HAVING cannot reference outer query column#37872

Merged
terrymanu merged 1 commit intoapache:masterfrom
jonasHanhan:fix/37431-having-correlated-subquery
Jan 28, 2026
Merged

Fix correlated subquery in HAVING cannot reference outer query column#37872
terrymanu merged 1 commit intoapache:masterfrom
jonasHanhan:fix/37431-having-correlated-subquery

Conversation

@jonasHanhan
Copy link
Contributor

Fixes #37431.

Changes proposed in this pull request:

  • Merge FROM tableBinderContexts into outerTableBinderContexts before binding HAVING clause expressions
  • This allows correlated subqueries in HAVING to resolve outer query table aliases (e.g., ref_0.c13)
  • Aligns HAVING binding behavior with WHERE binding path
  • Add unit test for HavingSegmentBinder
  • Add integration tests for correlated subqueries in HAVING clause (PostgreSQL, MySQL, openGauss)

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.
  • I have updated the Release Notes of the current development version.

When binding HAVING clause expressions, merge FROM tableBinderContexts
into outerTableBinderContexts before calling ExpressionSegmentBinder,
so that correlated subqueries can resolve outer query table aliases.

This aligns HAVING binding behavior with WHERE binding path.
@terrymanu terrymanu merged commit 2639820 into apache:master Jan 28, 2026
147 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correlated subquery in HAVING cannot reference outer query column, ColumnNotFoundException in PG

2 participants