Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Wrong Null folding of functions and operators. #35872

Closed
matriv opened this issue Nov 23, 2018 · 1 comment
Closed

SQL: Wrong Null folding of functions and operators. #35872

matriv opened this issue Nov 23, 2018 · 1 comment

Comments

@matriv
Copy link
Contributor

matriv commented Nov 23, 2018

COALESCE but also other functions and operators (e.g.: AND, OR) return false in their nullable() implementation. Therefore if they are nested inside IS NULL or IS NOT NULL, the FoldNull() rule will wrongly fold them to false and true respectively.

Here is an example of a query that because of the folding returns wrong results:

SELECT languages FROM test_emp WHERE emp_no IN(10019, 10020, 10021) AND COALESCE(languages, null) IS NOT NULL;

returns empty list:

   languages   
---------------

but it should return:

   languages   
---------------
null           
null     
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@jasontedor jasontedor added v6.7.0 and removed v6.6.0 labels Dec 19, 2018
@matriv matriv self-assigned this Jan 3, 2019
matriv added a commit to matriv/elasticsearch that referenced this issue Jan 3, 2019
Logical operators `OR` and `AND` as well as conditional functions
(`COALESCE`, `LEAST`, `GREATEST`, etc.) cannot be folded to NULL if one
of their children is NULL as is the case for most of the functions.
Therefore, their `nullable()` implementation cannot return `true`. On
the other hand they cannot return `false` as if they're wrapped within
an `IS NULL` or `IS NOT NULL` expression, the expression will be folded
to `false` and `true` respectively leading to wrong results.

Change the signature of `nullable()` method and add a third value `UKNOWN`
to handle these cases.

Fixes: elastic#35872
matriv added a commit that referenced this issue Jan 6, 2019
Logical operators OR and AND as well as conditional functions
(COALESCE, LEAST, GREATEST, etc.) cannot be folded to NULL if one
of their children is NULL as is the case for most of the functions.
Therefore, their nullable() implementation cannot return true. On
the other hand they cannot return false as if they're wrapped within
an IS NULL or IS NOT NULL expression, the expression will be folded
to false and true respectively leading to wrong results.

Change the signature of nullable() method and add a third value UKNOWN
to handle these cases.

Fixes: #35872
matriv added a commit that referenced this issue Jan 6, 2019
Logical operators OR and AND as well as conditional functions
(COALESCE, LEAST, GREATEST, etc.) cannot be folded to NULL if one
of their children is NULL as is the case for most of the functions.
Therefore, their nullable() implementation cannot return true. On
the other hand they cannot return false as if they're wrapped within
an IS NULL or IS NOT NULL expression, the expression will be folded
to false and true respectively leading to wrong results.

Change the signature of nullable() method and add a third value UKNOWN
to handle these cases.

Fixes: #35872
matriv added a commit that referenced this issue Jan 6, 2019
Logical operators OR and AND as well as conditional functions
(COALESCE, LEAST, GREATEST, etc.) cannot be folded to NULL if one
of their children is NULL as is the case for most of the functions.
Therefore, their nullable() implementation cannot return true. On
the other hand they cannot return false as if they're wrapped within
an IS NULL or IS NOT NULL expression, the expression will be folded
to false and true respectively leading to wrong results.

Change the signature of nullable() method and add a third value UKNOWN
to handle these cases.

Fixes: #35872
matriv added a commit that referenced this issue Jan 6, 2019
Logical operators OR and AND as well as conditional functions
(COALESCE, LEAST, GREATEST, etc.) cannot be folded to NULL if one
of their children is NULL as is the case for most of the functions.
Therefore, their nullable() implementation cannot return true. On
the other hand they cannot return false as if they're wrapped within
an IS NULL or IS NOT NULL expression, the expression will be folded
to false and true respectively leading to wrong results.

Change the signature of nullable() method and add a third value UKNOWN
to handle these cases.

Fixes: #35872
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants