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

Remove DISTINCT in aggregate function if field is unique

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.37.0
    • core

    Description

      For the sql

      select count(distinct x) cnt
      from(
         select distinct sal x from emp
      ) t  

      The distinct that in count can be removed.

      LogicalAggregate(group=[{}], CNT=[COUNT($0)])
        LogicalAggregate(group=[{0}])
          LogicalProject(X=[$5])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 

      But `CoreRules#AGGREGATE_REMOVE` not support it, so there are two DISTINCT.

      LogicalAggregate(group=[{}], CNT=[COUNT(DISTINCT $0)])
        LogicalAggregate(group=[{0}])
          LogicalProject(X=[$5])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 

      Attachments

        Issue Links

          Activity

            People

              jiajunbernoulli Jiajun Xie
              jiajunbernoulli Jiajun Xie
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: