Aleksey Plekhanov created CALCITE-4921: ------------------------------------------
Summary: Nested NATURAL JOINs or JOINs with USING can't find common column Key: CALCITE-4921 URL: https://issues.apache.org/jira/browse/CALCITE-4921 Project: Calcite Issue Type: Bug Reporter: Aleksey Plekhanov {{SqlValidatorUtil#deriveNaturalJoinColumnList}} can't correctly derive common columns for JOIN if the left hand of it is another NATURAL JOIN or JOIN with USING. For example: {noformat} SELECT * FROM (values (1, 1)) as t1(a, b) NATURAL JOIN (values (1, 1)) as t2(a, c) NATURAL JOIN (values (1, 1)) as t3(a, d){noformat} Builds incorrect plan: {noformat} LogicalProject(A=[$0], B=[$1], C=[$3], A1=[$4], D=[$5]) LogicalJoin(condition=[true], joinType=[inner]) LogicalJoin(condition=[=($0, $2)], joinType=[inner]) LogicalValues(tuples=[[{ 1, 1 }]]) LogicalValues(tuples=[[{ 1, 1 }]]) LogicalValues(tuples=[[{ 1, 1 }]]){noformat} Queries with USING also have problems: {noformat} SELECT * FROM (values (1, 1)) as t1(a, b) JOIN (values (1, 1)) as t2(a, c) USING (a) JOIN (values (1, 1)) as t3(a, d) USING (a){noformat} Fails with: {noformat} Column name 'A' in USING clause is not unique on one side of join{noformat} -- This message was sent by Atlassian Jira (v8.20.1#820001)