Ambiguous column in an outer join ON filter reports "Invalid column" instead of "Ambiguous column"
Description
When two tables that are already in scope of an outer join's ON clause share a column name, and the
ON clause uses that name unqualified in a filter conjunct, QuestDB rejects the query with
Invalid column: <name>. The column exists; the actual problem is that the name is ambiguous. The
same name in an INNER JOIN ON clause, in WHERE, or in an outer join's equality key reports
Ambiguous column [name=<name>].
The misleading message makes users look for a missing or misspelled column instead of qualifying the name.
Reproduction
CREATE TABLE f1 (a1 INT, b1 INT, w INT);
INSERT INTO f1 VALUES (3, 2, 1), (2, 2, 2), (null, 1, 3), (3, 3, 2), (3, 1, 3);
SELECT * FROM f1 a LEFT JOIN f1 b ON b.a1 = a.a1 AND w > 1;
-- [53] Invalid column: w <- expected: Ambiguous column [name=w]
SELECT * FROM f1 a JOIN f1 b ON b.a1 = a.a1 AND w > 1;
-- [48] Ambiguous column [name=w]
SELECT * FROM f1 a JOIN f1 b ON b.a1 = a.a1 WHERE w > 1;
-- [50] Ambiguous column [name=w]
SELECT * FROM f1 a LEFT JOIN f1 b ON w = a.b1;
-- [37] Ambiguous column [name=w]RIGHT JOIN and FULL JOIN behave like LEFT JOIN (Invalid column: w).
Expected
Ambiguous column [name=w] at the position of w, consistent with the other forms. Rejecting the
query is correct: w has two holders among the tables joined so far.
Notes
- The likely throw site is
FunctionParser.createColumn()(SqlException.invalidColumn), reached whenSqlCodeGeneratorcompiles the outer join's filter: the lookup of the unqualified name in the join metadata returns no column, and the parser reports it as missing. (Inferred from the code; no stack trace was captured.) - Observed on e756069d95 (an ancestor of master 641aa5fee5) and on the PR #7674 branch (f23cd017bc, df59aabe25). The error position is correct; only the message is wrong.
JoinTest.testLeftJoinOnNameSharedWithLaterTable(PR #7674) asserts the currentInvalid column: wtext and would need updating with a fix.
Source: questdb/questdb