Skip to content

In a join, an unqualified column that is NULL in the first source takes the value of the second source #2873

Closed

Description

@mathiasrw

In a join, an unqualified column that is NULL in the first source takes its value from the second source. WHERE x IS NULL stops finding the row, and x + 0 reads the other table's value.

var A = [{id: 1, x: null}, {id: 2, x: 20}];
var B = [{id: 1, x: 100}, {id: 2, x: 200}];
alasql('SELECT t0.id FROM ? t0 JOIN ? t1 ON t0.id = t1.id WHERE x IS NULL', [A, B]);
// [] (4.20.0: [{id: 1}])
alasql('SELECT t0.id, x + 0 AS v FROM ? t0 JOIN ? t1 ON t0.id = t1.id', [A, B]);
// [{id: 1, v: 100}, {id: 2, v: 20}] (4.20.0: v is missing for id 1)

Expected: the first query gives [{id: 1}], and v is NULL for id 1.

Since #2579 (in 4.21.0). An unqualified column that is not in defcols compiles to p['t0']?.['x'] ?? p['t1']?.['x'] (Column.toJS and Column.fromAnySource in src/expression/expression.js, and its use in src/select/columns.js), so a NULL falls through to the next source. It affects WHERE, ON, ORDER BY, GROUP BY and computed columns. The fix: go to the next source only when the row has no such property ('x' in p['t0']), not when the value is NULL, and add a test with NULL in the first source (test E of #2579 has no NULL).

Breaking?

No. It restores the result of 4.20.0.

Activity

  1. added a commit that references this issue on Oct 26, 2026
    253a10f
  2. added this to the v4.x Focus milestone on Oct 27, 2026
  3. added a commit that references this issue on Oct 28, 2026
    7a395a0
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