[ 
https://issues.apache.org/jira/browse/CALCITE-5780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17733270#comment-17733270
 ] 

Runkang He commented on CALCITE-5780:
-------------------------------------

[~nobigo] `1 > x or x >=1 or x is null` is not handled in the past, and can be 
simplified to TRUE in this Jira's commit.

 
An interesting thing is `x >=1 or 1 > x or x is null` can be simplified to TRUE 
in the past, there are two points to explain why:

1. When simplify OR terms, we move `x is null` to term list's head, and then, 
inverse each term one by one. When inverse `x >= 1`(i.e. `is not true(x >= 
1)`), it can be simplified to `x < 1`, which can be used in further 
simplification.

2. When simpify predicate with pulled up predicates, the `1 > x` is processed 
and represented using Comparison, which can handle it properly.

 
Back to `1 > x or x >=1 or x is null`, the reason why it is not handled in the 
past is basically the opposite:

1. When inverse `1 > x`(i.e. `is not true(1 > x)`), it cannot be simplified to 
`1 <= x` because isEffectivelyNotNull logic for `1 > x` when pulled up 
predicates contain `x is not null` is missing. So the simplified result is `is 
not true(1 > x)`(not changed), but it can and should be {*}`1 <= x`{*}, and we 
need it for further simplification.

2. After we conside reverse comparison case and improve the logic, when simpify 
predicate `x >=1` with pulled up predicates(`x is not null`, {*}`1 <= x`{*}), 
the `1 <= x` in pulled up predicates is not handled.

> Always-true OR expressions contain reverse order comparison should be 
> simplified to TRUE
> ----------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5780
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5780
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.34.0
>            Reporter: Runkang He
>            Assignee: Runkang He
>            Priority: Major
>              Labels: pull-request-available
>
> The following expressions which contain reverse order comparison are always 
> true:
> {code:sql}
> 1 > x or 1 <= x or x is null
> 1 < x or 1 >= x or x is null
> 1 > x or 0 < x or x is null
> {code}
> But currently these expressions are not fully simplified to TRUE, the current 
> simplified results are SEARCH operator.
> The root cause is that RexSimplify doesn't identify these cases and makes 
> targeted simplification.
> It would be nice if RexSimplify.simplifyOr handled these cases.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to