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

Simplify 'p OR (p IS NOT TRUE)' to 'TRUE'

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.36.0
    • None

    Description

      Statements of the form 'P OR P IS NOT TRUE' to 'TRUE' should always be true (please correct me if I am wrong):

      > select x, X='A' as EQ, 
                  X='A' IS NOT TRUE as EQ_NOT_TRUE,
                  (X='A') OR ((X='A') IS NOT TRUE) as EQ_OR_EQ_NOT_TRUE
      from (values 'A', 'B', null) as t(x);
      +---+-------+-------------+-------------------+
      | X |  EQ   | EQ_NOT_TRUE | EQ_OR_EQ_NOT_TRUE |
      +---+-------+-------------+-------------------+
      | A | true  | false       | true              |
      | B | false | true        | true              |
      |   |       | true        | true              |
      +---+-------+-------------+-------------------+
      

      Here a test case for the expected behavior:

      @Test void testSimplifyPOrPNotTrue() {
        checkSimplify(
            and(
                vBool(),
                or(
                    eq(vInt(), literal(1)),
                    isNotTrue(eq(vInt(), literal(1)))
                )),
            "?0.bool0");
      }

      There are some other, similar expressions, such as 'P IS NOT FALSE OR NOT P', which can be reduced to true. Maybe there's a way to handle all of them?

      Attachments

        Issue Links

          Activity

            People

              hongyuguo hongyu guo
              thomas.rebele Thomas Rebele
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: