Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4921

Nested NATURAL JOINs or JOINs with USING can't find common column

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.38.0
    • None

    Description

      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:

      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)

      Builds incorrect plan:

      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 }]])

      Queries with USING also have problems:

      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)

      Fails with:

      Column name 'A' in USING clause is not unique on one side of join

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              alex_pl Aleksey Plekhanov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: