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

Improve ReduceExpressionsRule

    XMLWordPrintableJSON

    Details

      Description

      In FilterReduceExpressionsRule, if the expression is a IS [NOT] NULL on a non-nullable column, then we can either remove the filter or replace it with an Empty(namely reduceNotNullableFilter). In such a case, we can set importance to 0 to reduce search space.

       

      // code placeholder
        private void reduceNotNullableFilter(
            RelOptRuleCall call,
            Filter filter,
            RexNode rexNode,
            boolean reverse) {
          // If the expression is a IS [NOT] NULL on a non-nullable
          // column, then we can either remove the filter or replace
          // it with an Empty.
          boolean alwaysTrue;
          switch (rexNode.getKind()) {
          case IS_NULL:
          case IS_UNKNOWN:
            alwaysTrue = false;
            break;
          case IS_NOT_NULL:
            alwaysTrue = true;
            break;
          default:
            return;
          }
          if (reverse) {
            alwaysTrue = !alwaysTrue;
          }
          RexNode operand = ((RexCall) rexNode).getOperands().get(0);
          if (operand instanceof RexInputRef) {
            RexInputRef inputRef = (RexInputRef) operand;
            if (!inputRef.getType().isNullable()) {
              if (alwaysTrue) {
                call.transformTo(filter.getInput());
              } else {
                call.transformTo(createEmptyRelOrEquivalent(call, filter));
              }
            }
          }
        }
      }
      

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Chunwei Lei Chunwei Lei
                Reporter:
                Chunwei Lei Chunwei Lei
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h