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

ReduceExpressionRule may oversimplify filter conditions containing nulls

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.18.0
    • Component/s: None
    • Labels:
      None

      Description

      ReduceExpressionsRule is invoking simplifications - by using ExprSimplifier which unfortunately doesn't switch unknownAs mode (because it's a visitor).

      Can be reproduced by adding the following test case to RelOptRulesTests

        @Test public void testIncorrectlyRemovedCondition() {
          HepProgram program = new HepProgramBuilder()
              .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
              .build();
      
          String sql =
              //        "select * from emp where ( (empno=1 and mgr=1) or (empno=null and mgr=1) ) is null";
              "select * from emp where ( (empno=null and mgr=1) ) is null";
          checkPlanning(program, sql);
        }
      

      Plan should retain the condition; right now it incorrectly simplified to false.

          <TestCase name="testIncorrectlyRemovedCondition">
              <Resource name="sql">
                  <![CDATA[select * from emp where ( (empno=null and mgr=1) ) is null]]>
              </Resource>
              <Resource name="planBefore">
                  <![CDATA[
      LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
        LogicalFilter(condition=[IS NULL(AND(=($0, null), =($3, 1)))])
          LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      ]]>
              </Resource>
              <Resource name="planAfter">
                  <![CDATA[
      LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
        LogicalValues(tuples=[[]])
      ]]>
              </Resource>
          </TestCase>
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kgyrtkirk Zoltan Haindrich
                Reporter:
                kgyrtkirk Zoltan Haindrich
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: