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

Add rule to convert Minus to Filter

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.40.0
    • None

    Description

      Replaceing Minus with Filter when both inputs are from the same source with only filter conditions differing.
      SQL like

      SELECT mgr, comm FROM emp WHERE mgr = 12
      EXCEPT
      SELECT mgr, comm FROM emp WHERE comm = 5
      ==>
      SELECT DISTINCT mgr, comm FROM emp
      WHERE mgr = 12 AND NOT(comm = 5) 

      Plan like

      LogicalMinus(all=[false])
        LogicalFilter(condition=[=($0, 12)])
          LogicalProject(MGR=[$3], COMM=[$6])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
        LogicalFilter(condition=[=($1, 5)])
          LogicalProject(MGR=[$3], COMM=[$6])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      
      ==>
      
      LogicalAggregate(group=[{0, 1}])
        LogicalFilter(condition=[AND(=($0, 12), <>($1, 5))])
          LogicalProject(MGR=[$3], COMM=[$6])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      Some plans may contain complex alternating Filter and Project, which are not handled by this rule. Prerequisite rules are required to normalize such cases first. Currently only supports ALL is false and 2-way Minus.
       
       

      Attachments

        Issue Links

          Activity

            People

              jensen Zhen Chen
              jensen Zhen Chen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: