[
https://issues.apache.org/jira/browse/CALCITE-3630?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chunwei Lei updated CALCITE-3630:
---------------------------------
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:java}
// 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));
}
}
}
}
}
{code}
was:
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:java}
// 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));
}
// New plan is absolutely better than old plan.
call.getPlanner().setImportance(filter, 0.0);
}
}
}
}
{code}
> Improve ReduceExpressionsRule
> -----------------------------
>
> Key: CALCITE-3630
> URL: https://issues.apache.org/jira/browse/CALCITE-3630
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.21.0
> Reporter: Chunwei Lei
> Assignee: Chunwei Lei
> Priority: Major
>
> 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:java}
> // 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));
> }
> }
> }
> }
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)