fix(sql): a correlated reference over a derived table is not a missing column - #406
Merged
Merged
Conversation
…g column - The unknown-column check for derived tables treated a valid correlated reference (c.id in EXISTS (SELECT 1 FROM (SELECT a FROM x) d WHERE d.a = c.id)) as a column missing from the derived table. A name whose table alias belongs to an enclosing query is now correlated: one shared predicate (SubqueryScope.readsEnclosingScope) serves the router, the LATERAL walk and the check, so such statements get their true diagnosis back. - A HAVING that qualifies a SELECT-list alias (HAVING d.avg_salary > 1) gets a precise message naming the alias, instead of "move it to WHERE". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
fupelaqu
marked this pull request as ready for review
September 30, 2026 10:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
c.idinSELECT c.id FROM customers c WHERE EXISTS (SELECT 1 FROM (SELECT a FROM x) d WHERE d.a = c.id), as a column missing from the derived table ("Column 'c.id' is not projected by derived table 'd'"). A name whose table alias belongs to an enclosing query is now recognised as correlated. One shared predicate (SubqueryScope.readsEnclosingScope) serves the router, the LATERAL walk and the check, so these statements get their true diagnosis back (e.g. "cannot carry a derived table" from the relational engine).HAVING d.avg_salary > 1) now gets a precise message naming the alias, instead of "Move it to WHERE, or add its column to the GROUP BY".Verification
DerivedTableSpec(+7, including an 84-statement population) andHavingOverAggregateFunctionSpec(+2); 8 mutations go red.sql/test1,731 · bridges 256 / 249 ·core/test1,146 ·macrosTests/test30 ·+ compile· CI's lint line.arrowJoin/test379/379, including twoJoinPlannerSpectests that fail against the current snapshot;arrowExt/test67/67; the Elasticsearch 8.18 JOIN integration suite 91/91.Release notes
Known limitations (not changed here)
C.idfor aliasc) is not recognised as correlated.🤖 Generated with Claude Code