-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: fix TypeCheck for NULLIF #44718
Conversation
Prior to this commit, TypeCheck for NULLIF would set the type of the expression NULLIF(NULL, 0) to be int. However, the correct type is actually unknown, since the type of NULL is unknown. This commit fixes the error by using the type of the first expression as the type of NULLIF. Fixes cockroachdb#44632 Release note (bug fix): Fixed an internal error that could occur when NULLIF was called with one null argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @andy-kimball and @RaduBerinde)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
44718: sql: fix TypeCheck for NULLIF r=rytaft a=rytaft Prior to this commit, `TypeCheck` for `NULLIF` would set the type of the expression `NULLIF(NULL, 0)` to be `int`. However, the correct type is actually `unknown`, since the type of `NULL` is `unknown`. This commit fixes the error by using the type of the first expression as the type of `NULLIF`. Fixes #44632 Release note (bug fix): Fixed an internal error that could occur when NULLIF was called with one null argument. Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Build succeeded |
I realized I am actually a little confused here.
|
Hmm interesting. I'll hold off on the backports and look into this more. Thanks for checking on this! |
Good catch. My mind just jumped to the assumption that we'd type according to the first argument, without type inference. This means that the bug is with this code in
The resulting expression is not typed as
The fix for the issue is to use something like |
Thanks for identifying the fix, @andy-kimball (and finding the issue, @RaduBerinde!). I've made the suggested change in #45354. Also added a few more test cases for both |
Prior to this commit,
TypeCheck
forNULLIF
would set the type of theexpression
NULLIF(NULL, 0)
to beint
. However, the correct type isactually
unknown
, since the type ofNULL
isunknown
. This commitfixes the error by using the type of the first expression as the type
of
NULLIF
.Fixes #44632
Release note (bug fix): Fixed an internal error that could occur when
NULLIF was called with one null argument.