release-21.2: sql: ALTER PRIMARY KEY
rewrites secondary index if new PK subsets old PK
#84578
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 #84303.
/cc @cockroachdb/release
Previously, during a
ALTER PRIMARY KEY
, if the new PK columns is asubset of the old PK columns, we won't rewrite existing unique,
secondary index.
This was inadequate because the user might think this column is not used
anywhere and will want to drop it, which will unexpectedly drop the
dependent unique index.
Fixes: #84040
Release note (bug fix): This PR fixed a bug where, in a
ALTER PRIMARY KEY
, if the new PK columns is asubset of the old PK columns, we will not rewrite existing secondary
index, and hence those secondary indexes continue to have some of
the old PK columns in their
suffixColumns
.But the user might, reasonably, think those columns are not used anymore
and proceed to drop them. The bug then caused those dependent secondary
indexes to be dropped, unexpectedly for the user.
Release justification: fixed a bug where unique indexes will be silently
dropped after
ALTER PRIMARY KEY
followed byDROP COLUMN
.