Skip to content

Write the per-row read of a column from a source without column definitions only in the binding #2680

Open

Description

@mathiasrw

What happens today

In a join, a bare column name that no table defines can only come from a source without column definitions (?, a subquery in FROM, APPLY, a function, a table made without columns). Its value is read per row from the first of those sources whose row has the key, even when the value there is NULL.

The code for this read is written in two places. bind.write in src/engine/bind.js writes it with perRowJS, also for the 4.x rule firstWithColumn. Column.fromAnySource in src/expression/expression.js writes it again for Column.lookupJS and for the needsRuntimeResolution block of compileSelect1 in src/select/columns.js, which builds its own list of sources from query.aliases or query.sources.

What to change

  1. Add one writer in src/engine/bind.js, bind.anyJS(sc, aliases, context, columnid), with the logic of Column.fromAnySource. For each alias in order, a source whose column definitions have the name is read with ?. and ends the list, a source whose definitions lack it is skipped, and a source without definitions is asked whether its row has the key. bind.write uses it for ref.any and for firstWithColumn. Remove perRowJS.
  2. Column.lookupJS calls internal.bind.anyJS. Remove Column.fromAnySource.
  3. In compileSelect1, take the sources from internal.bind.aliases(query.columnScope). Remove the askAliases code and the APPLY special case. inOtherSource reads the scope with bind.has instead of query.sources[].columns.
  4. Update the header comment of src/engine/bind.js and the comment above Column.lookupJS.

What stays the same

  • Every result, column name and error text.
  • The generated code text. The parity check shows no code difference.
  • A row without the key reads the next source (test2873 C, test832).
  • A name that two tables define is still an error in a plain expression and keeps the 4.x rules firstTable and firstWithColumn.

Done when

  • A new test file named after this issue pins the rule in the select list, WHERE, ON, ORDER BY, GROUP BY, id + 0 and UPPER(id). Each case has a NULL in the first source and a row of the first source without the key, for FROM ? a JOIN ? b, a subquery in FROM and CROSS APPLY.
  • Column.fromAnySource and the askAliases code are gone.
  • The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.

Depends on

Nothing, can start now.

Activity

  1. added this to the v4.x Focus milestone on Oct 20, 2026
  2. changed the title [-]Review #2339 for code improvements: an unknown column takes its value from a different table per row[/-] [+]Write the per-row read of a column from a source without column definitions only in the binding[/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions