-
-
Notifications
You must be signed in to change notification settings - Fork 39
Add support for IS NULL expression on records
#1520
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
Conversation
bd75823 to
d10a246
Compare
|
|
zachmu
left a comment
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.
LGTM but see comments
Hydrocharged
left a comment
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.
This seems like the wrong approach. In dolthub/go-mysql-server#3004, you mentioned that the analyzer uses *expression.IsNull for optimization passes, but what exactly are those and how do they break? In GMS we make the assumption that IS NULL == NOT(IS NULL), but from reading the Postgres documentation, this does not seem to be true.
https://www.postgresql.org/docs/15/functions-comparison.html
If the expression is row-valued, then IS NULL is true when the row expression itself is null or when all the row's fields are null, while IS NOT NULL is true when the row expression itself is non-null and all the row's fields are non-null. Because of this behavior, IS NULL and IS NOT NULL do not always return inverse results for row-valued expressions; in particular, a row-valued expression that contains both null and non-null fields will return false for both tests.
This implies that IS NULL and IS NOT NULL are fundamentally different comparison operations, which would evaluate to them being different functions/expressions. I ask about the optimization passes, as assumptions made there are for specific MySQL characteristics, and while MySQL and Postgres share a lot, they are overall different engines.
I ran two test queries through this PR, and it indeed fails as expected:
SELECT ROW(null, 1) IS NULL; -> 0 (right value, wrong type)
SELECT ROW(null, 1) IS NOT NULL; -> "t" (should be "f")
|
Another (somewhat side) comment, I think the better abstraction for GMS would be to have types as a pluggable architecture, where MySQL implements their types, and Postgres implements theirs. This would be a part of the transition to All of the above I feel @zachmu should read as well, and we can go into more detail in our next sync. |
|
Good callout on the fact that Postgres does not treat Yup, this means we'll have to rework some of this expression logic in GMS. I'll start digging into how/where |
8e25fde to
2dadaa6
Compare
zachmu
left a comment
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.
LGTM, just one comment
…ne initialization
2dadaa6 to
c9e9a62
Compare
Postgres semantics for
IS NULLandIS NOT NULLdiffer slightly from the the MySQL semantics implemented in GMS. For records and composites,IS NULLreturns true if the record/composite itself isNULLor if all values in the record/composite areNULL.IS NOT NULLreturns true only if all values in the record/composite are notNULL. Note that this means, for records and composites in Postgres,IS NOT NULLis not equivalent toNOT(IS NULL).This change adds custom implementations of
IS NULLandIS NOT NULLto support Postgres' behavior with records and composites.Depends on: dolthub/go-mysql-server#3064