-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: equality, IN incorrect when dealing with "deep" tuples #22717
Comments
This change fixes handling of NULLs with IN expressions. The following examples illustrate the interesting cases that are fixed: ``` NULL IN <empty-tuple> = false (1, NULL) IN <empty-tuple> = false (1, NULL) IN ((1, NULL)) = NULL (1, NULL) IN ((1, 1)) = NULL (1, NULL) IN ((2, NULL)) = false ``` To implement this correctly, we now require that only tuples that don't contain NULLs can be marked as sorted. This is because we can't use binary search to, for example "match" `(1, NULL)` with `(1, 1)` (necessary to know if the result is false or NULL). Note that equality is broken for deeper tuples (cockroachdb#22717), and the new IN code relies on the equality code so it is broken for deep tuples as well. Updates cockroachdb#22670. Release note: None
This change fixes handling of NULLs with IN expressions. The following examples illustrate the interesting cases that are fixed: ``` NULL IN <empty-tuple> = false (1, NULL) IN <empty-tuple> = false (1, NULL) IN ((1, NULL)) = NULL (1, NULL) IN ((1, 1)) = NULL (1, NULL) IN ((2, NULL)) = false ``` To implement this correctly, we now require that only tuples that don't contain NULLs can be marked as sorted. This is because we can't use binary search to, for example "match" `(1, NULL)` with `(1, 1)` (necessary to know if the result is false or NULL). Note that equality is broken for deeper tuples (cockroachdb#22717), and the new IN code relies on the equality code so it is broken for deep tuples as well. Updates cockroachdb#22670. Release note (bug fix): Fixed incorrect evaluation of IN expressions where the left-hand side is a tuple, and some of the tuples on either side contain NULL.
This change fixes handling of NULLs with IN expressions. The following examples illustrate the interesting cases that are fixed: ``` NULL IN <empty-tuple> = false (1, NULL) IN <empty-tuple> = false (1, NULL) IN ((1, NULL)) = NULL (1, NULL) IN ((1, 1)) = NULL (1, NULL) IN ((2, NULL)) = false ``` To implement this correctly, we now require that only tuples that don't contain NULLs can be marked as sorted. This is because we can't use binary search to, for example "match" `(1, NULL)` with `(1, 1)` (necessary to know if the result is false or NULL). Note that equality is broken for deeper tuples (cockroachdb#22717), and the new IN code relies on the equality code so it is broken for deep tuples as well. Updates cockroachdb#22670. Release note (bug fix): Fixed incorrect evaluation of IN expressions where the left-hand side is a tuple, and some of the tuples on either side contain NULL.
@RaduBerinde I think this issue still exists right? |
Yes. |
Wait, but to be clear, we've decided that this is also a bug in Postgres, right? This doesn't seem like an issue that people are going to notice in practice. |
(notice or care about) |
Yes, it is also in PG. I agree it's probably not very important. |
Reassigning to @knz since he knows about this. Feel free to close this if you think it's not important. |
I was addressing this #27885. Will look further. |
Closing this - the first one works as expected, and the second one is identical to Postgres. |
SELECT ((1, 1), (2, NULL)) = ((1, 1), (2, NULL))
andSELECT ((1, 1), (2, NULL)) IN (((1, 1), (2, NULL)))
return true instead of NULL.See #22670 (comment)
The text was updated successfully, but these errors were encountered: