release-21.1: opt: do not generate unnecessary cross-joins on join input #79508
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/2 commits from #79389.
/cc @cockroachdb/release
opt: do not generate unnecessary cross-joins on lookup join input
This commit fixes a bug that caused unnecessary cross-joins on the input
of lookup joins, causing both suboptimal query plans and incorrect query
results. The bug only affected lookup joins with lookup expressions.
Fixes #79384
Release note (bug fix): A bug has been fixed that caused the optimizer
to generate query plans with logically incorrect lookup joins. The bug
can only occur in queries with an inner join, e.g.,
t1 JOIN t2
, if allof the following are true:
tables, e.g.,
t1.a = t2.a
.CHECK
constraint constrains a column to a setof specific values, e.g.,
t2.b IN (1, 2, 3)
. In the case of aCHECK
constraint, the column must beNOT NULL
.CHECK
constraint constrains a column to arange, e.g.,
t2.c > 0
. In the case of aCHECK
constraint, thecolumn must be
NOT NULL
.INDEX t2(a, b, c)
.This bug has been present since version 21.2.0.
opt: do not cross-join input of inverted semi-join
In #78685, we prevented
GenerateLookupJoins
from incorrect creating across-join on the input of a semi-join, addressing #78681. This commit
addresses the same issue with
GenerateInvertedJoins
, which weoriginally forgot to fix.
Informs #78681
Release note (bug fix): A bug has been fixed which caused the optimizer
to generate invalid query plans which could result in incorrect query
results. The bug, which has been present since version 21.1.0, can
appear if all of the following conditions are true:
SELECT * FROM a WHERE EXISTS (SELECT * FROM b WHERE a.a @> b.b)
.inverted column in the filter.
filter or a
CHECK
constraint, e.g., with anIN
operator. In thecase of a
CHECK
constraint, the column isNOT NULL
.Release justification: Fixes a correctness bug in the optimizer.