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

Enhance RexSimplify to handle (x<>a or x<>b)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.20.0
    • 1.21.0
    • None

    Description

      Currently, ReduceExpressionsRule.FILTER_INSTANCE can successfully reduce a query like this one (see RelOptRulesTest#testReduceConstantsDup):

      // query:
      select d.deptno from dept d where d.deptno=7 and d.deptno=8
      
      // plan before:
      LogicalProject(DEPTNO=[$0])
        LogicalFilter(condition=[AND(=($0, 7), =($0, 8))])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      
      // plan after:
      LogicalProject(DEPTNO=[$0])
        LogicalValues(tuples=[[]])
      

      As we can see, since the filter is 'always false', the LogicalTableScan+LogicalFilter are correctly replaced by an empty LogicalValues.

      However, the same filter with a NOT expression, is not correctly simplified:

      // query:
      select d.deptno from dept d where not(d.deptno=7 and d.deptno=8)
      
      // plan before:
      LogicalProject(DEPTNO=[$0])
        LogicalFilter(condition=[NOT(AND(=($0, 7), =($0, 8)))])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      
      // plan after (actual, NOT distributivity for AND):
      LogicalProject(DEPTNO=[$0])
        LogicalFilter(condition=[OR(<>($0, 7), <>($0, 8))])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      
      // plan after (expected, when $0's type is NOT nullable, filter removed):
      LogicalProject(DEPTNO=[$0])
        LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      
      // plan after (expected, when $0's type IS nullable, filter simplified as IS NOT NULL):
      LogicalProject(DEPTNO=[$0])
        LogicalFilter(condition=[IS NOT NULL($0)])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      

      Attachments

        Issue Links

          Activity

            People

              rubenql Ruben Q L
              rubenql Ruben Q L
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 9h 10m
                  9h 10m