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

ReduceExpressionsRule applied to 'IN subquery' should make the values distinct if the subquery is a Values composed of literals

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.38.0
    • 1.40.0
    • core

    Description

      Currently IN operator would not distinct values.

      for example  in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1)  transform to in (1,2,3) is better, but currently would be  in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1) without distinct.

      Like case follow:

      test case:

       

      @Test void testReduceExpressionsWithIn()
      { final String sql = "select deptno, sal " + "from emp " + "where deptno in (1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1) "; sql(sql).withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS) .check(); }
      

       

       
      plan would be:

      LogicalProject(DEPTNO=[$7], SAL=[$5])
      LogicalFilter(condition=[IN($7,
      { LogicalValues(tuples=[[
      { 1 }
      , { 1 }, { 2 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 3 }, { 1 }]])
      })])
      LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 

       

      we should distinct Values and consider a  more generic and simple way we can add a AggregateValueReduceRule to distinct Values

      which plan should convert to:

      LogicalProject(DEPTNO=[$7], SAL=[$5])
        LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
          LogicalJoin(condition=[=($7, $9)], joinType=[inner])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
            LogicalValues(tuples=[[{ 1 }, { 3 }]])

      Attachments

        Activity

          People

            xuzifu666 Yu Xu
            xuzifu666 Yu Xu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: