release-22.1: opt: fix invalid transformation in SplitLimitedSelectIntoUnionSelects #89281
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 #89113.
/cc @cockroachdb/release
opt: fix invalid transformation in SplitLimitedSelectIntoUnionSelects
This commit removes some untested logic in
SplitLimitedSelectIntoUnionSelects
that created invalid expressiontransformations. With this logic, this rule could construct an unordered
limit below the
UnionAll
which is incorrect. The bug could causeincorrect query results.
Fixes #88993
Release note (bug fix): A bug has been fixed that could cause incorrect
results in rare cases. The bug could only present if the following
conditions were true:
ORDER BY
andLIMIT
was executed.ORDER BY
columns had an index containingthose columns.
number of values by the query filter (e.g.,
WHERE a IN (1, 3)
),a
CHECK
constraint (e.g.,CHECK (a IN (1, 3))
), inferred bya computed column expression (e.g.
WHERE a IN (1, 3)
and a columnb INT AS (a + 10) STORED
), or inferred by aPARTITION BY
clause(e.g.
INDEX (a, ...) PARTITION BY LIST (a) (PARTITION p VALUES ((1), (3)))
).This bug was present since version 22.1.0.
Release justification: Correctness bug fix.