Skip to content

fix(sql): a correlated reference over a derived table is not a missing column - #406

Merged
fupelaqu merged 1 commit into
mainfrom
fix/correlated-reference-over-derived-table
Sep 30, 2026
Merged

fupelaqu merged 1 commit into
mainfrom
fix/correlated-reference-over-derived-table

Conversation

@fupelaqu

Copy link
Copy Markdown
Contributor

Summary

  • Correlated references over a derived table. The unknown-column check added by fix(sql): derived tables over UNNEST name columns by their short name; up to 100 elements per parent #404 treated a valid correlated reference, e.g. c.id in SELECT 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 over a qualified SELECT-list alias (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

  • Before / after measurement: 75 correlated statements, run on core just before fix(sql): derived tables over UNNEST name columns by their short name; up to 100 elements per parent #404, on current main and with this fix, through core alone (Elasticsearch 8.18.3) and through the arrow extension (8.18.3 and 6.8.23). No statement answered correctly before is refused or wrong now, and the fix restores the pre-fix(sql): derived tables over UNNEST name columns by their short name; up to 100 elements per parent #404 diagnoses.
  • Unit: DerivedTableSpec (+7, including an 84-statement population) and HavingOverAggregateFunctionSpec (+2); 8 mutations go red.
  • Suites: sql/test 1,731 · bridges 256 / 249 · core/test 1,146 · macrosTests/test 30 · + compile · CI's lint line.
  • softclient4es-arrow main (unchanged) against this core: arrowJoin/test 379/379, including two JoinPlannerSpec tests that fail against the current snapshot; arrowExt/test 67/67; the Elasticsearch 8.18 JOIN integration suite 91/91.
  • Parse cost: neutral (−0.02 % on the probe's sum of medians).

Release notes

  • Statements that were refused with "Column '.' is not projected by derived table …" get their real refusal message again. No statement changes verdict.
  • A HAVING over a qualified SELECT-list alias gets a precise message.

Known limitations (not changed here)

  • A qualifier written in another case (C.id for alias c) is not recognised as correlated.
  • An unqualified outer name over a lone derived table is refused as not projected.

🤖 Generated with Claude Code

…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
fupelaqu marked this pull request as ready for review September 30, 2026 10:01
@fupelaqu
fupelaqu merged commit a04f123 into main Sep 30, 2026
4 checks passed
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.

1 participant