You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2020/08/09 22:40:00 UTC

[jira] [Updated] (CALCITE-4170) Improve simplification of "<>" predicates

     [ https://issues.apache.org/jira/browse/CALCITE-4170?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde updated CALCITE-4170:
---------------------------------
    Description: 
Improve simplification of "<>" (not equals) predicates. The goal is to simplify "a <> 1 or a = 1" to "true".

Today we can simplify "a = 1 or a <> 1" to "true" (the same expression with the terms re-ordered) but we cannot simplify "a <> 1 or a = 1" to "true". The problem is this. The algorithm for simplifying "or" builds a up a list of predicates as it works left to right. After dealing with "a = 1" RexSimplifier has a predicate "a = 1" and therefore it can simplify the next predicate to anything that returns the right result over the possible inputs - which will not include a = 1 - and therefore 'a <> 1' can be simplified to 'true'.

But today, we can't take that approach with "a <> 1 or a = 1" because "a <> 1" cannot be represented as a single range. It needs two ranges - less than 1 or greater than 1. The fix is therefore to allow predicates to be range sets not just ranges.

  was:
Improve simplification of "<>" (not equals) predicates.

Today we can simplify "a = 1 or a <> 1" to "true" but we cannot simplify "a <> 1 or a = 1" to "true". The problem is this. The algorithm for simplifying "or" builds a up a list of predicates as it works left to right. After dealing with "a = 1" RexSimplifier has a predicate "a = 1" and therefore it can simplify the next predicate to anything that returns the right result over the possible inputs - which will not include a = 1 - and therefore 'a <> 1' can be simplified to 'true'.

But today, we can't take that approach with "a <> 1 or a = 1" because "a <> 1" cannot be represented as a single range. It needs two ranges - less than 1 or greater than 1. The fix is therefore to allow predicates to be range sets not just ranges.


> Improve simplification of "<>" predicates
> -----------------------------------------
>
>                 Key: CALCITE-4170
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4170
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Priority: Major
>
> Improve simplification of "<>" (not equals) predicates. The goal is to simplify "a <> 1 or a = 1" to "true".
> Today we can simplify "a = 1 or a <> 1" to "true" (the same expression with the terms re-ordered) but we cannot simplify "a <> 1 or a = 1" to "true". The problem is this. The algorithm for simplifying "or" builds a up a list of predicates as it works left to right. After dealing with "a = 1" RexSimplifier has a predicate "a = 1" and therefore it can simplify the next predicate to anything that returns the right result over the possible inputs - which will not include a = 1 - and therefore 'a <> 1' can be simplified to 'true'.
> But today, we can't take that approach with "a <> 1 or a = 1" because "a <> 1" cannot be represented as a single range. It needs two ranges - less than 1 or greater than 1. The fix is therefore to allow predicates to be range sets not just ranges.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)