You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/10/13 22:29:25 UTC

[GitHub] [calcite] julianhyde opened a new pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

julianhyde opened a new pull request #2212:
URL: https://github.com/apache/calcite/pull/2212


   Improve how class Sarg handles IS NULL and IS NOT NULL
   conditions. They are now handled symmetrically, using fields
   nullCount and notNullCount, whereas previously we used
   containsNull, which could handle IS NULL only in certain
   circumstances and IS NOT NULL not at all.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] vlsi commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504297710



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {
+      complexity = 1;
+    } else {
+      complexity = rangeSet.asRanges().size();

Review comment:
       Should this be `int complexity = rangeSet.asRanges().size()`, and then `if (...) { complexity = 1;}`?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] asfgit merged pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
asfgit merged pull request #2212:
URL: https://github.com/apache/calcite/pull/2212


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] vlsi commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504306246



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {
+      complexity = 1;
+    } else {
+      complexity = rangeSet.asRanges().size();

Review comment:
       Then please avoid re-computing the same things again and again.
   
   It is hard to review and analyze how these `.asRanges().size()` differ.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] julianhyde commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
julianhyde commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504300873



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {
+      complexity = 1;
+    } else {
+      complexity = rangeSet.asRanges().size();

Review comment:
       It's a matter of taste. I prefer not to re-assign variables.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] vlsi commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504307063



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {

Review comment:
       Is this computation important for something?
   Please add the relevant comment: if it is important, then clarify so. If it is just a fine detail, then comment so. The intention behind the conditions is not really visible.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] julianhyde commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
julianhyde commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504308699



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {

Review comment:
       Yeah, there aren't many comments in the code. But there are reasonable method javadoc comments. Also a test, `testSargComplexity`. Run the test, and all will become clear.
   
   I moved the code so that I could add a test.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [calcite] vlsi commented on a change in pull request #2212: [CALCITE-4325] RexSimplify incorrectly simplifies complex expressions that contain Sarg and IS NULL

Posted by GitBox <gi...@apache.org>.
vlsi commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504307449



##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
         && rangeSet.complement().asRanges().stream()
             .allMatch(RangeSets::isPoint);
   }
+
+  /** Returns a measure of the complexity of this expression.
+   *
+   * <p>It is basically the number of values that need to be checked against
+   * (including NULL).
+   *
+   * <p>Examples:
+   * <ul>
+   *   <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+   *   <li>{@code x > 1 or x is null} has complexity 2
+   *   <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+   *   <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+   * </ul>
+   */
+  public int complexity() {
+    int complexity;
+    if (rangeSet.asRanges().size() == 2
+        && rangeSet.complement().asRanges().size() == 1
+        && RangeSets.isPoint(
+            Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {

Review comment:
       Oh, this code already existed. Then I'm puzzled.




----------------------------------------------------------------
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:
users@infra.apache.org