julianhyde commented on a change in pull request #2144:
URL: https://github.com/apache/calcite/pull/2144#discussion_r485407995



##########
File path: core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
##########
@@ -1640,6 +1640,21 @@ private void checkExponentialCnf(int n) {
         .expandedSearch(expanded);
   }
 
+  @Test void testSimplifyRange6() {
+    // An IS NULL condition would not usually become a Sarg,
+    // but here it is combined with another condition, and together they cross
+    // the complexity threshold.
+    final RexNode aRef = input(tInt(true), 0);
+    final RexNode bRef = input(tInt(true), 1);
+    // a in (1, 2) or b is null
+    RexNode expr = or(eq(aRef, literal(1)), eq(aRef, literal(2)), 
isNull(bRef));
+    final String simplified =
+        "OR(SEARCH($1, Sarg[, null]), SEARCH($0, Sarg[1, 2]))";
+    final String expanded = "OR(IS NULL($1), OR(=($0, 1), =($0, 2)))";
+    checkSimplify(expr, simplified)

Review comment:
       NULL isn't a value on the line -infinity to infinity, so it cannot be 
part of the range-set.
   
   Ideally we wouldn't create a Sarg with an empty range-set that allows NULL. 
It happened in this case because the complexity threshold isn't perfect (maybe 
we'll improve that later). We will always want to allow `Sarg[, null]` - it 
might occur if you intersect `Sarg[ < 2, null]` with `Sarg[ > 10, null]` - but 
hopefully we won't use it very often.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to