-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
planbuilder: use OR for not in comparisons #14607
Conversation
Signed-off-by: Andres Taylor <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
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.
😢
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
@@ -1966,7 +1966,7 @@ | |||
"Sharded": true | |||
}, | |||
"FieldQuery": "select id from `user` where 1 != 1", | |||
"Query": "select id from `user` where not :__sq_has_values and id not in ::__sq1", | |||
"Query": "select id from `user` where not :__sq_has_values or id not in ::__sq1", |
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.
I have a question. It seems that in this scenario, we can remove the "not :__sq_has_values" condition. Why do we need to convert it to "or"?
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.
Excellent question!
We have already built the queries by this time, so we need to be able to send down something that is valid SQL.
NOT IN ()
does not even parse - we need to have at least one value there.
We can't stick NULL
there, NOT IN (NULL)
evaluates to NULL
, not true
.
We just put in the fake value 0. Just to make sure that we end up with true
for the empty results, even if the column we are comparing against does contain a 0
, we add this not :__sq_has_values
that will return true no matter what.
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.
If it is important, we would need to come up with a value that we put into the ::__sq1
tuple that guarantees that id not in ::__sq1
returns true for all values of id
. We can make it very unlikely, but not guarantee that we will no clash, right?
…4615) Signed-off-by: Andres Taylor <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> Co-authored-by: Andres Taylor <[email protected]>
Description
The plans produced for
NOT IN
queries that have to be scattered did not handle the missing values case, which leads to wrong results for these situations.Related Issue(s)
Fixes #14605
Checklist0