[
https://issues.apache.org/jira/browse/CALCITE-7758?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109990#comment-18109990
]
Julian Hyde edited comment on CALCITE-7758 at 8/31/26 5:36 PM:
---------------------------------------------------------------
There's another way to do CAST, which doesn't involve subexpressions, and it
relies on the fact that {{CAST\(x)}} is null *if and only if* {{x}} is null.
Having deduced that {{CAST\(x)}} is not null, you can deduce {{x}} is not null,
and then later, when you see {{CAST\(x)}} again you can deduce that it is not
null because you know {{x}} is not null.
In other words, if the goal is to do subexpressions, CAST doesn't seem like the
best test-case for it. You should also use a test case that has "if" rather
than "if and only if".
was (Author: julianhyde):
There's another way to do CAST, which doesn't involve subexpressions, and it
relies on the fact that {{CAST(x)}} is null *if and only if* {{x}} is null.
Having deduced that {{CAST(x)}} is not null, you can deduce {{x}} is not null,
and then later, when you see {{CAST(x)}} again you can deduce that it is not
null because you know {{x}} is not null.
In other words, if the goal is to do subexpressions, CAST doesn't seem like the
best test-case for it. You should also use a test case that has "if" rather
than "if and only if".
> RexSimplify does not absorb redundant IS NOT NULL on non-input-ref
> sub-expressions in AND simplification
> --------------------------------------------------------------------------------------------------------
>
> Key: CALCITE-7758
> URL: https://issues.apache.org/jira/browse/CALCITE-7758
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Ruben Q L
> Assignee: Ruben Q L
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.43.0
>
>
> The following simplification:
> {noformat}
> IS_NOT_NULL(x) AND (x + 1) < 10
> =>
> (x + 1) < 10
> {noformat}
> is correctly applied on RexSimplify (Unknown=FALSE) for RexInputRef and
> RexFieldAccess (via simplifyAnd2ForUnknownAsFalse).
> However, if the expression X is e.g. a CAST, the simplification does not
> occur:
> {noformat}
> IS_NOT_NULL(CAST(a)) AND (CAST(a) + 1) < 10
> =>
> unchanged; should be: (CAST(a) + 1) < 10
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)