asolimando commented on code in PR #3143:
URL: https://github.com/apache/calcite/pull/3143#discussion_r1166645953


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -1793,16 +1761,51 @@ private <C extends Comparable<C>> RexNode 
simplifyAnd2ForUnknownAsFalse(
         return rexBuilder.makeLiteral(false);
       }
     }
-    // Add the NOT disjunctions back in.
-    for (RexNode notDisjunction : notTerms) {
-      terms.add(not(notDisjunction));
-    }
     // The negated terms: only deterministic expressions
     for (RexNode negatedTerm : negatedTerms) {
       if (termsSet.contains(negatedTerm)) {
         return rexBuilder.makeLiteral(false);
       }
     }
+    // Add the NOT disjunctions back in.
+    for (RexNode notDisjunction : notTerms) {
+      terms.add(not(notDisjunction));
+    }
+    // Find operands that make will let whole expression evaluate to FALSE if 
set to NULL
+    final Set<RexNode> strongOperands = new HashSet<>();
+    for (RexNode term : terms) {
+      if (!RexUtil.isDeterministic(term)) {
+        continue;
+      }
+      VariableCollector collector = new VariableCollector();
+      term.accept(collector);
+      for (RexInputRef ref : collector.refs) {
+        if (Strong.isNotTrue(term, ImmutableBitSet.of(ref.index))) {
+          strongOperands.add(ref);
+        }
+      }
+      RexUtil.FieldAccessFinder fieldAccessFinder = new 
RexUtil.FieldAccessFinder();
+      term.accept(fieldAccessFinder);
+      for (RexFieldAccess rexFieldAccess : 
fieldAccessFinder.getFieldAccessList()) {
+        if (Strong.of(ImmutableSet.of(rexFieldAccess)).isNotTrue(term)) {

Review Comment:
   Nit: I personally prefer to move complex `if` conditions out of the `if` 
itself, not a big deal to leave it but please double check



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to