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

Double aggregate generated for in subquery with distinct

    XMLWordPrintableJSON

Details

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

    Description

      Repro:
      Add the following test to SqlToRelConverterTest.java.

      @Test public void testSubQueryIN() {
          final String sql = "select deptno\n"
              + "from EMP e\n"
              + "where deptno in (select distinct deptno\n"
              + "from EMP where empno=e.empno)";
          sql(sql).ok();
        }
      

      Plan:

      LogicalProject(DEPTNO=[$7])
        LogicalJoin(condition=[AND(=($0, $10), =($7, $9))], joinType=[inner])
          LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalAggregate(group=[{0, 1}])
            LogicalProject(DEPTNO=[$0], EMPNO=[$1])
              LogicalAggregate(group=[{0, 1}])
                LogicalProject(DEPTNO=[$7], EMPNO=[$0])
                  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      One LogicalAggregate would suffice. Although the 2 aggregates can be merged by rules described in issue CALCITE-1172, which is not available yet.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hyuan Haisheng Yuan
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: