-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
release-21.1: colexec: fix IN operator with unsorted tuple #69979
Conversation
The vectorized implementation of an `element IN tuple` expression assumes that the contents of `tuple` are sorted by the optimizer. Based on this assumption, it performs a binary search instead of a linear search. However, the assumption that the optimizer sorts all tuples is incorrect. For example, there are cases where the contents of a tuple are not known at planning-time, so the tuple cannot be sorted. Performing a binary search with an unsorted tuple causes incorrect query results. Now, the vectorized engine sorts tuple contents if they are not already sorted. Fixes cockroachdb#68979 Release justification: This commit fixes a bug with the IN operator that causes incorrect results. Release note (bug fix): A bug has been fixed which caused incorrect evaluation of the `IN` operator when the tuple on the right-hand-side of the operator included a subquery, like `a IN ('foo', (SELECT s FROM t), 'bar')`.
Thanks for opening a backport. Please check the backport criteria before merging:
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
Add a brief release justification to the body of your PR to justify this backport. Some other things to consider:
|
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.
Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner)
@yuzefovich The build is failing with:
I think this means that the bug is not reproducible on 21.1. In that case, do we need to backport this fix? |
Hm, I'm not sure - it does sound like the bug is not reproducible (i.e. we will fallback to the row-by-row engine in all cases where the |
SGTM. Closing. |
Backport 1/1 commits from #69651.
/cc @cockroachdb/release
Release justifcation: This commit fixes a critical correctness bug in
the vectorized execution engine.
The vectorized implementation of an
element IN tuple
expressionassumes that the contents of
tuple
are sorted by the optimizer. Basedon this assumption, it performs a binary search instead of a linear
search.
However, the assumption that the optimizer sorts all tuples is
incorrect. For example, there are cases where the contents of a tuple
are not known at planning-time, so the tuple cannot be sorted.
Performing a binary search with an unsorted tuple causes incorrect query
results.
Now, the vectorized engine sorts tuple contents if they are not already
sorted.
Fixes #68979
Release justification: This commit fixes a bug with the IN operator that
causes incorrect results.
Release note (bug fix): A bug has been fixed which caused incorrect
evaluation of the
IN
operator when the tuple on the right-hand-sideof the operator included a subquery, like
a IN ('foo', (SELECT s FROM t), 'bar')
.