release-22.2: opt: fix hoist of ANY comparison with tuples #98769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 1/1 commits from #98700.
/cc @cockroachdb/release
opt: fix hoist of ANY comparison with tuples
Prior to this commit, when hoisting Any expressions like
<left> = ANY (SELECT <right> ...)
, we constructed(IsNot <left|right> Null)
expressions which are equivalent to<left|right> IS DISTINCT FROM NULL
. As discovered in #46675, theseexpressions have different behavior than
<left> IS NOT NULL
when<left>
is a tuple. As a result, the hoisting transformations couldconstruct invalid plans that cause incorrect results. This commit fixes
the issue by using
IsTupleNotNull
expressions when<left>
and` are tupleq.
Fixes #98691
Release note (bug fix): A bug has been fixes that caused incorrect
results of ANY comparisons of tuples. For example, an expression like
(x, y) = ANY (SELECT a, b FROM t WHERE ...)
could returntrue
instead of the correct result of
NULL
whenx
andy
wereNULL
, ora
andb
wereNULL
. This could only occur if the subquery wascorrelated, i.e., it references columns from the outer part of the
query. This bug was present since the cost-based optimizer was
introduced in version 2.1.
Release justification: Fixes a minor bug.