Zhen Chen created CALCITE-6973:
----------------------------------

             Summary: Add rule for convert Minus to Filter
                 Key: CALCITE-6973
                 URL: https://issues.apache.org/jira/browse/CALCITE-6973
             Project: Calcite
          Issue Type: New Feature
            Reporter: Zhen Chen


Replaceing Minus with Filter when both inputs are from the same source with 
only filter conditions differing.
SQL like
{code:java}
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) {code}
Plan like
{code:java}
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]])
{code}
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.
 
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to