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

When simplifying NOT-AND-OR, RexSimplify incorrectly applies predicates deduced for operands to the same operands

    XMLWordPrintableJSON

    Details

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

      Description

      When simplifying NOT-AND-OR, RexSimplify incorrectly applies predicates deduced for operands to the same operands.

      Here is the test case (add it to RexProgramTest):

        @Test public void testSimplifyNotAnd() {
          final RexNode e = not(
              and(
                  gt(and(vBool(1), literal(true)),
                      or(literal(true), literal(true), literal(false))),
                  gt(isNotNull(vBool(0)), eq(literal(false), vBool(1))),
                  or(ne(literal(true), literal(false)),
                      ge(vInt(0), literal((Integer) null)))));
          final String expected = "TODO";
         checkSimplify(e, expected);
        }
      

      When you run it, verify will find a combination of assignments such that the simplified expression returns a different result than the original.

      The test case is not minimal; sorry. Maybe it reproduces with NOT-OR.

      The bug is in RexSimplify.simplifyAndTerms. Put a breakpoint at that line to see the problem. It passes through the operands once, building a list of predicates. Then it passes through the operands again, simplifying each operand. Thus operand1 is simplified using a list of predicates that includes the predicate 'not operand1'. Clearly wrong. Zoltan Haindrich, I warned that this was possible in our discussions.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: